Page 1 of 2

A power meter - using the Pyboard as a measuring instrument

Posted: Mon Oct 30, 2017 10:05 am
by pythoncoder
This project is for measuring power consumption of mains operated devices in the range 0-3KW. It performs true vector/phasor measurements and can integrate to determine the mean power consumption of switched devices such as freezers and pumps. It can handle devices with arbitrary power factors including those which both use and generate power. It uses the official lcd160cr display to provide a touch interface with uasyncio.
Image

Image

Here are illustrations of the display. It looks much better in real life than in my photography ;)
Image
The base screen. Measuring the power of my soldering iron.

Image
Our microwave oven has a small leading power factor. Note the phasor display; conventionally this should be rotated 90 degrees clockwise. To do.

Image
A plot of the current waveform, with the mains voltage as a phase reference.

Image
The integration screen. The mean and watt-hour total update continuously for as long as the screen is kept open. The mean display can be toggled by the button on the right to show the maximum power input to the grid (for generating devices).

The green PCB houses a transconductance amplifier for the current transformer, matched anti-aliasing filters for voltage and current signals and a programmable gain amplifier to extend the dynamic range of the ADC (for the current measurement only). However the device is remarkably accurate even when measuring my soldering iron on the 3KW range which says something for the Pyboard ADC's. Compare and contrast
Image

Image

Note that the plot screen provides a snapshot of the current sample set: it shows a single shot and is not a continuously updating oscilloscope display. The device takes 400 sample pairs of voltage and current as fast as MicroPython can do it. This is sufficient to capture two full cycles at 50Hz. It then processes and displays the result, before repeating the cycle. The result is an update rate of about 1Hz. The algorithm prioritises accuracy in the presence of noise over performance and I have made no attempt to improve the latter. I doubt that doing so would offer any benefit in terms of its utility as a measuring instrument.

I've now replaced the dodgy tie-wrap strain relief in the pictures above with proper cable glands. ;)

GUI code https://github.com/peterhinch/micropyth ... cr-gui.git.
I haven't posted details of the design as I doubt anyone else would want to build one, but if there's any interest I could do so.

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Wed Nov 01, 2017 6:19 am
by inakto
Cool project.
I really like the I, V graph display, gives you more detail than just a power factor number.

For making cutouts in plastic project boxes, I have a small chinese CNC mill that does a great job.
In my experience it's almost impossible to make a good looking box cutout by hand.

Does that toroidal transformer need to be that large? Or can it be done with something smaller.

I might be interested in building one actually, if you would share the details

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Wed Nov 01, 2017 8:29 am
by pythoncoder
The toroidal transformer is rated at 6VA - it was the smallest stocked at my usual supplier (CPC/Farnell). It fitted in the box so I used it. A smaller one would undoubtedly suffice if you can find one.

As for hand tools I was trained in metalwork where we were required to produce work in mild steel to +-0.005 inch tolerance using hand tools alone. Alas age has stolen the steadiness of hand required to achieve decent precision. A mill would be good.

I'll post code and schematics in due course but unless there's wider interest documentation will be rudimentary.

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Wed Nov 01, 2017 9:42 am
by rcolistete
Great device and interface !

I'm also interested, in the MicroPython code using the excellent Pyboard ADC, as well as the hardware schematics.

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Fri Nov 03, 2017 8:30 am
by torwag
pythoncoder wrote:
Wed Nov 01, 2017 8:29 am
The toroidal transformer is rated at 6VA - it was the smallest stocked at my usual supplier (CPC/Farnell). It fitted in the box so I used it. A smaller one would undoubtedly suffice if you can find one.

As for hand tools I was trained in metalwork where we were required to produce work in mild steel to +-0.005 inch tolerance using hand tools alone. Alas age has stolen the steadiness of hand required to achieve decent precision. A mill would be good.

I'll post code and schematics in due course but unless there's wider interest documentation will be rudimentary.
Hey Peter,

nice project! This looks like an super-version of a power-meter to me. Now, if there would be wifi and you could access those infos from a website generated on the device too, that would be great. My main concern with conventional power-meters always was the place where I would like to add them is often so hidden, that reading the values from a display is an artistic act. I noticed you used some wires already to be able to place the unit in a better "reading" position.

As for the power supply, I found those a while ago:
http://www.hlktech.net/product_detail.php?ProId=54
They are as small as a middle sized relay. Kind of handy. However, I never used them in a measurement set-up and never checked about the DC signal quality. Just thought that might help to create a even smaller version.

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Fri Nov 03, 2017 12:24 pm
by pythoncoder
I've posted some rather minimal documentation here https://github.com/peterhinch/micropython-samples.git - follow the link near the end of the README.

@torwag The transformer is used to safety-isolate and reduce the line voltage for measurement. Given that requirement, I felt it might as well power the unit too. In other circumstances I would have bought a switchmode module or wall-wart.

As for a WiFi version, the ESP8266 wouldn't work as it has only one (rather poor) ADC. We need two for phase measurement. An option would be to use my method of bringing MQTT to the Pyboard using an ESP8266 - I think that would be easily implemented.

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Fri Nov 22, 2019 2:53 am
by ta1db
pythoncoder wrote:
Fri Nov 03, 2017 12:24 pm
.. An option would be to use my method of bringing MQTT to the Pyboard using an ESP8266 - I think that would be easily implemented.
Hi Peter,
How can I learn more about your method of "bringing MQTT to the Pyboard using an ESP8266" ?
Thanks.

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Fri Nov 22, 2019 4:16 am
by jimmo
I'm sure Peter will reply in more detail, but I'd guess that https://github.com/peterhinch/micropython-mqtt is a good place to start.

Here's a recent thread discussing it -- viewtopic.php?f=18&t=7259

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Fri Nov 22, 2019 9:51 am
by ta1db
Hi Jim,

Thanks for your interest.

I am aware of the Peter's Mqtt library and the link you've provided. However, as far as I understand he has tested his library with esp8266, esp32 and pyboard d ( see https://github.com/peterhinch/micropyth ... ent-driver) not a pyboard with esp8266.

From above sentence I understand that he has another work as to use ESP8266 on pyboard as a wifi module. You know I am still looking for solutions to add wifi to stm32 boards without wifi.

Re: A power meter - using the Pyboard as a measuring instrument

Posted: Fri Nov 22, 2019 11:01 am
by kevinkk525
The micropython-iot project https://github.com/peterhinch/micropython-iot has a link from pyboard to esp8266 but doesn't use mqtt. It just provides a direct connection to the server included in the project that can be run on a raspberry pi for exmaple.