How to upload a .hex to the Arduboy?

I’d consider having a go myself, but I don’t have access to a mac, so I’d be flying blind.

Plus I’d have to substitute ManagementObjectSearcher for a custom class using that interops some of OSX’s OS-specific library functions, which could get a bit hairy.

Well, not quite, but if you’re pulling values from %APPDATA%, it seems like you’re doing it the hard way. I get the following output for mine, copied directly from the log window:

/home/mwm/Downloads/x/arduino-1.8.2/hardware/tools/avr/bin/avrdude -C/home/mwm/Downloads/x/arduino-1.8.2/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/arduino_build_466848/Blink.ino.hex:i 

The Arduino bootloader is only active for a short period after a reset. You can force that by toggling one of the tty control lines, which is what the various loaders do before running avrdude.

For real arduino’s, hitting the reset button works fine. The Arduboy doesn’t have a reset button, so you have to power cycle - which also causes the USB devices to be reset, which can cause the serial port to change if the PC doesn’t shut down the old device before the new one is set up.

Personally, I power off the Arduboy, set up the command line, make sure the old serial device is gone, power on the arduboy and hit enter. That works pretty reliably for me.

That’s what the verbose output gives.

I’ve tried with both the avrdude.exe the Arduino IDE uses in AppData and the avrdude.exe that comes bundled with the Arduino IDE.
(I suspect it’s just copying that one into AppData anyway, or something obscure. The Arduino IDE seems to use AppData as scratch space.)

Actually, it does.

And I’m glad you mentioned it because it seems using the reset button with proper timing got avrdude to work. Seems doing it too much in quick succession does leave the old COM port occupied, but it’s pretty predictable. On my computer at least, the Arduboy only ever occupies one of two COM ports.

It seems that setting up the command line, resetting the arduboy and then pressing enter does the trick (assuming the COM port is right).
It works for both the version bundled with the IDE and the one living in AppData.

I suspect the process on a Mac will be much the same.

Ah, so Windows apparently expands this stuff after the invocation instead of before. But I didn’t have the verbose output to look at.

It should be searching them in order, which - if you’ve got nothing else plugged in - means you get the first one, and sometimes the second one. The Mac tends to use long messy names; both my Arduboy and Leonardo show up as /dev/tty.usbmodemFD131; if I plug them both in at the same time the second one becomes /dev/tty.usbmodemFA121. Not sure what’s going on there.

BTW, another - possibly easier, depending on how hard it is to find the arduino command - way to get the command line if you’ve got Arduino installed is to run “arduino --upload --board arduino:avr:leonardo --verbose --port” followed by the serial port and a .ino file. Unfortunately, the command line doesn’t support just uploading a .hex file.

I think the IDE is purposely feeding it an absolute path, if it was splatting the %APPDATA% environment variable into the command line I think it would show up as %APPDATA% in the verbose output (I think, %APPDATA% is not exactly something I have to deal with often). I can’t be bothered to check the IDE’s source code to find out what’s actually happening. Whichever way round it is, the result is the same.

Theoretically, but if that is the case I don’t know what happened to COM1, COM2 and COM3 because they never get used by the Arduboy and they don’t register as being in use by anything else.

Good to know. I won’t add it to the list as this thread is aimed at specifically uploading .hex files. If there’s ever a thread on performing command line magic though, that’ll be a good one to bring up.

Or anything else, for that matter. I think it’s a compatibility thing - pretty much every early PC I used had COM1 & COM2 as motherboard serial, and COM3 as a modem. I recall cursing at DOS software that assumed that the first free COM port was COM4 on systems that had more than those 3 in them. Possibly those are still reserved for specific hardware ports, so not available virtual serial ports. MS has always been careful about backwards compatibility.

Closing then opening the port specifically at 1200 baud is what triggers USB based Arduinos to jump into the bootloader and await commands (normally to do an upload). (In actual fact, the Arduino is looking for the port to be set to 1200 baud and the DTR signal to be toggled.)

So yes, you have to reset the Arduboy by doing the above before you can use avrdude to perform an upload. Otherwise you have to manually reset the Arduboy using the reset button.

DTR is not relevant for Arduboy (and Leonardo, Micro and Pro Micro). Opening and closing a com port at 1200 baud is what resets it and causes the arduino to go into bootloader mode.

The com port also changes in bootloader mode on Windows (usually one port lower then in normal mode). This is because the bootloader uses a different USB VID (Vendor ID) and PID (Product ID) combo then in normal mode. (Windows registers and reserves a com port for a newly connected USB serial device based on its VID PID combo)

1 Like

And what exactly is meant by “opening and closing” a serial port? It’s normally DTR being active or inactive that indicates a port is open or closed. That’s what the Arduino USB code looks for. See Arduino core file CDC.cpp

Not under Linux. On my Ubuntu system the port stays on /dev/ttyACM0 both before and after the reset.

Forcing reset using 1200bps open/close on port /dev/ttyACM0
PORTS {/dev/ttyACM0, /dev/ttyS0, } / {/dev/ttyS0, } => {}
PORTS {/dev/ttyS0, } / {/dev/ttyS0, } => {}
PORTS {/dev/ttyS0, } / {/dev/ttyACM0, /dev/ttyS0, } => {/dev/ttyACM0, }
Found upload port: /dev/ttyACM0
/opt/arduino-1.8.4/hardware/tools/avr/bin/avrdude -C/opt/arduino-1.8.4/hardware/tools/avr/etc /avrdude.conf -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/arduino_build_999423/MYBL_AB.ino.hex:i 

The Arduino Leonardo documentation only mentioned 1200 baud. I checked the CDC.cpp like you said and read

			// We check DTR state to determine if host port is open (bit 0 of lineState).
			if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)

Thanks for pointing that out.

Nice that on linux the same com port is used. I’m using a bunch of serial devices besides Arduinos on my Windows PC and com port number go up to COM28 atm. It’s insane!

With the same com port assigned in bootloader and normal mode you could basically make a simple batch file looping executing avrdude until it’s exit code is 0

There are some python scripts around that do this. I believe I saw one on the STM32DUINO site.

Seems legit, but I’ve never seen it documented anywhere.

This is 100% correct.
You can in fact check which ports they’re assigned to using Device Manager. You need to ‘Show Hidden Devices’ though.

I’ve actually started making a simple set of batch files to make uploading .hex files via avrdude easier. It’s fiddly because of batch’s weird quote mark rules, but I’ve got a basic version working where the command is reduced to UploadHex.bat COM5 file.hex (after running Setup.bat and telling it where avrdude.exe is and making sure avrdude.exe can find avrdude.conf).

It’d probably be easier in powershell, but I’m guessing most people don’t have that in their %PATH%, and I can always do that later.

Nice idea. I didn’t think of using batch files. Since I have pyton and pySerial installed I went straight for that and wrote an uploader script

When the Arduino IDE is installed , you could use the following lines to get the locatiions of avrdude and it’s config file

for /f "tokens=2*" %%A in ('REG QUERY HKLM\SOFTWARE\Arduino /v Install_Dir') do (
set AVRDUDE="%%B\hardware\tools\avr\bin\avrdude.exe"
set CONFIG="%%B\hardware\tools\avr/etc/avrdude.conf"
)
1 Like

I’m pretty sure I have one or two versions of Python somewhere either fully or partly installed (I tend not to get on very well with things that use makefiles). I could have done a version using Lua, but I opted for batch because all versions of Windows prior to 10 use batch for scripting by default so if anyone wants to use it they don’t have to worry about installing anything.

Only if it was installed by the installer though.
I used the zipped copy purposely to avoid registry changes.

I could make the script attempt to look for the key before asking though. I’ll put that on my todo list, but I probably won’t rush to do it yet, I have other more urgent projects.

Note that the avr8 burn-o-mat package is broken in new versions of Ubuntu, and even after force installing it requires me to downgrade to openjdk-8 (my system is running openjdk-9) which I won’t do.

avrdude is quite hard to use, so afaik there is really no easy way to get .hex files onto the Arduboy from Linux. Uploading sketch files from the Arduboy IDE is the easiest way to go.

1 Like

ProjectABE does this easily on Linux. Since it’s a beta, just make sure your lock bits are set properly before trying it.

1 Like

Yep - it happened. I got my Kickstarter Ardventure download, but I have no way of uploading it from my Mac. After all of this, does anyone have a clear set of steps to follow to upload a .hex file to the Arduboy from a Mac?

1 Like

I’m pretty sure avrgirl-arduino by @noopkat could be used on macOS, right, guys?

Are you saying ProjectABE can somehow be used to upload a .hex to an Arduboy on Linux?

The off line version, yes. Just press U to upload.

1 Like