EmonTX to Rpi - Direct Serial Connection

Took my life in my hands and Success!! :grinning:.

Having installed the system using the emonScripts, some of the elements were already in place.

First compile the sketch. I know that @Robert.Wall is not keen on PlatformIO, but on the Pi it installed and worked flawlessly as described here GitHub - openenergymonitor/EmonTxV3CM: EmonTxV3 Continuous Monitoring Firmware (Default shipped EmonTxV3 firmware). The only oddity is creating the hex file. That instruction says use the upload option but that of course complains (although is does create the hex). A bit of digging and I created a new environment in the platformio.ini and an extra_script.py. This then creates the hex cleanly. The avrdude-rpi repo is created and installed by the emonScripts on the Pi so that was all ready to use (bar editing it to change the pin number for reset). Stopped the emonhub service first then ran the avrdude command as listed in the docs above and hey presto.

It has taken me quite a while, pulling the various bits of documentation together have taken time, but pretty pleased I got there in the end.

PlatformIO environment for the ini file (just adds the extra_scripts line).

[env:emontx_pi]
platform = atmelavr
framework = arduino
board = uno
build_flags = ${common.build_flags}
lib_deps = ${common.lib_deps_external}
monitor_speed = ${common.monitor_speed}
extra_scripts = post:extra_script.py

The extra_script.py file

Import("env", "projenv")
from shutil import copyfile

def save_hex(*args, **kwargs):
    print("Copying hex output to project directory...")
    target = str(kwargs['target'][0])
    copyfile(target, 'output.hex')
    print("Done.")

env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", save_hex)   #post action for the target hex

to build (first run pulls in the Libraries)

pio run -v -e emontx_pi

You need to edit the file /opt/openenergymonitor/avrdude-rpi/autoreset and change the pin number to 12.

to upload (having stopped emonhub)

avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:firmware.hex

[edit]
The extra script is now available in the repository as is a new platformio.ini file so the compile command should just work. (14/8/20)