This post is about evolving the energy monitor firmware to use Python instead of the Arduino IDE. It’s been awhile since I discussed the pieces of this project. Most of this post is about the firmware running on the Energy Monitor.
Here is the “bigger picture” of the HappyDay Neighbors prototype:
The prototyping environment Circuit Python enables makes me smile. It is for this reason I evolved the environment such that the Energy Monitor:
The goal of this post is to run a Circuit Python script on the Huzzah that publishes energy readings to an mqtt broker. I want to document what I have done to ensure I and others can have the opportunity to not repeat my bumblings or gain a spot of insight that shortens the amount of time to get a prototype out.
Circuit Python Libraries
We need access to the ATM90e26 and mqtt. Here’s how I did it:
There is a Python Script running continually on the Huzzah and on the Raspberry Pi. The Huzzah’s script is using mqtt to publish energy readings. The Raspberry Pi subscribes to the mqtt messages and then appends them to a local file.
- The python script running on the energy monitor’s Huzzah is main.py. NOTE: I don’t like storing my WLAN ssid and password on GitHub. So to run main.py, there also needs to be a file network_credentials.info in the same directory as main.py. There is one line in the file: ssid,pwd:
|(full_filename, ) :|
NOTE: The challenge at this point is stopping the While True: loop so we can fix the code as needed. The code does nothing to allow us to cut in. Rather, it runs continually…sleeping for some amount of time and then taking another reading. When I was trying to access the Huzzah with main.py running using ampy, I got:
ampy.pyboard.PyboardError: could not enter raw repl
What to do? What to do? ( First, I thank @deshipu on Adafruit’s circuit python).
$ screen /dev/tty.SLAB_USBtoUART 115200
ctl-b into REPL
Yippee! there is no longer a main.py…so now I can get into ampy!
The Raspberry Pi is running the mosquitto mqtt broker.
- The python script running on the Raspberry Pi is WriteEnergyReadingsToCSVFile.py
Here is a link to a Google spreadsheet that contains the readings. A previous post describes taking energy readings in North America and why there are two voltage, current, etc. readings. This is why there is a v1 and a v2…etc.
A very HAPPY time. It works…. at least for now :-). Thanks for reading this far. Please find many things to smile about.