Keep that ADC circuit well away from a Pi or you will let all the magic smoke out. Without looking it up, I wouldn't care to bet that the ADS1115 can take 24v, either.ertank wrote: ↑Tue Jul 09, 2019 4:21 pmHello,
- I have a set of 24Volts batteries. (3 or 4 total)
- They are connected to this inverter: https://imgyukle.com/i/kK9UrY as power input
- Inverter outputs power to a refrigerator of 220Volts.
- Everything is mobile.
I am asked to measure battery level (volts or percentage or any other way possible).
There are similar questions asked in this forum before. I tried to read them all and even more from out of this forum.
My current plan is to power Raspberry Pi using a wall adapter 220V. Since Raspberry Pi has digital I/O, I think of using ADS1115 module. That module has max 5V analog input. I think of using something like this: https://imgyukle.com/i/kKd441
1- I am not completely sure that will work. I do not have any electric/electronics education. I cannot think of a problem of any kind in this design.
2- I do not know what to do with the open end cable at bottom.
3- I am not sure what tolerance resistors should be. I think I can find 10% ones in the market as usual.
Any suggestions and help is appreciated.
Thanks & regards,
If you're referring to the wire dangling from the bottom of the 4.7k resistor, connect it to GND
5% and 1% should be more common than 10%. What precision do you require for your voltage measurements?3- I am not sure what tolerance resistors should be. I think I can find 10% ones in the market as usual.
To achieve 1% measurement accuracy without calibration, you will need to use better than 1% resistors in every relevant potential divider. You will need high stability components, stable power supplies, a good accurate reference voltage, excellent decoupling, and generally a high standard of design and build. Achievable but not simple.
Code: Select all
#!/usr/bin/python import spidev # ============================================================================ # MCP3008 8 channel 10-Bit ADC # ============================================================================ class MCP3008 : spi = None _MAX_ADC_VAL = 1023 # Constructor def __init__(self, spi_device=0, spi_channel=0, max_speed_hz = 100000, adc_vcc=5.0, debug=False): # 100kHz self.spi = spidev.SpiDev(spi_device, spi_channel) self.spi.max_speed_hz = max_speed_hz self.adc_vcc = adc_vcc self.debug = debug def read_voltage(self, channel, diff=False): # Only 8 channels 0 thru 7, else return -1 if ((channel > 7) or (channel < 0)): return -1 # Send start bit, sgl/diff, odd/sign, MSBF # channel = 0 sends 0000 0001 1000 0000 0000 0000 # channel = 1 sends 0000 0001 1100 0000 0000 0000 # sgl/diff = 1; odd/sign = channel; MSBF = 0 if (diff == False): r = self.spi.xfer([1,(8+channel)<<4,0]) else: r = self.spi.xfer([1,(0+channel)<<4,0]) ret = ((r&3) << 8) + (r) voltage = ret * self.adc_vcc / self._MAX_ADC_VAL if (self.debug): print "r0, R1, R2 is 0x%2x,0x%2x,0x%2x " %(r, r, r) print "Raw hex value read is 0x%3x" % ret print "ADC channel %d voltage is %0.2f" % (channel,voltage) return voltage
Code: Select all
#!/usr/bin/python from MCP3008 import MCP3008 mcp3008 = MCP3008(spi_device=0, spi_channel=0, adc_vcc=5.0) print "Reading ADC value on channel 0, differential" adc_value = mcp3008.read_voltage(channel=0, diff=True) print "ADC value is %f" % adc_value
I ordered one MCP3008 and waiting for it to arrive. In the mean time, I have some questions as to all wiring.chipace wrote: ↑Sun Jul 14, 2019 6:53 amI tried a stack of 4 AAA rechargeable batteries (no resistor divider) and a MCP3008. I was able to read each battery voltage.
First battery positive terminal connected to CH0, negative terminal connected to CH1... final battery positive terminal connected to CH6 and negative terminal to CH7. I then read 2, 3 and 4 battery stack voltages (moved the first battery away from CH0/CH1, and used that differential channel to read the various stack voltages.
Code: Select all
bat1_value = mcp3008.read_voltage(channel=0, diff=True) bat2_value = mcp3008.read_voltage(channel=2, diff=True) bat3_value = mcp3008.read_voltage(channel=4, diff=True) bat4_value = mcp3008.read_voltage(channel=6, diff=True)
(Quoted with correction)
That's right... the original instructions are best. The sclk, mosi and miso are fine with being at 3.3V with the Vdd at 5.0V.Vref should not exceed Vdd
you don't need any LDO for tasks like this. use ads1115 it has an internal reference. you will able to get 16adc channels on one i2c bus,chipace wrote: ↑Mon Jul 15, 2019 6:07 amI was also thinking about the effective voltage range that you are going to measure on each battery. I am thinking that if the 12V battery drops to 6V, it will be in deep cycle. Also, open circuit measurement of a 12V battery can be as high as 13V. Maybe your effective measurement range would be between 6V to 13V. If you used multiple LDO regulators, this could allow you to use the majority of your ADC range (10bits) in your desired voltage measurement range (6V to 13V).
I drew a diagram of what that circuit might look like:
Maybe one of the 4 LDOs could also be used as the ADC Vref.