The emonTx, emonTH and emonPi all use an ATmega328p 8-bit AVR microprocessor. This AVR microprocessor is Arduino compatible. You may want to modify and re-compile the firmware.
See Resources page for links to firmware repositories for all OpenEnergyMonitor units.
A USB to UART adapter is required to upload to emonTx / emonTH. Any 5v FTDI adapter can also be used.
Note: The method of compiling and uploading firmware is identical for the emonTx and emonTH. To upload firmware to the emonPi this can either be done by compiling locally then flashing .hex file (in the
.pioenvs folder in the project dir if using platformIO) then using avrdue on the emonPi to upload (see emonPi avrdude upload script or compiling and uploading using PlatformIO directly on the emonPi (see blog post.
Using Arduino IDE
Either PlatformIO or Arduino IDE can be used to compile and upload the firmware. This example will use PlatformIO since we consider it the easiest method. If you wish to use Arduino IDE see Offical Arduino Getting Started Guide.
PlatformIO is an open-source ecosystem for IoT development.
Cross-platform build system, IDE integration and continuous testing. Arduino, Espressif, ARM and mbed compatible.
See our blog post introducing PlatformIO.
1. Install PlatformIO IDE
Note: skip this section if your would prefer to use PaltformIO via it’s excellent command-line interface
These install steps have been tested to work on Linux, Mac and Windows.
The first time Atom IDE is opened after a few seconds PlatformIO will finish the installation and then display its home page.
Open emonTx Firmware
- Download emonTx Firmware GitHub repo either via git clone or downloading the zip and extracting.
- From the PlatformIO Home screen in Atom IDE choose
Open Project (1)*
- Navigate to the standard emonTx Firmware
- You should see the emonTx firmware files in the file-tree on the right-hand-side of the editor
- Once change has been made save then file then compile with PlatformIO by clicking
- If this is the first time the code has been compiled PlatformIO will ask if you want to install all the required libs that are specified in
platformio.ini. See PlatformIO library manager.
5. Upload Firmware
- If code compiles successfully upload the firmware by clicking on
- Note: A USB to UART cable is required to upload to emonTx / emonTH
- After successful upload check nodeID has changed by viewing serial output, click
Serial Monitor (4)and choose
PlatformIO Command Line
PlatformIO works great from the commandline, follow these instructions to install and run platformIO from the commandline. See the excellent PlatformIO Quick Start Guide for more info.
1. Install PlatformIO via commandline
The easiest way if running Linux is to use the install script, this installs pio via python pip and installs pip if not present. See PlatformIO installation docs:
$ sudo python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"
2. Clone emonTx / emonPi repo
We’ll use the emonTx (V3 discrete sampling) as an example here but the steps are exactly the same for emonPi.
$ git clone https://github.com/openenergymonitor/emontx3` $ cd emontx3/firmware
$ git clone https://github.com/openenergymonitor/emonpi` cd emonpi/firmware
3. Compile with PlatformIO CLI
$ pio run
4. Upload with PlatformIO CLI
$ pio run -t upload
The first time platformIO is run it will ask to install the required libraries and avr toolchain. The required libraries are defined in platformio.ini in the project folder.
4. View serial port with PlatformIO CLI
$ pio device monitor
For more PlatformIO commandline love see PlatformIO getting started