On a recent project I needed to fairly accurately measure current and power consumption of a handful of parts in real time. We needed to measure current in the range of micro amps, so this was actually somewhat tricky.
I _could_ have just used a bunch of super expensive current meters, but I managed to find a much more convenient and cheap solution using a Raspberry Pi. We were already using a Pi to allow for remote debugging, so I went looking for something I could hook up to that.
I found these ADCs:
– [ADC to measure small delta voltage](https://www.abelectronics.co.uk/products/3/Raspberry-Pi/14/Delta-Sigma-Pi)
– [ADC to measure larger voltage from ground](https://www.abelectronics.co.uk/products/3/Raspberry-Pi/17/ADC-Pi-V2—Raspberry-Pi-Analogue-to-Digital-converter)
They plug right into the GPIO headers on the Pi and even come with some [python libraries for reading them.](https://github.com/abelectronicsuk/ABElectronics_Python_Libraries)
Using a tiny shunt resister inline with Vdd, we can use those ADCs to measure the voltage drop across the shunt resister to get the current, and combine that with the voltage at Vdd to the power. We ended up with a circuit that looks like this:
The resulting circuit lets us measure currents from 1uA to 4.6mA with a precision of +-0.5uA, which is plenty good for our purposes. We can also adjust the gains on the ADCs in software to give us more range at the expense of precision.
And we can do it remotely! The Pi can be wired into our hardware, and we can just ssh into it to get live power measurements. And there are 8 channels on those boards so we can measure (and log!) the power consumption of 8 different components simultaneously. It’s super convenient.
Can you give the code you used to get the measurements?
So I didn’t provide the code mainly because 1) It’s super ugly, and 2) It’s fairly specific to our particular setup.
But here it is, in all its ugliness: https://gist.github.com/jvranish/efdefaf37ffcf345ce56
Absolutely no warranty towards its usefulness but maybe it will be helpful to somebody.
As I said, it was adapted from some examples here: https://github.com/abelectronicsuk/ABElectronics_Python_Libraries
I would look there if you’re wanting and example or demo to start from.
I would like to use the raspberry pi to measure either voltage or current for a high power device with voltage of 12-24 volts and high current. I understand that the raspberry GPIO is limited to small voltage of about 3v and maximum current of a few mA. How can i overcome this problem please
I have a similar problem to yours. The only difference is that the device that I want to use, has a range of values between 0-12V.
I’ve thinked about using a voltage divider before each ADC. It might not be the best option but it might work. Do anybody have any other better suggestion?
Hi gents, I have two Pi’s sitting doing nothing and would like to use them as metering devices too. Metering of 8 different circuits 230 v or 380 v (3ph). Can you help with where I get what’s needed to set this up with the Pi? Job do I need you ADC’s to do this and am I right that you can also program the Pi too?
how to use rasp pi as an electricity meter???
I’m a bit late to this party but just curious if anyone knows the approximate ideal value of the shunt resistor?
Comments are closed.