MicroPython scriptable, wifi enabled, dc-powermeter (36V x 15A ~ 500W). Build around espressif's ESP8266 soc and TI's INA260 current-sensor. Open Source Hard- & Software.
The MicroPowerMeter (MPM) can be used, to measure voltages between 0-36 V, currents between 0+-15 A and both current, and voltage at the same time to measure the power consumed by a load or produced by a generator.
Measuring: a) voltage, b) current c) power.
You can read the measured values on your phone or any wifi enabled device with a webbrowser. Alternativley you can send the values to another webserver and store them to be viewed from somewhere else. A third option is storing the data on the microcontoller to download them later (not jet implemented).
You can turn on the MPM by connecting it to a 5V batterypack or a phonecharger. There is no on/off switch, it will turn on immediatly and run the boot.py script.
During the boot section the MPM exceptcs a wifi device to connect to the wifi access point with the ssid: "MicroPowerMeter". The password can be found/changed in the boot.py file. Would be nice if it tried to log in to the last/known wifi network first. Anyone keen to implement that?
Once your phone is connected you can open a browser and enter http://192.168.4.1/ in the url-field. A get-request for the file index.html will be sent from your phones browser to the microcontroller. The microcontroller resonds by sending back the requested file. In the header section of the index.html file a few other files (.css and .js) are requested and will be send to your browser. When all files are transfered an interval function triggers a get-request every 500ms asking the microcontroller for new sensor data. Once received the ui will update.
Fig.: UI preview filled with random data.
- Vcc = 5V - so you can use your USB powerbank as supply
- 4MB Memory - to store captured data (csv/txt)
- U_sens = 0 - 36V
- I_sens = 0 ± 15A + - 1.5mA
- P_max = U_sens_max * I_sens_max = 540W
Building this powermeter will not only give you a handy tool for your electronic projects, it will also help you understand the concepts of current, voltage & electrical power, along with the basics of IoT-devices, sensors and microcontrollers.
All the required parts are listed in the bill of materials (BOM) below. Additionaly you will need a 5V powerbank, a wifi enabled device with some kind of webbrowser and some fillament for the enclosure.
* there are different versions of this board available. Only the version shown in the BOM works for this project. You can also use standard prototyping board and cut it to size.
The rectangle on the left labeled Wemos D1 mini is the dev board for the esp8266. On this printed circuit board (PCB) sits the ESP8266, a wifi antenna, a reset button, a micro USB-port and the IC for a serial connection to your computer. On the right you see the breakout board for the current sensor (INA260). In this tiny IC is where the magic happens.
Assembling the electronics requires some soldering. If you have never soldered before check out this awesome soldering guide by adafruit.
Solder the two female pin-headers to the wemos D1 mini.
Unfortunatly the sensor can not directly be connected to the Wemos D1 mini. A adapter board is needed. The following pictures show the soldering process of the adapter board. If you are familiar with KiCAD, or any other e-cad software please consider having a look at the to-do list. This might be the most difficult part, (you might want to get a drink before you start.)
If you have a 3D-printer or the fab-lab is not to far you can print an enclosure for your device. You find the .stl files in the hardware directory of this repo. There is also a Blender file, in case you want to add custom text.
Download CAD-file as [.blend]
Micropython Firmware
RESTfull Webserver
- d3
In order to tell the microcontroller what we want it to do we need to write some code and store it on the microcontroller. We will be using MicroPython as the programming language and Pymakr to communicate with the microcontroller.
Pymakr is a plugin, available for the code editors Atom and VisualStudio Code (VS-code). Both are free and Open Source and available for Windows, Linux and Mac. This guide will show you how to set up the IDE on a Microsoft Windows using visual studio code.
Open VS-code und navigate to the extensions panel. Search for pymakr and click install.
If this is your first time using micropython please have a look at the more general guide.
Search for the latest stable firmware version for the ESP8266 on MicroPythons Download page and download the .bin file.
In a terminal type:
$ pip install esptool
Connect the MCU to your computer and search for the serial port it got connected to.
$ dmesg | grep tty
[ 36.460270] usb 3-1: cp210x converter now attached to ttyUSB0
What we are looking for is the "ttyUSB0" (on Windows this should be something like "COM0", you can look it up in the device manager)
Now we will first erase the flash of the MCU by typing:
esptool.py --port /dev/ttyUSB0 erase_flash
Flash the firmware-file to the MCU by typing:
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 ~/Downloads/esp8266-20191220-v1.12.bin
make sure to replace the serial-port and filename if you downloaded a newer version.
Clone or download this repository and open the folder in your editor (VS-code/atom). Open the pymakr.conf file and change the following two lines:
"address": "/dev/ttyUSB0",
"sync_folder": "software",
The first line tells pymakr on which serial-port to look for the MCU. The second line makes sure only the software files will be uploaded to the MCU.
Press the "Pycom Console" button at the bottom of your editor to connect to the MCU. (check if the pymakr-plugin is enabled, if you can't find it).
Then press the "upload" button. After the upload process is done, the MCU will reboot and you can access the webserver by connecting to the WIFI access point called "MicroPowerMeter". The password is "ohms_law". You can change the ssid and the pwd in the file "/Software/boot.py" if you like.
Have a look at the to do list. If you feel like one of the tasks is yours, you can clone this repo, commit your changes and post a pull request. So fare everything you can find in this repo has been created using free & open source software. If you contribute, it would be great if you follow this pattern.
- Documentation
- add missing parts (D1z proto, 4mm gold connector) to fritzing library & update layout.png
- write guide on how to send, store and graph measured data on external webserver (for example via mqtt, influxDB, Grafana)
- write guide on how to use boolean operators in blender to change the text
- Firmware
- use server-sent-events or websockets for sending sensor-data
- add code for status led's (hearbeat on connect, blink while waiting for connection, etc.)
- make webserver asynchron
- allow client to cache static files - to reduce traffic/load time on second connection
- add proper gzip-ing
- move sensor reading away from the get-request -> setup a timer
- write data to .csv file
- add proper logging
- function complete library for ina260
- Web-Frontend
- integrate webREPL in UI
- improve UI (please post inspiration in issue
- add user guide
- Hardware
- design stackable enclosure
- design custom pcb for INA260 to replace D1z proto and adafruit INA260 (reduce cost, size and assembly time)