Trouble with Raspberry Pi 4 and avrdude programmer

Hi there.

I’m testing a PCB similar to EmonPi with some tweaks of my own and I’m having trouble programming the firmware to it with avrdude.
My board has the same connections from the 328P to the RPi GPIO header as the original emonPi and I’m using a recently downloaded SD image.
EmonHUB service is stopped.
The 328P used was pulled up from an Arduino Nano I had laying around (the JLCPCB price for it was unacceptable) and coincidently it has a random energy monitoring firmware (maybe one adapted by me for one of my projects).
I can do the command “screen /dev/ttyAMA0 38400” and if I press any key it will return “J i10 g210 @ 433 MHz”, so this means that the 328P is running and the RX/TX communication is good.
With some shell commands I was able to pull pin 7 (GPIO 4) down and up again and was able to detect that the 328P was reset by opening the screen command immediately after and watching the boot-up messages.
But avrdude won’t reset it with the command “avrdude-autoreset -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200” or program it with the command “avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:/root/FirmWares/MyEmonPi_NewBoard_2022.ino.eightanaloginputs.hex”

Here is the output for both commands:

avrdude-autoreset -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200

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/ttyAMA0
              Using Programmer              : arduino
              Overriding Baud Rate          : 115200

avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original: stk500_getsync() attempt 1 of 10: not in sync: resp=0x1c
avrdude-original: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe0
avrdude-original: stk500_getsync() attempt 3 of 10: not in sync: resp=0x8e
avrdude-original: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
avrdude-original: stk500_getsync() attempt 5 of 10: not in sync: resp=0x1c
avrdude-original: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude-original: stk500_getsync() attempt 7 of 10: not in sync: resp=0xf0
avrdude-original: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude-original: stk500_getsync() attempt 9 of 10: not in sync: resp=0x1c
avrdude-original: stk500_getsync() attempt 10 of 10: not in sync: resp=0x0e

avrdude-original done. Thank you.

strace: |autoreset: Broken pipe

avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:/root/FirmWares/MyEmonPi_NewBoard_2022.ino.eightanaloginputs.hex

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/ttyAMA0
              Using Programmer              : arduino
              Overriding Baud Rate          : 115200

avrdude-original: Using autoreset DTR on GPIO Pin 7
avrdude-original: stk500_getsync() attempt 1 of 10: not in sync: resp=0x1c
avrdude-original: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe0
avrdude-original: stk500_getsync() attempt 3 of 10: not in sync: resp=0x8e
avrdude-original: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0
avrdude-original: stk500_getsync() attempt 5 of 10: not in sync: resp=0x1c
avrdude-original: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe0
avrdude-original: stk500_getsync() attempt 7 of 10: not in sync: resp=0xf0
avrdude-original: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude-original: stk500_getsync() attempt 9 of 10: not in sync: resp=0x1c
avrdude-original: stk500_getsync() attempt 10 of 10: not in sync: resp=0x0e

avrdude-original done. Thank you.

strace: |autoreset: Broken pipe

Any idea how to overcome this programmer problem?
This should be a common problem with the original EmonPi on an Raspberry Pi 4.

Cheers.

Are you trying to program this from a EmonSD based setup?

The avrdude command is redirected if you are. Took me a while to unpick the redirected symlinks.

This was how I programmed an EmonTX directly from an EmonSD based Pi.

Not sure if it will help :slight_smile:

Hi.
I will look into that information.
I’m using emonSD-21Jul21.img

Everything else seems ok, at least to the point of configuration where I am now.

Cheers.

1 Like

I found the problem.

The bootloader in this 328P does not support 115200 bps for programming.
This is the correct command for the bootloader I have:

avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 57600 -U flash:w:/root/FirmWares/MyEmonPi_NewBoard_2022.ino.eightanaloginputs.hex

Later I will try to update the bootloader to the newer version, but it seems that I have to use the ICSP pins with an external programmer (e.g. a nano) to do that.

Cheers.

1 Like