About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Register or Sign In


1270 Views - Created 03/10/2016


Posted by:

Users Avatar

Warragul, Victoria Australia

I have been following Andrew Wedmore's blog re battery monitoring at https://offgriduk.net/2014/12/06/monitoring-the-battery-bank-part-1/.

I am calibrating the Pi Plus with a set external voltage on the inputs via calculated external (200k) resistors for maximum 60V.  Can anyone tell me the difference between using the various correction factors Andrew uses in his code and something like the following python code:

# calibrate_voltage = 12.04V

# raw_read = adc1.read_raw(input)

    if calibrate_voltage > 0:
      # as calibrate_voltage = raw_read * adc_multiplier then
      adc_multiplier = calibrate_voltage / raw_read
      factor[i] = adc_multiplier

# factor[i] is then used to calibrate raw_readings for that adc channel [i]

Andrew borrows and expands on AB electronics demo code:

# following assumes 18 bit (which gives the 0.0000078125) and PGS gain of 1 (which gives the 0.48828125)
# The 2.448579823702253 is a constant that is given without explanation in ABElectronics_ADCPi.py
rawToPiVoltageMultiplier = 2.448579823702253 * 0.0000078125 / 0.48828125 # translates the raw reading into the voltage seen by the ADCPi  
adcPIResistance = 16800 # the on-board resistance of each input in ohms

resistorRatio1 = (externalResistance1 + adcPIResistance) / adcPIResistance
rawToFinalVoltageMultiplier = rawToPiVoltageMultiplier * resistorRatio1
factor = [
rawToFinalVoltageMultiplier * correction[0] # etc.

I'd appreciate your comments on this, as I'm not sure if the added complexity provides more accuracy, etc.

PS The Pi Plus was received from the UK to AUS in just over a week - congratulations on the fantastic service!


Posted by:

Users Avatar

United Kingdom

Users Twitter  Users Website  

If you are using our ADCPi python library to read the values from your ADC Pi then the easiest way to make it work for 60V input would be to modify the read_voltage() function within the library to use a multiplier based on the voltage divider you are using.

The read_voltage() function contains the following code on line 116:

(raw * (self.__lsb / self.__pga)) * 2.471)

The 2.471 is the multiplier for the voltage divider.  This is calculated based on the maximum input voltage divided by the maximum output voltage.  On the ADC Pi the voltage divider contains a 10K and 6K8 resistor and the maximum voltage the ADC chip can read is 2.048V.   Using our voltage divider calculator with R1 at 10000, R2 at 6800 and Output as 2.048 gives an input voltage of 5.05976V.  

5.05976 / 2.048 = 2.47058 which in the ADC Pi library is rounded to 2.471.

The code Andrew was using contained an early version of our library that had an incorrect value for the multiplier of 2.448579823702253 which we have since fixed.

If you are using external 200K resistors then that combined with the existing 10K will give a 210K on the input side of the divider.  This will give a maximum voltage of 65.29506V which can be divided against the 2.048 output voltage to give us a new multiplier.

65.29506 / 2.048 = 31.8824

Updating the ADC Pi library so the code above now contains the new multiplier should give you the correct voltage readings when using the read_voltage() function.  This should be simpler than the method Andrew used.

(raw * (self.__lsb / self.__pga)) * 31.8824)

The accuracy of the readings will be based on the tolerances of the resistors so if you need to make the circuit more accurate you will need a calibrated voltage source to measure against and then comparing the voltage source to the value being recorded you can work out an error correction value for each input channel.

AB Electronics UK Tech Support


Posted by:

Users Avatar

Warragul, Victoria Australia

Thanks so much for your excellent, detailed and speedy response.  It all makes sense, particularly as I was stuck on the values used in the early library.  I've now got the code working nicely.

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.