2

I've been searching through multiple forums, and gone to different links online trying to find a "cheap" solution to my question.

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. 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. This has lead to me to look into different options for sensors, rather than use an analog output sensor, 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.

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?
  • 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,

5
  • Since you say you've already got it working, the obvious USB option is to plug the arduino into the pi. Commented Feb 20, 2019 at 16:28
  • Sorry for responding so late. This is for a design project of mine, and the professor specifically wants a raspberry pi, and believe that having an arduino connected to a raspberry pi is a waste. With that being said, I have gotten it to work since I last posted this, but with fluctuating readings. If you have any experience with that, any help would be appreciated.
    – Aly Abed
    Commented Feb 27, 2019 at 14:25
  • You're probably better off asking on the electronics stack exchange about fluctuating ADC readings than adding to this question. Commented Feb 27, 2019 at 14:30
  • @PeteKirkham Note that sending people over to EE.SE with questions about electronic devices they buy online (rather than design themselves) may do them a disservice. Since the OP mentions a shunt, I guess they are not talking about the INA219 IC, but rather about a pre-made module. Commented Mar 8, 2019 at 9:18
  • @AlyAbed You can modify the shunt on the board and hope that people who designed the module didn't try to save every cent on copper and made a PCB which can handle 6.4A. It will likely work for factor 2x, but will likely fail for 10x or more. Commented Mar 8, 2019 at 9:21

2 Answers 2

3

########## The Question ##########

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!

enter image description here

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.

enter image description here

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.

enter image description here

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.26 https://www.aliexpress.com/i/32901786763.html

AdaFruit INA219 High Side DC Current Sensor Breakout - 26V ±3.2A Max $9.95 https://www.adafruit.com/product/904

enter image description here

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!

enter image description here

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.

enter image description here

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.

enter image description here

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.

enter image description here

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.

enter image description here

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,

enter image description here

/ to continue, ...

References

tlfong01's Current Sensing Testing Diary https://penzu.com/p/4b805fb3

ACS712 Output Voltage vs Input Current Measurement Results YouTube Video https://youtu.be/sQBmYBdOc-c

5
  • WOW! Thank you so much for such a thorough reply! I truly appreciate it. I do apologize in the lateness of my reply. I have been trying to figure out how to solve my problem on my own for a while now, and as you said it was my Vcc voltage that was "noisy" that lead to the ACS712 giving fluctuating readings. After solving that problem, I found that my ADC (MCP3208) was sending out data that was "noisy" as well, which is why I placed a capacitor between the ground and Vdd to filter that out. Though now, I see that the ADS1015 would be extremely useful and I might try and compare the two.
    – Aly Abed
    Commented Mar 27, 2019 at 21:36
  • I will keep you updated with my progress. The information you've provided has been very informative, and look forward to your next update!
    – Aly Abed
    Commented Mar 27, 2019 at 21:40
  • @Aly Abed: Nice to hear that you are making good progress. Actually I have very little experience on ACS712 and MCP3208, so I needed to google hard to find fluctuating readings of MCP3208. I started playing with ADS1015 because I think it is more advanced than MCP3208. Actually I am studying another even more advanced ADC, the ADS1256. You might read the following post for more details. Waveshare ADC Board negative value issue (raspberrypi.stackexchange.com/questions/95843/…)
    – tlfong01
    Commented Mar 28, 2019 at 14:15
  • @Aly Abed: I spent more than 20 hours playing with ADS1015, trying out basic things, but now got stuck in reading two bytes from I2C, providing I2C device address but not register address. It appears that Python smbus functions does not work in this case. It is sort of write block and read block. I once tried write block and found it OK. But I2C read block seems not compatible with smbus. I googled hard but sadly concluded it is dead end for me. So I am thinking of jumping to ADS1256/AD7190. If your schedule is tight, I would suggest you to first complete the project using MCP3208,
    – tlfong01
    Commented Mar 29, 2019 at 9:06
  • that's very interesting. My schedule isn't that tight. My plan so far is to get the system to work using the MCP3208, and then once I am satisfied with the system, I will move forward and start "upgrading" components. I'll be researching the ADS1256 in parallel with working on the current system. Thank you for the recommendation!
    – Aly Abed
    Commented Mar 29, 2019 at 9:59
2

The INA219 does not have a maximum measured current, only a maximum measured voltage (26V). I suspect you've run afoul of this annoying recent trend of naming a breakout board the same as the IC it is breaking out.

To be clear, this is what an INA219 looks like:

enter image description here

And this is what a popular INA219 breakout from Adafruit looks like (the actual INA219 is below the "R5" designator):

enter image description here

So to answer your most important question, yes you can definitely modify the sense resistor to change the maximum measured current. When modifying the sensor resistor, make sure:

  1. you use a high precision (low percentage) and low thermal coefficient resistor. This is typically what makes a resistor, a "sense" resistor;
  2. you do not exceed the INA219's maximum voltage;
  3. you do not exceed the power rating of the sensor resistor - to find the power absorbed by the resistor, multiply the resistance by the maximum current squared. Eg. if you put a 0.1Ω resistor in parallel and half the 6.4A is flowing through it, it must be rated at at least 0.1 * 3.2 * 3.2 = 1W. Note the power rating will not be as good if the resistors are stacked on top of each other.

It seems to me that modifying the sense resistor is the fastest road to success you have available to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.