Struggling to upload .hex files on Linux

Hi, I’m wondering if anyone can give me a pointer on how to do this. I’ve been happy flashing sketch files, but I’ve been thinking about making a utility for Linux users to flash .hex or .arduboy files so I need to get past this step.

Flashing with the Arduino IDE gives me this output:

/opt/arduino-1.8.5/hardware/tools/avr/bin/avrdude -C/opt/arduino-1.8.5/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM1 -b57600 -D -Uflash:w:/tmp/arduino_build_421023/MYBL_AB.ino.hex:i

This succeeds, when run in the Arduino IDE. My game is successfully flashed.

Running the same command in my terminal, replacing the .hex file with a new location, avrdude lags and refuses to proceed:

Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding

avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = ""; type = 
    Software Version = .; Hardware Version = t.�
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader

I have seen people suggest clicking the reset button, but I haven’t been able to make that work. Also, surely there’s a way to make this work with software if the Arduino IDE can do it.

I also tried using @Mr.Blinky’s Python uploader script, which freezes on line 92. Apparently it is freezing while we “wait for Arduboy to disconnect and reconnect in bootloader mode”.

I don’t fully know what this means. Is bootloader mode required to flash images, and how can I successfully trigger it?

Thanks!

EDIT: My Linux user is in the dialout group, which is why the Arduino IDE works when run as my user. I’m using the same user in the terminal so in theory my permissions are the same. Using sudo also doesn’t affect the result.

Afaik @FManga has ProjectABE uploading on Linux now.

1 Like

Flashing is done in two steps, that command is the second.

  • First you have to reset the arduboy (and power cycling is not the same as resetting).
  • Before the sketch runs, you can connect to the bootloader with avrdude.

The problem is that the timing is critical and it varies. Getting it right manually is tricky. And sometimes it takes a bit longer to reboot and become available again.

2 Likes

Thanks, this makes sense. I’m guessing the Arduino IDE performs the reset in software, which I’m curious how to do.

MrBinky’s Python script supposedly does this, though for some reason it’s not working for me:

I’m getting stuck on line 92

It may hang if your PC disconnects and reconnects very fast. Try inserting this between line 92 and 93:

    if bootloader:
        break

If it still hangs then does your Arduboy enter bootloader mode at all when you run it ?

2 Likes

To reset a USB connected Arduino, like the Arduboy, into bootloader mode, you have to open the serial port at 1200 baud, then close it and keep it closed for a short time (at least 130ms). Opening and closing the port specifically means making DTR active then inactive.

In Linux, you can do this from a terminal command line using:
stty 1200 < /dev/(portName)
E.g.
stty 1200 < /dev/ttyACM0

After resetting, you should switch to a different baud rate to actually talk to the bootloader.

2 Likes

Just wanted to update that your fix worked. I also had to edit the path to avrdude in the script, but nevertheless I can upload .hex files directly to the Arduboy with that script now. Thanks!

I’d be really interested in making a pip installable package that people can install with a single command then upload .hex files to their Arduboy with zero configuration. Some issues with the current approach are:

  1. avrdude is required, so people would have to install that in addition to the Python package. Not a deal breaker, but potentially error-prone and it wouldn’t inspire my confidence going into it as a new user.

  2. A configuration file for avrdude has to be created before this script can run. If users don’t install the Arduino IDE first and use the generated config, the user feels like they need a phd in electrical engineering just to upload a game.

Node has a package called avrgirl-arduino which can completely replace avrdude and run from the context of another script. I noticed that most all-in-one solutions for the Arduboy use this package (eg ProjectABE). So, we might need to use an npm installable cli tool instead of a pip installable one, to my dismay.

I couldn’t get ProjectABE to actually flash roms to my device, by the way. It resets my Arduboy and looks like it’s gonna work but doesn’t finish.

Thank you for clarifying this! Exactly the answer I was hoping for.

ProjectABE doesn’t use avrgirl anymore. The class is still there, but it isn’t used as it doesn’t work most of the time. Are you sure you were using the latest version? I’ve been using it on Linux to flash roms daily, without issue.

Good to hear it worked. I’ll update mine.

Yeah that’s currently still required. I’ll need to work on adding some python flasher code to get rid of that dependency.

1 Like

I was on the master branch last week when I tried. I’ll try again.

What does it use to flash the roms, if not avrgirl-arduino?

Ah, you made your own build. Was it nwjs or did you use electron? The electron build is deprecated and was based on avrgirl. The nwjs build has its own flasher.

1 Like