Flash image to Moteino USB device

Here’s a related question. I have been testing using a Moteino USB to act as an RFP69Pi. Thus far I’ve been loading the RFM69Pi firmware onto the Moteino using the Arduino IDE. I’m wondering, since the “Update Firmware Only” tool in emonCMS Admin can see my device on ttyUSB0, and since I can choose it, wouldn’t it be cool if it could update it? It doesn’t work, though.

LAST ENTRIES ON THE LOG FILE
-------------------------------------------------------------
emonBase_jeelib Firmware Upload
-------------------------------------------------------------
Downloading firmware from:
https://github.com/openenergymonitor/RFM2Pi/releases/download/1.4.0/firmware.hex

Downloaded file:
-rw-r--r-- 1 pi pi 22K Dec 7 2021 /opt/openenergymonitor/data/firmware/emonBase_jeelib.hex

EmonHub is running, stopping EmonHub

Uploading emonBase_jeelib on serial port ttyUSB0
Attempt 1...


avrdude-original: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "avrdude.conf"
User configuration file is "/root/.avrduderc"
User configuration file does not exist or is not a regular file, skipping

Using Port : /dev/ttyUSB0
Using Programmer : arduino
Overriding Baud Rate : 38400
avrdude-original: stk500_recv(): programmer is not responding
avrdude-original: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude-original: stk500_recv(): programmer is not responding
avrdude-original: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude-original: stk500_recv(): programmer is not responding
avrdude-original: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude-original: stk500_recv(): programmer is not responding
avrdude-original: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude-original: stk500_recv(): programmer is not responding
avrdude-original: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude-original: stk500_getsync() attempt 6 of 10: not in sync: resp=0x83
avrdude-original: stk500_getsync() attempt 7 of 10: not in sync: resp=0x84
avrdude-original: stk500_getsync() attempt 8 of 10: not in sync: resp=0x0c
avrdude-original: stk500_getsync() attempt 9 of 10: not in sync: resp=0x84
avrdude-original: stk500_getsync() attempt 10 of 10: not in sync: resp=0x0a

avrdude-original done. Thank you.

avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original: Using autoreset DTR on GPIO Pin 7
ERROR: Not in sync

Restarting EmonHub

I found that avrdude at the command line doesn’t work with 38400 baud, but does work at 115200 to update the firmware in the Moteino (output of both commands below). That said, the Moteino doesn’t respond in the Serial Monitor tool in emonCMS Admin after updating it in this manner.

pi@emonpi:/opt/openenergymonitor/data/firmware $ avrdude -v -c arduino -D -p ATMEGA328P -P /dev/ttyUSB0 -b 38400 -U flash:w:emonBase_rfm69pi_LPL.hex:i

avrdude-original: Version 6.3-20171130
                  Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                  Copyright (c) 2007-2014 Joerg Wunsch

                  System wide configuration file is "/etc/avrdude.conf"
                  User configuration file is "/root/.avrduderc"
                  User configuration file does not exist or is not a regular file, skipping

                  Using Port                    : /dev/ttyUSB0
                  Using Programmer              : arduino
                  Overriding Baud Rate          : 38400
avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original: stk500_recv(): programmer is not responding
avrdude-original: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude-original: stk500_recv(): programmer is not responding
avrdude-original: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude-original: stk500_getsync() attempt 3 of 10: not in sync: resp=0x9d
avrdude-original: stk500_getsync() attempt 4 of 10: not in sync: resp=0x74
avrdude-original: stk500_getsync() attempt 5 of 10: not in sync: resp=0x04
avrdude-original: stk500_getsync() attempt 6 of 10: not in sync: resp=0x84
avrdude-original: stk500_getsync() attempt 7 of 10: not in sync: resp=0x84
avrdude-original: stk500_getsync() attempt 8 of 10: not in sync: resp=0x0a
avrdude-original: stk500_getsync() attempt 9 of 10: not in sync: resp=0x0c
avrdude-original: stk500_getsync() attempt 10 of 10: not in sync: resp=0x04

avrdude-original done.  Thank you.

pi@emonpi:/opt/openenergymonitor/data/firmware $ avrdude -v -c arduino -D -p ATMEGA328P -P /dev/ttyUSB0 -b 115200 -U flash:w:emonBase_rfm69pi_LPL.hex:i

avrdude-original: Version 6.3-20171130
                  Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
                  Copyright (c) 2007-2014 Joerg Wunsch

                  System wide configuration file is "/etc/avrdude.conf"
                  User configuration file is "/root/.avrduderc"
                  User configuration file does not exist or is not a regular file, skipping

                  Using Port                    : /dev/ttyUSB0
                  Using Programmer              : arduino
                  Overriding Baud Rate          : 115200
avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original: Using autoreset DTR on GPIO Pin 7
                  AVR Part                      : ATmega328P
                  Chip Erase delay              : 9000 us
                  PAGEL                         : PD7
                  BS2                           : PC2
                  RESET disposition             : dedicated
                  RETRY pulse                   : SCK
                  serial program mode           : yes
                  parallel program mode         : yes
                  Timeout                       : 200
                  StabDelay                     : 100
                  CmdexeDelay                   : 25
                  SyncLoops                     : 32
                  ByteDelay                     : 0
                  PollIndex                     : 3
                  PollValue                     : 0x53
                  Memory Detail                 :

                                           Block Poll               Page                       Polled
                    Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
                    ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
                    eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                    flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                    lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                    calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                    signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

                  Programmer Type : Arduino
                  Description     : Arduino
                  Hardware Version: 3
                  Firmware Version: 5.0
                  Vtarget         : 0.3 V
                  Varef           : 0.3 V
                  Oscillator      : 28.800 kHz
                  SCK period      : 3.3 us

avrdude-original: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude-original: Device signature = 0x1e950f (probably m328p)
avrdude-original: safemode: lfuse reads as 0
avrdude-original: safemode: hfuse reads as 0
avrdude-original: safemode: efuse reads as 0
avrdude-original: reading input file "emonBase_rfm69pi_LPL.hex"
avrdude-original: writing flash (10106 bytes):

Writing | ################################################## | 100% 3.78s

avrdude-original: 10106 bytes of flash written
avrdude-original: verifying flash memory against emonBase_rfm69pi_LPL.hex:
avrdude-original: load data flash data from input file emonBase_rfm69pi_LPL.hex:
avrdude-original: input file emonBase_rfm69pi_LPL.hex contains 10106 bytes
avrdude-original: reading on-chip flash data:

Reading | ################################################## | 100% 3.53s

avrdude-original: verifying ...
avrdude-original: 10106 bytes of flash verified

avrdude-original: safemode: lfuse reads as 0
avrdude-original: safemode: hfuse reads as 0
avrdude-original: safemode: efuse reads as 0
avrdude-original: safemode: Fuses OK (E:00, H:00, L:00)
avrdude-original: Using autoreset DTR on GPIO Pin 7

avrdude-original done.  Thank you.

New question, new topic.

Probably because the reset pin is hardcoded to the pin the Hats are connected to on the RPi.

This command works. So maybe the script could be updated such that it uses avrdude-original for USB firmware updating, and the existing call to the script with GPIO reset pin for updates via the GPIO.

avrdude-original -v -c arduino -D -p ATMEGA328P -P /dev/ttyUSB0 -U flash:w:/opt/openenergymonitor/data/firmware/emonBase_rfm69pi_LPL.hex:i

Open an issue on the emoncms repo on GitHub and suggest it. It will, though be down the list as there are quite a lot of things demanding Trystans attention, and this is a bit of an outlier :slight_smile:

Before I open an issue on the repo to suggest this, I thought I would test it and see how well it worked. It doesn’t.

When I load the EmonScripts-supplied firmware into the Moteino USB using the following command, I get garbled serial output afterward.

avrdude-original -v -c arduino -D -p ATMEGA328P -P /dev/ttyUSB0 -U flash:w:/opt/openenergymonitor/data/firmware/emonBase_rfm69pi_LPL.hex:i

If I get the source (GitHub - openenergymonitor/emonBase_rfm69pi_LPL: emonBase rfm69pi LowPowerLabs radio format) and compile a .hex in the Arduino IDE, then load it using the same avrdude command, it works. The serial output is fine.

My guess was both devices (RFM69Pi and Moteino USB) would run the same .hex firmware, but I was incorrect. Looking at the bootloader part of the documentation, it explains the modifications to the clock that require a different build board.

A different clock source seems likely to explain the garbled serial I was seeing.

1 Like