# Avrdude not in sync errors attempting to update emonTx firmware

**URL:** <https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691>\
**Category:** emonTx\
**Created:** [6 May 2021 00:11 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691 "2021-05-06T00:11:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sage-Energy](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sage-Energy](https://community.openenergymonitor.org/u/Sage-Energy)\
**Post date:** [6 May 2021 00:11 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691/1 "2021-05-06T00:11:13Z")

</div>

Hi all,  
Having another crack at direct avrdude firmware programming of the emonTx via wired UART serial connection with a RPi. I’ve googled and searched but can’t find any clear ideas what’s going wrong - be grateful if someone can point me in the right direction?

I’ve tried 9600, 38400 and 115200 baud rates and the only difference in the errors is that at 115200 there’s an additional “programmer not responding” line.

I’ve also stopped the emonhub service first and checked via cat/dev/ttyAMA0 and the emonTx is still outputting data on the serial port but nothing else appears.

I’ve changed the reset GPIO pin to GPIO12 (BCM 18) in the autoreset file in /usr/bin/ and connected up the appropriate wires.

Here’s the shell output:

```auto
pi@emonpi:~ $ avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 9600 -U flash:w:/home/pi/emonTx_3Phase_PLL.ino.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 : 9600
avrdude-original: Using autoreset DTR on GPIO Pin 12
avrdude-original: stk500_getsync() attempt 1 of 10: not in sync: resp=0x4f
avrdude-original: stk500_getsync() attempt 2 of 10: not in sync: resp=0x70
avrdude-original: stk500_getsync() attempt 3 of 10: not in sync: resp=0x65
avrdude-original: stk500_getsync() attempt 4 of 10: not in sync: resp=0x6e
avrdude-original: stk500_getsync() attempt 5 of 10: not in sync: resp=0x45
avrdude-original: stk500_getsync() attempt 6 of 10: not in sync: resp=0x6e
avrdude-original: stk500_getsync() attempt 7 of 10: not in sync: resp=0x65
avrdude-original: stk500_getsync() attempt 8 of 10: not in sync: resp=0x72
avrdude-original: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe7
avrdude-original: stk500_getsync() attempt 10 of 10: not in sync: resp=0x4f

avrdude-original done. Thank you.

strace: |autoreset: Broken pipe

```

Anyone spot anything I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![Bill.Thomson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/bill.thomson/32/1834_2.png) [@Bill.Thomson](https://community.openenergymonitor.org/u/Bill.Thomson)\
**Post date:** [6 May 2021 00:41 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691/2 "2021-05-06T00:41:16Z")

</div>

Have you tried swapping the data Rx and TX lines?

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [6 May 2021 06:46 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691/3 "2021-05-06T06:46:33Z")

</div>

> [@Sage-Energy](#):
>
> I’ve changed the reset GPIO pin to GPIO12 (BCM 18) in the autoreset file in /usr/bin/ and connected up the appropriate wires.

Obvious question, but you have connected the rst pin to that pin on the Pi?

> [@EmonTX to Rpi - Direct Serial Connection](https://community.openenergymonitor.org/t/emontx-to-rpi-direct-serial-connection/13114/48):
>
> You need to edit the file `/opt/openenergymonitor/avrdude-rpi/autoreset` and change the pin number to 12.

I edited a different file when I did it.

Did you stop `emonhub` first?

---

<div class="post-metadata">

**Author:** ![Sage-Energy](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sage-Energy](https://community.openenergymonitor.org/u/Sage-Energy)\
**Post date:** [6 May 2021 08:50 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691/4 "2021-05-06T08:50:41Z")

</div>

> [@Bill.Thomson](#):
>
> Have you tried swapping the data Rx and TX lines?

I haven’t, because emonhub receives the data from the emonTx just fine with the wires as they are…

> [@borpin](#):
>
> Obvious question, but you have connected the rst pin to that pin on the Pi?

Yes! 😉 I also tried it with GPIO7(BCM 4) before modifying the script and results were the same…

> [@EmonTX to Rpi - Direct Serial Connection](https://community.openenergymonitor.org/t/emontx-to-rpi-direct-serial-connection/13114/48):
>
> > [@EmonTX to Rpi - Direct Serial Connection](https://community.openenergymonitor.org/t/emontx-to-rpi-direct-serial-connection/13114/48):
> >
> > You need to edit the file `/opt/openenergymonitor/avrdude-rpi/autoreset` and change the pin number to 12.
> 
> I edited a different file when I did it.

So the setup on my SD card is slightly different to that described in the docs, despite following the exact same instructions (and it was already installed as-is anyway when I received the prewritten SD card from the shop - running the script, or doing it manually changed nothing).

I might be misunderstanding how symlinks work so bear with me…

The instructions in the README.md file (in the /opt/openenergymonitor/avrdude-rpi/ folder and on github and elsewhere) imply to me that you should end up with a file named “avrdude-autoreset” in /usr/bin/ and that there should be a symlink to this file in the same folder named “avrdude”, with the actual original avrdude renamed “avrdude-original”.

Running the script doesn’t leave me with a “avrdude-autoreset” file, only an “autoreset” file…?

Why are there two copies of these files, one in /usr/bin/ and another in /opt/openenergymonitor/??? The version in /opt/openenergymonitor/ still has GPIO7 as the reset pin so clearly this is not the version being run when I try it…

> [@borpin](#):
>
> Did you stop `emonhub` first?

> [@Sage-Energy](#):
>
> I’ve also stopped the emonhub service first and checked via cat/dev/ttyAMA0 and the emonTx is still outputting data on the serial port but nothing else appears.

---

<div class="post-metadata">

**Author:** ![borpin](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/borpin/32/193_2.png) [@borpin](https://community.openenergymonitor.org/u/borpin)\
**Post date:** [6 May 2021 09:05 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691/5 "2021-05-06T09:05:21Z")

</div>

> [@Sage-Energy](#):
>
> Why are there two copies of these files, one in /usr/bin/ and another in /opt/openenergymonitor/??? The version in /opt/openenergymonitor/ still has GPIO7 as the reset pin so clearly this is not the version being run when I try it…

Yes it is rather torturous as I remember but it was a while ago so I don’t remember the details.

I do remember seeing this sync message but I was successful writing the Hex.

```auto
pi@emon-serial:~ $ ls -la /usr/bin/avrdud*
lrwxrwxrwx 1 root root 52 May 1 2020 /usr/bin/avrdude -> /opt/openenergymonitor/avrdude-rpi/avrdude-autoreset
-rwxr-xr-x 1 root root 383576 Apr 12 2019 /usr/bin/avrdude-original

```

I just had a look to remind myself 🙂

One thing that strikes me is that this script is Python rather than Python3. I noticed on a Debian update yesterday that python2.7 was removed as part of the update.

Other than that it all looks fine.

---

<div class="post-metadata">

**Author:** ![Sage-Energy](https://community.openenergymonitor.org/letter_avatar_proxy/v4/letter/s/e99b99/32.png) [@Sage-Energy](https://community.openenergymonitor.org/u/Sage-Energy)\
**Post date:** [6 May 2021 10:59 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691/6 "2021-05-06T10:59:46Z")

</div>

> [@borpin](#):
>
> I do remember seeing this sync message but I was successful writing the Hex.

Interesting… and annoying!! How are you supposed to reliably confirm it’s worked if these errors pop up?

> [@borpin](#):
>
> ```auto
> pi@emon-serial:~ $ ls -la /usr/bin/avrdud*
> lrwxrwxrwx 1 root root 52 May 1 2020 /usr/bin/avrdude -> /opt/openenergymonitor/avrdude-rpi/avrdude-autoreset
> -rwxr-xr-x 1 root root 383576 Apr 12 2019 /usr/bin/avrdude-original
> 
> ```

Your symlink points to the other copy of avrdude-autoreset compared to mine, but otherwise that looks identical.

> [@borpin](#):
>
> One thing that strikes me is that this script is Python rather than Python3. I noticed on a Debian update yesterday that python2.7 was removed as part of the update.

Interesting point… I knew python2 had been deprecated, but hadn’t considered how that might affect this… could this be the source of the error messages? I saw a forum thread where the time.sleep(0.32) line in the reset function had been increased from (0.12) to prevent this error… if this python script isn’t working properly anymore due to moving to python3 could this make a difference?

I’m pondering out loud now, I haven’t thought this through yet…

---

<div class="post-metadata">

**Author:** ![Bill.Thomson](https://community.openenergymonitor.org/user_avatar/community.openenergymonitor.org/bill.thomson/32/1834_2.png) [@Bill.Thomson](https://community.openenergymonitor.org/u/Bill.Thomson)\
**Post date:** [6 May 2021 16:29 UTC](https://community.openenergymonitor.org/t/avrdude-not-in-sync-errors-attempting-to-update-emontx-firmware/17691/7 "2021-05-06T16:29:03Z")

</div>

> [@Sage-Energy](#):
>
> I knew python2 had been deprecated,

Not just deprecated, but EOL. e.g. Python `pip` removed support for Python 2 starting with version 21.
