I am new to this forum and Raspberry pi. Our team is attempting to build an IOT Energy sensor/monitor utilizing a raspberry pi zero and a non-invasive ac current monitor. Has anyone done this before? Our raspberry pi does not have an audio jack, so we would like to hardwire the sensor/clamp into the board. Any insight would be greatly appreciated.
There is a huge amount of insight on this site, itâs mainly documented in the Resources section. Iâd suggest you take a look at that first and then if you have any specific questions come back on the forum.
To answer your specific question on the pi zero and a non-invasive ac current monitor, assuming you mean a current clamp as used with the emonTx then the answer is yes but youâll need an ADC device as well. I think some people have done this with an ADC hat for the zero.
Dig around and Iâm sure a) youâll learn a lot and b) you might even find what you are looking for.
As Simon says, it canât be done directly using only a current transformer and a Raspberry Pi, because the Pi does not have an analogue input. You need to add a means of converting the analogue output of a c.t. into digital form that the Pi can handle - thatâs what the ADC device does. When youâve done that, then if you canât find what you need in Learn (for the basic principles) or Resources (for actual designs of units in production), then ask.
I have done raspberry pi with non-invasive current clamp sensor, using mcp3008 a/d 10bit, added a 4 channel level shifter to allow the mcp3008 to run at 5.0v, while feeding back to raspberry pi spi communications at 3.3v, this allow the Mcp3008 chip to do 200,000 samples per second. It also needed a voltage divider to shift up the analog reading to all positive values so that it can be fed meaningfully into mcp3008.
Once I installed the lib from adafruit mcp3008, the pi immediately able to read the analog signal, but the voltage from the non-invasive current transducer will be fluctuating, and that is how it is for ac power, to get something meanful, we calculate current by using rms, by summing up each reading from mcp3008 at about 6000 counts per second, then squared each value, sum them all up, then divide total number of samples, and finally, take the square root, all these are one within a split second, and I watched my raspberry CPU went to 40% on one of the 4 CPUs during the process. I am using the act-130-30 30amp at my furnace blower fan, my Chinese clamp meter read 1.95 to 1.98 amp, my raspberry pi read about 1.96 to 1.97amp, I have since then output the reading to a text file and save to sd card as log, it can also catch inrush current, when my heat pump runs, I saw current draw about 3 times higher for moment, then staplized at about 17.8amp per leg, works pretty well
here is my code,
i took the adafruit_python_MCP3008 simpletest.py
and added the emonlib irms calculation function,
adjusted the ical value, it gives me an accurate AC current,
for some reason, i copied and pasted my python code here, and it seems like formatted to something different than my python, any other suggestion how i can share my raw python code?
I have some mcp3208âs somewhere that Iâd like to try one day. I couldnât see a sample frequency published for 3.3v, only for 2.7v(75KHz) and 5v(200KHz). I was wary of running them at 5v as the increased burden values increase the phase error, but looking at the spec sheet they seem to have a separate Vref so it is possible to use 5v to get the sampling frequency whilst using a lower Vref (3.3v or even less) to avoid swings in the CT phase error. That of course isnât an issue for you if you are just measuring current, not real power.
the ref_voltage is the voltage supplied to MCP3008 pin15, multiplied by 1000
ref_ical would be the rating of the clamp sensor, in my case, it would be 30, because i have the the SCT-013-30, 30amp current sensor,
the MCP3208 is the higher resolution version of MCP3008, i think both of them will work
i have a voltage sensor to measure the AC voltage, together, voltage X current will gives me Watt.
the MCP chip can run either on 3.3v or 5v with bi-directional level shifter. whether at 75k samples per second or 200k samples per second is far beyond my 6000 samples per seconds need, the rms took care of the swing in ct, i am not sure the impact or bottleneck on raspberry SPI, since i am reading the AC current every 5 seconds interval, it seem to be stable and accurate, I have two raspberry pi 3, each is wired to one 30 amp CT, one running MCP3008 at 3.3v, one with 5V and level shifter, i am not able to tell any performance or accuracy difference
I thought you were running at 5v just to get the 200ksps. If you are only sampling at 6ksps why are you running at 5v? 3.3v would have been fast enough and avoided using levelshifters,
The operating voltage and reference voltage are different things. For example you are using a 30A CT from YDHC that outputs 1v, so if you currently have vref at 5v you are only using ~20% of the ADC (at full 30A load) making the ADC operate at less than 8bits effectively.
At 3.3V you would be using just over 30% of the ADC or effectively 8.5âish bits.
Over on the STM32 development thread we have been discussing the possibility of using a 2.0v Vref, thatâs as low as the STM will allow, but the mcpâs seem to allow down to 0.25v so a 1.0v Vref to make full use of the ADCâs resolution (with a 1.0v CT) might be possible.
That can only give you apparent power, which will be fairly accurate when measuring a purely resistive load such as a kettle or immersion heater etc. To measure real power you need a more complex calculation and the timing of the voltage signal compared to the current signal becomes very important, hence the concern about phase error.
I was referring to phase error, that is not related to the RMS. The lower the burden value the less the waveform shifts and the more linear the shift across the range of the CT. Normally (with a sct-013-000 100A CT) you would select a burden to give you full use of the adc at the capacity of the CT (eg 33R at 5v or 22R at 3.3v) the lower the value, the more linear the phase error and therefore easier to correct. Since you are using voltage output CTâs, the burden is already selected and itâs probably pretty low to give a 1.0v output.
See the learn section for more info on calculating real power and correcting phase error.
[Edit - RW] ⌠and to see how the phase error changes with burden value.
assume your hardware circuit is correct, if there is any AC current flowing through the Current sensor, the Raw number is an instantaneous reading of current at your interval of every 5 seconds, suppose to be fluctuating, like a sine wave, higher the current, bigger the fluctuation.
the rms (root mean square) of 6000 samples will give you AC current in amps,
did you build your circuit from breadboard, or soldered into a wafer board?
i learned a hard lesson when soldering, forgot to clean up the flux paste, in my case it make a huge different because i am using a DC biasing circuit to up-shift the voltage to positive, after i use q-tips and rubbing alcohol to clean out the every flux paste, the circuit has been working beautifully.
if there is no current floating, the raw reading should be steady at 512, will translate to nearly 0 amps.
i highly suspect problem maybe your circuit has been mis-wired.
i am using the dc-bias circuit with four 10k ohm resistors and two 10 uF capacitors similar to the last picture on the following link.
Indeed. That means that the result for every c.t. will be put into ct[0], therefore when you print the value, you will print the last value that was put into ct[0].
I was using the SCT-013-020, SCT-013-030, SCT-013-060, SCT-013-100, the blue color one from ebay, and output 1V, the python work fine
then i also tried the Magelab SCT-0750-150, output 0.333V instead 1V, and when i tried to turn on the heatgun, handheld clamp amp meter read 10.6amp, but python read 3.5 to 3.6amp, if i were to multiple the python reading by 3, then i will get the correct reading, is the op amp best way to amplify output voltage to get more accurate reading?
Look at âLearnâ and the derivation of the calibration coefficients. I know it is rather complicated, but that explains why your reading is wrong.
You can amplify the input voltage, or you might be able to reduce the analogue reference that your ADC uses, and thereby increase the sensitivity of the input.
This is the reason why we donât encourage the use of voltage output c.tâs, and especially 0.333 V output c.tâs.
But of course, it is always best to size the c.t. to suit the load you are measuring.
as you suggested,
i played around with my dc biasing voltage divider a little bit, and added two resistors for the analog ref voltage of MCP3008, reduce voltage to 1v instead of 3.3v, the divider voltage became 500mV, and also change the python code in raspberry pi, instead of amplify the Magnelab SCT-0750-200 output voltage from 0.333v to 1v with rail to rail op amp.
now i have a nice and accurate amp full resolution reading from raspberry pi
when the house appliance like the fridge, fans, tv turn on and off periodically, even the led lights, i do see the the reading swings up and down according.
you must study the data sheet for your MCP3008 and work out what the calibration will be for your c.t. You know the c.t. produces 1 V rms for 30 A rms input, and you know the MCP3008 converts voltage over a range 0 - VREF to numbers over the range 0 - 1023, so you must calculate using those values.