Jump to content
  • entries
    8
  • comments
    91
  • views
    7244

The energy meter experiment


SteamyTea

3562 views

I am not sure how well it works yet, but it works in trivial cases i.e. a 40 W lightbulb and my fridge (once I had stopped stray morning light).  I am going to ask my neighbours if I can pop the Photo Diode on their meter as I don't want to stop the one that is already logging mine.

What would be good is if others, who have a lot more knowledge and skills than me (I am really just a chancer than fiddles about till it seems to work) could improve and add to it.

Things that would be nice are a remote sensor to save having to run a small bit of wire into the meter box.  A nicely made sensor cover that holds the magnet in place, and does not let stray light in.  A display, and an enclosure for the complete kit (thinking of you @Onoff and your plastic printing skills).

Remote, but not cloud based access may be interesting, but as will all new toys, after a few days, does not get used often.

Other 'things' could easily be added i.e. temperature, humidity, air pressure, but they are really stand alone items, though inside and outside temperature is useful.

 

So here it is, my feeble attempt.

What I have used to make my energy meter.

 

A shop bought energy meter

image.png.44b162879c936548933df82915e1f754.png

https://www.ebay.co.uk/itm/354118466147

I used this purely to test the power, 1 pulse per Wh, same as my main meter.  I will, as I bought 3 of them, use them on my 3 ‘night circuits’ once I have finished playing.

 

Some magnets with holes in the middle

 image.png.d1ee01e9900a09cf73327fcc569f0070.png

https://www.ebay.co.uk/itm/184928442876

These are to hold the light dependant LED onto the meter.  A suitably sized metal washer was super glued in place.

 

Some photodiodes to sense the red flashing light on the meter.

image.png.78c2cdfc5d5a4250c4bbbdf7a4824e5c.png

 

https://www.ebay.co.uk/itm/232690475106

This is the real magic, just wired in between a GPIO pin, 22 in my case and ground.  The important thing is to wire it in the ‘wrong way around’.  So the anode, the longer leg on the diode, is wired to ground, and the cathode, the short leg, is wired to pin 22.

 

A Raspberry Pi ZeroW 

 image.png.f63769877b0d0bad228a50bb670403c1.png

https://thepihut.com/products/raspberry-pi-zero-w

Just a bog standard RPi ZeroW

 

A header

image.png.b30e76d2f034532ecadcc38c642e6ad1.png

 https://thepihut.com/products/colour-coded-gpio-headers

Are useful, and I think you can buy the RPi ZeroW with them already soldered in place.  You need it to easily fit the RTC on.

 

A Real Time Clock

image.png.cc19547f571911d1dbf924eb09c8bf78.png

https://www.ebay.co.uk/itm/234603677979

While not necessary, I always fit an RTC (real time clock) as I cannot guarantee an internet connection all the time.  You have to muck about with the /boot/config.txt file to include the line

 

dtoverlay=i2c-rtc,ds3231

 

and edit the /lib/udev/hwclock-set file to disable the settings with the # symbol

 

# if [ -e /run/system/system ] ; then

#    exit 0

#fi

 

A USB to TTL Serial adaptor

 image.png.f6390e4394ab8ee9961485c90575650e.png

 https://www.ebay.co.uk/itm/203604196200

Useful when setting up a ‘headless’ RPi.  Just make sure to change the /boot/config.txt to inclide the line

enable_uart=1

 

 

The Code

The code I have used uses Python3 and standard libraries.

After much searching and thinking, I found that GPIOZero library was quite useful (https://gpiozero.readthedocs.io/en/stable/api_input.html) as it has some useful code for a ‘button’, or switch to the rest of us.

I also, included a block of code to create a daily *.csv file that automatically changes the filename every midnight.

All the code does is sense when the light dependant LED senses light, and when that light stops, it timestamps the daily *.csv file, then wait until more light appears again.

Simple, 3 lines of main code.

 

#!/usr/bin/python3

from gpiozero import Button

import time, datetime

 

button = Button(22)

def sort_time():

            dt = datetime.datetime.utcnow()

            runday = dt.day

            dt.day == runday

            ts = time.time()

            UTC = datetime.datetime.utcfromtimestamp(ts)

            logfile = '/home/pi/monitoring/data/meter-%s-%s-%s.csv' % (dt.day, dt.month, dt.year)

            tfile = open(logfile, "a")

            tfile.write("%s"%UTC + '\n')

            tfile.close

           

while True:

            button.when_pressed

            button.when_released = sort_time

 

What could be simpler.

 

The output is presented like this.

 

2022-07-09 13:05:38.577239

2022-07-09 13:05:40.028295

2022-07-09 13:05:40.374854

2022-07-09 13:05:50.753515

2022-07-09 13:05:52.390287

 

Each timestamp is equal to 1 Wh.

 

I do all the analysis in a spreadsheet.

 

 

39 Comments


Recommended Comments



43 minutes ago, MikeSharp01 said:

I am having a real struggle getting the RTC to work reliably

Could you not use the time library with network time protocol instead?

Link to comment
26 minutes ago, SteamyTea said:

Some pictures of my 1wire therm and LED.

I know what you mean by LED but it might confuse others... now, if you called it an LRD, that would be more like it 😄

Link to comment
2 minutes ago, Radian said:

I know what you mean by LED but it might confuse others... now, if you called it an LRD, that would be more like it 😄

Yes, had just woken up from an after lunch snooze.

Or would that be dinner.

Link to comment
1 hour ago, Radian said:

Could you not use the time library with network time protocol instead?

Yes I thought of that but if I2C is not working then other things won't work and I need to have it available as I want the block to be universal - I have a few other I2C devices so I need to try them and see if it's the RTC, the library (which may not have been extensively tested on the ESP8266) or my circuit / associated capacitive issues. I have played with MQTT on it and thought I could use it to provide a time to all the subscribers so I still keep time if the internet is down.

Link to comment
29 minutes ago, MikeSharp01 said:

if I2C is not working then other things won't work and I need to have it available as I want the block to be universal

Around a decade ago I developed a Real Time Clock I2C module for CJE Micro’s to sell in the 'then new' Raspberry Pi market. I can't be arsed to resort to scope low-level issues with I2C these days. Not unless absolutely necessary. Have fun 😄

Link to comment
1 hour ago, Radian said:

Time Clock I2C module for CJE Micro’s to sell in the 'then new' Raspberry Pi market. I can't be arsed to resort to scope low-level issues with I2C these days. Not unless absolutely necessary. Have fun 😄

I have moved on and found an interesting bug. If I run the RTC on a nano it works fine, then I transfer it to the WEMOS, first run is fine but next upload it breaks and I get error 4. So for now I will put the RTC on the back burner and work on getting counts back to the server. See if can remember enough Node Red to get that going with MQTT from the device. Might be fun but no more time today. Chores🤨

Link to comment
21 minutes ago, MikeSharp01 said:

If I run the RTC on a nano it works fine, then I transfer it to the WEMOS, first run is fine but next upload it breaks and I get error 4.

Seem to remember our @Ed Davies having some quirks with RTCs, probably on his website.

Link to comment
26 minutes ago, MikeSharp01 said:

I have moved on and found an interesting bug. If I run the RTC on a nano it works fine, then I transfer it to the WEMOS, first run is fine but next upload it breaks and I get error 4. So for now I will put the RTC on the back burner and work on getting counts back to the server. See if can remember enough Node Red to get that going with MQTT from the device. Might be fun but no more time today. Chores🤨

Sounds like you have something pulling the GPIO0, GPIO2 and/or GPIO15 pins to the wrong levels at boot time. These are the boot control bits.

summary here

Link to comment

Yes, thanks for the heads up on the boot pins - had the GPIO15 with a pullup for the pulses. That has cured the boot from reset switch but the rtc is still error 4 - bus arbitration fault. (Nothing else on the SDA / SCL pins I can see.) 

Link to comment

Bugger me, just looked at the tracks above the board taking SDA and SCL from the RTC to the WEMOS lovely and parallel - so thought nice capacitor there, so bent them apart - see pic, works like a dream - dry joint or interference? 

16586902357401112689888500075683.jpg

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...