Cheap Solution for Rpi ACS712 Current Sensing/Logging Problem
I’ve been searching through multiple forums, and gone to different links online trying to find a “cheap” solution to my question.
I am a poor hobbyist and can only afford to play cheap things. So I am thinking of suggesting a cheap solution.
I am currently trying to monitor the current and voltage of an external car battery and log that data. I’ve been trying to using an ADC with a voltage sensor and the ACS712 for the current measuring.
Your project specification and user requirement and constraint is clear. I have experience in ADC such as MCP3008/3208, but no experience in ACS712. I am thinking of starting ACS712 not. So perhaps I can start sharing some experience with you.
With the ADC wired (triple checked) and the ACS712 tested on the Arduino (and showed to be working), I cannot seem to get a reading on the PI.
I read your comments that you already solved your no Rpi reading on ACS712, but the new problem is that the readings are not stable. I guess you still have no idea if the problem is on Rpi or ADC side.
This has lead to me to look into different options for sensors, rather than use an analog output sensor,
I think ACS712 + ADC is the cheapest solution. Of course you can find fully commercial digital products, but that might be beyond your and my budget.
I’m looking for either sensors that connect to the raspberry via usb or through the I2C, but with a max current rating of around 10A.
There are many I2C/SPI ADC chips and cheap breakout boards/modules using SPI or I2C, which Rpi can handle. But communication using USB is a bit complex for Rpi. I once tried SPI ADC and found no problems. Now I am thinking of trying I2C ADC (more about this later).
The only one I have been able to find, is the INA219, but it can only handle up to 3.2A, which leads me to ask two questions: Can I solder another .1 Ohm resistor in parallel to the shunt resistor on board, to increase the max current to 6.4A?
I don’t know INA219. But I know ACS712 has 5A, 20A, 30A versions. So I think I will only start with ACS712.
Secondly, what other options have most of you come across that use USB or the I2C? Lastly, I have to use a Raspberry pi to collect the current and voltage data. Thanks,
As I said earlier, Rpi SPI/I2C ADC + ADC712 seems good. I am going to explore further.
########## The Answer Part 1 – Current Sensing Using ACS712 ##########
Your big question can break into 3 smaller questions.
1. How to measure current (say, using sensor ACS712)
2. How to convert sensor analog output to digital (say, using MCP3008)
3. How to read ADC converter output (say, using Rpi3B+ I2C)
I would suggest to eat the big elephant in 3 bites. The first bite is ACS712. You mentioned that the output signal is not stable. So let me check from the very beginning, the ACS721. To troubleshoot intermittent, unstable, unrepeatable problems, I usually do “pair programming/development hardware/software”. In this ACS712 case, I am squeezing 4 modules in one prototyping board, to make it easy to compare and swap modules to find out who is the bad guy, …
There you go, the real thing!
Measuring Sensor Output vs Forward Current
but with fluctuating readings. If you have any experience with that, …
I don’t understand what do you mean by “fluctuating” readings. Fluctuating by how much? 10% or 30%？ Fluctuating how frequent? 10 times or 30 times per second?
I checked the datasheet and find that the total accuracy is 1.5%. In other words, any fluctuation within 1.5% is within specification.
I checked the sensor voltage output vs current input, as displayed below. I found performance more or less linear. Next is to check current in reverse direction, to see how symmetrical is the sensor. PS – I did not observe any noticeable fluctuation as you reported.
Raspberry Pi Current & Voltage Sensors (10A rating and ~40V respectively)
Your title is a bit misleading. ACS712 is a current sensor, it does not measure voltage. So perhaps you can make it more clear by saying something like “How to use an IC current sensor to measure the output current, up to 10A, of a 40V car battery”
Measuring Sensor Output vs Reverse Current
Now I swapped the two connecting wires at the ACS712 current input terminal, and repeated the input current vs output voltage calibration. I tested the current range from -1.5A to 0A. The result is displayed below. So far so good. I am not keen to extend the test range to 5A, because I will only measure current for 12V DC motor, which takes less than 1A.
Now let me calculate the sensitivity.
V = 3.07V – 2.42V = 0.65V I = 1.57A – (-1.57A) = 3.14A
Sensitivity = V/I = 0.65V / 3.14A = 250mV/A.
Comparing with the datasheet’s maximum sensitivity of 190mV/A, I concluded my ACS712 Sample #1 looks good.
I think I can consider this current sensing part more or less completed, and move on to the second part of OP’s question – ADC, using MCP3008 or others.
The only one I have been able to find, is the INA219, but it can only handle up to 3.2A, which leads me to ask two questions:
Can I solder another .1 Ohm resistor in parallel to the shunt resistor on board, to increase the max current to 6.4A?
Are you very sure? The datasheet seems to say that you can decide the value of shunt resistance with a maximum voltage limit. Adafruit indeed selects fixed current sensing resistor. But you can change that. In other words, you can set your own full scale current limit, say to 10A, if you like. You may like to read the following references.
INA226 Datasheet – TI http://www.ti.com/lit/ds/symlink/ina226.pdf
CJMCU-226 INA226 IIC bi-directional current sensing module -US$1.26https://www.aliexpress.com/i/32901786763.html
AdaFruit INA219 High Side DC Current Sensor Breakout – 26V ±3.2A Max $9.95https://www.adafruit.com/product/904
I’ve been searching through multiple forums, and gone to different links online trying to find a “cheap” solution to my question … I’ve been trying ADC with a voltage sensor and ACS712 for current measuring … I’m looking for sensors connect to the raspberry via usb or I2C … The only one I have been able to find, is the INA219, but …
Yes, in the last couple of months I have also been searching various forums for Rpi + ADC + sensors solutions for my cheap smart home DIY project. However so far I don’t find that much useful references for Rpi, though for Arduino there is a lot. What is very disappointing is that more new references, especially from Adafruit, are for CircuitPython hardware. Rpi is CicruitPython “compatible”, but I read Wikipedia saying the following:
Programs written for CircuitPython compatible boards may not run unmodified on other platforms such as the Raspberry Pi.
I don’t like CircuitPython because like the MicroPython I once played with, it is REPL based and is good for beginners, but not that friendly for regular python programmers.
So sadly, I made the decision to forget about CircuitPython and start writing Rpi python programs for I2C ADC now.
CircuitPython – Wikipedia https://en.wikipedia.org/wiki/CircuitPython
########## The Answer Part 2 – ADC using ADS1015 ##########
what other options that use USB or the I2C?
As I said earlier, it is very difficult to program Rpi to communicate through USB. The other options are UART, SPI, and I2C. UART is not comman nowadays, except perhaps in BlueTooth. SPI is easier than I2C, but not that many modules are available. For example, SPI MCP3008/3204/3208 ADC modules are not common and very expensive. On the other hand, I2C ADCs such as ADS1115, HX711 are common and cheap. I2C is harder to play with than SPI. For example, I am now trying to put 4 ADS1115 on one I2C bus, I found the module’s 10k pullups are overloading Rpi’s built 1k8, and I need to remove all the ADS1115 modules’ pullups, otherwise the modules cannot be detected by I2C tools i2cdetect -y 1. Newbies might find desoldering SMDs a bit scary!
Assembling and testing the quad ADS1150 ADC Board
So I placed 4 ADC1150 on a 7x10cm protoboard. Now each of the 4 ADS1150 can be separately detected by i2cdetect -y 1 when ADDR set to 0x048, 0x49, 0x4a, and 0x4b. But at most two ADS1150 can be detected at the same time, even though I removed all the 10k pullups of each board. I guess the reason is I am using very long, over 60cm wires and so the resultant total capacitance overloads the TSX0104 logical level converter.
Next is to see if the ADS1150 ADCs can convert ASC712 current sensing outputs.
Why testing 4 current sensors and 4 ADCs at the same time
I am testing 4 current sensors and 4 ADCs at the same time, because I2C circuits are often intermittently reliable, so I can swap 4 identical circuits to find out which bad guy is causing trouble. I even have three TSX0104 based level shifted I2C channels to do swap troubleshooting. You may like to read the following thread for more details.
Strange I2C behaviour Strange I2C behaviour
Testing four ADS1015 ADCs alone, without ACS712 current sensor
Now that I have independently tested ACS712 current sensor alone, without ADC. Next turn is ADX1015 ADC, again manually tested alone, without ACS712. I will use a standard voltage reference, perhaps 3V or 3V3, to calibrate the 4 ADCs. By the way, ADS1015 uses a clever trick to enable one address pin (NOT the usual two hardware address/demux pins!) to address four devices, as illustrated below.
Now I am using KA431 as a 2.56V to 4.096V reference to test and calibrate the ADC. I used to use a Zener diode but I found it difficult to get Zeners with precise reference voltage, so I think KA431 a good replacement.
ACS712 Current Sensor Reference Voltage
While calculating the biasing resistor for the KA431 reference voltage to calibrate the ADC ADS1150, I suddenly remembered that ACS712 does not have internal analog voltage like ADS1150, and no external analog reference input like MCP3x0y. In other words, it only uses Vcc as the reference. No wonder earlier I found the no current centre point of 2.75V, instead of 2.50V as expected. The centre point is actually not offset by 0.25V, but because the Vcc was 2.75 x 2 = 5.5V! So I now know I need to use a precisely adjusted voltage supply for the current sensor. I searched my junk box and found a mini psu with fixed voltages LM2940-5.0 for 5V and AMS1117 3.3 for 3V3.
I mounted the PSU on a protoboard and input 5V to ACS712. Then I found Vcc = 4.99V and the no current voltage is 2.49V! In other words the ACS712 centre point accuracy is (4.99V/2 – 2.49V) / 2.5V ~= 0.2%. So now I guess the OP says his readings are fluctuating, perhaps his PSU is not stable, or noisely fluctuating.
Now I think I can also use the AMS1117 3.3 output as the voltage standard to calibrate the ADC, instead of wasting time wiring the KAxxx voltage reference.
Programming in Rpi python to check ADS1050 ADC
Now finally the time has come to program Rpi to check if ADS1050 ADC can accurately convert the voltage standard signal 3V3, output by AMS1117 3.3.
The first newbie program I am going to write is as suggested by the quick start guide in the datasheet, as pasted below. As usual, first thing first is try to read a register, second is writing something to a register and read back. This is usually the bottleneck, and may take me at least one day,
/ to continue, …
tlfong01’s Current Sensing Testing Diary https://penzu.com/p/4b805fb3
ACS712 Output Voltage vs Input Current Measurement Results YouTube Videohttps://youtu.be/sQBmYBdOc-c