# How to read 3v3 pin voltage with code?

Is there any way of reading 3v3 pin voltage through code?
If so, would that be accurate?
Don’t have trust in my digital multimeter.

The reference for the ADCs is the same as the 3v3 supply, so you’d probably always get 4095 when `analogRead()`ing the voltage there.
If you don’t trust your DMM use an oscilloscope.

You can setup another voltage reference less than 3.3V and read that–it needs be a true voltage reference IC or Zener, not a resistor divider from 3.3V. Maxim and TI and others make precision voltage references. Then when you get your reading you can backward calculate what the 3.3V reference for the ADC had to be. Here is an example:

Let’s say you have a 2.5V reference on A0. If the 3.3V supply was correct, you would have 2.5/3.3 * 4095 = 3102 ADC value. Now lets say the 3.3V supply is really 3.2V, you should get 2.5/3.2 * 4095 = 3199 ADC reading. Similarly if the 3.3V supply is 3.4V, you get 2.5/3.4 * 4095 = 3011 ADC reading.

So the to backward calculate this you take your ADC reading, you calculate (Vref * 4095)/ADC in floating point. Let’s say you read 3050 from the ADC with 2.5V reference, then you calculate (2.5 * 4095)/3050 = 3.356 V.

If this is a one-time thing, you should just buy a better multimeter!

3 Likes

Thanks for that info guys. @bko does the photons 3v3 supply fluctuate with temperature?
As the reference voltage is needed to calculate the ACS758 150amp bidirectional, which has a resolution of 13.3mV per amp, I guess I might have to live with incorrect readings ±200mA.
Apart for that I managed to get better readings by taking 100 samples, 1 every 5ms and doing some math to smooth out the readings due to noise.

I am sure the 3.3V regulator on a Photon has a temperature coefficient. I would check the datasheet for the regulator.

You should know that the ACS758 has been marked “not for new design” by Allegro since they have better parts now. It will be end-of-life’d soon I would think.

If you need more precise measuring, you could consider adding an external ADC with its own voltage reference.

1 Like

The INA219 chip is a great voltage and current monitor also.

Thanks for that @RWB although I need to measure current upto 200a.
@bko would it be a better approach to use the ADS1115 and a 75mV 200a shunt

You would lose the temperature compensation and benefits of the Hall effect device measuring so I would look at ACS770 family parts.

Hi @bko.
Thank you for the wealth of information. The ACS781 has been tuned for 3.3v although it is surface mounted and I am unable to find it mounted on a board. Digikey has other models on demo boards but none available for the ACS781. Very frustrating.
If it helps, I will explain my need for currunt sensing.
I want to measure the current drop over time of large battery banks being charged. When the current draw has dropped to a minimum after absorbtion stage, need to know when it is time for float charging. Will be using the Photon hence my need for 3.3v sensor.

No @RWB.
The charging is done by a DC generator equipped with a permanent magnet alternator.
There are also many solar charge controllers that don’t have a programmable auxilliary relay to be triggered at float.

What is the dc voltage that the generator puts out?

12v@250a, 24v@120a, 48v@63a.

It will output all three voltages, or you have to pick one of the three options?

What is your battery bank voltage?

Sorry. 3 different models.
Ex. If you need to charge a 48v battery bank it is rated at 63amps continuous charge, 100amps peak.

You could use a Victron BMV 700 battery monitor to measure battery voltage, current, SOC, AH removed, Watts, and Time to Go until the battery bank is empty in Hours and mins.

This unit has a serial UART data port on the back that you can read with a Photon and then act on this data to trigger you generator to turn off.

The battery monitor also has contacts on it that you can program to change based on the battery bank SOC level. Like when the battery bank is charged up to 90-95%, you can trigger it to close or open a contact to trigger the generator to turn OFF.

The battery monitor comes with a 500A shunt for measuring high current levels on large battery banks.

1 Like

Thanks for that @RWB. I am aware of the BMV 700. Great product and might have to resort to something like that. No need to read the UART data port as it already has a programmable relay.