Hi again,
I’ve been able to edit the change, compile it and run it on the microcontroller. I had some problems along the way but persistence paid off. Things to note on the emonpi are that the baud speed is 38400 and the reset pin is pin 7. I currently have emonpi set to update every 2.5 seconds but I will update this with further info if I push it faster.
I actually find the connection between the pi and the arduino quite tempermental, it only rarely works, I sometimes had to use:
sudo avrdude -v -p atmega328p -C /root/.platformio/packages/tool-avrdude/avrdude.conf -c arduino -b 38400 -D -P "/dev/ttyAMA0" -U flash:w:.pio/build/emonpi/firmware.hex:i
Has anyone else found this?
Here are my notes for anyone who wants to increase the speed of updates from emonpi that are sent to mqtt:
sudo su
systemctl stop emonhub
sudo pip install -U urllib3
sudo pip install -U platformio
cd /opt/openenergymonitor/emonpi/
git pull origin master
cd /opt/openenergymonitor/emonpi/firmware/src
EDIT CHANGES AND SAVE > TIME_BETWEEN_READINGS= 5000; in:
touch extra_script.py
nano extra_script.py
and paste >>
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
cd /opt/openenergymonitor/emonpi/firmware
/root/.platformio/penv/bin/platformio project init
nano platformio.ini
add reference to extra_script.py >
[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
cd /opt/openenergymonitor/emonpi/firmware
sudo platformio run
open a parallel connection to view communication between the pi and the arduino:
miniterm --rtscts /dev/ttyAMA0 38400
sudo platformio run -t upload
sudo service emonhub start