Uploading Via arduino-cli?

Hey everyone,

I’ve been trying to figure out how to make use of the arduino command line interface on my MacBook pro, but to be frank, I don’t entirely know what I’m doing. I’ve almost figured out the command to use to upload a sketch onto a Blink, but I’m a little stuck with this error:

arduino-cli upload -b Move38-Blinks-Library:avr:blink -programmer
Error during Upload: compiled sketch /Users/JonathanWest/Projects/Causeway/Causeway.Move38-Blinks-Library.avr.blink.hex not found

This seems to me that it’s trying to point to a hex file that I assume lives somewhere other than the project directory, but I’m unsure how to change that.

I was also under the assumption that I just hadn’t properly added the Blinks core package, so I attempted that with this command from the “getting started” guide:

arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/Move38/Blinks-SDK/master/package_move38.com-blinks_index.json

But I was met with this error:

Updating index: package_index.json downloaded
Updating index: package_move38.com-blinks_index.json downloaded
Error updating index: invalid package index in https://raw.githubusercontent.com/Move38/Blinks-SDK/master/package_move38.com-blinks_index.json: invalid character ']' looking for beginning of value

Has anyone done this before who could show me what I’m doing wrong or walk me through this process? It isn’t a huge deal for me to get this working, but as I’m mostly using Vim for code editing and I’m only using the Arduino software for it’s “upload” button, I thought this might be nicer to set up.

Thanks for the help!

Enabling debug output in Aruino IDE and seeing what happens when it compiles a program might help you. For example, here is the final command line:

/home/bga/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/bga/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -B 5 -v -patmega168pb -cusbtiny -Uflash:w:/tmp/arduino_build_667796/empty.ino.hex:i -Uflash:w:/home/bga/.arduino15/packages/blinklib/hardware/avr/1.0.0-beta.2/bootloaders/BlinkBIOS.hex:i -u

So it is very likelly you want to point to BlinkBIOS.hex instead of the path that is being used. There might be an option to set it.

1 Like

Thanks for that suggestion. Looking a bit more closely at the documentation for the arduino-cli’s configuration file, it looks like there are options to set specific directories for data. I might play around with that and see what I can come up with.

I’m not sure about the other stuff, but I think at least this error was my fault - you happened to hit the boards manager config file while I was corrupting updating it. Sorry.

That file should be good now. If the other issues persist then the debug output from the bottom window would be helpful as @BGA mentioned above.

1 Like

@bigjosh Thanks for looking at this, unfortunately though I still seem to be getting that error:

arduino-cli core update-index --additional-urls https://raw.githubusercontent.com/Move38/Blinks-SDK/master/package_move38.com-blinks_index.json
Updating index: package_index.json downloaded
Updating index: package_move38.com-blinks_index.json downloaded
Error updating index: invalid package index in https://raw.githubusercontent.com/Move38/Blinks-SDK/master/package_move38.com-blinks_index.json: invalid character ']' looking for beginning of value

Is there maybe another URL I should be using instead? I did get a step closer yesterday by updating the “data directory” in my config to point to the location where I installed the Blinks SDK originally, which is where the BlinkBIOS.hex file was being stored, but I was met with a rather vague error when uploading:

arduino-cli upload -b Move38-Blinks-Library:avr:blink -programmer
Downloading missing tool builtin:ctags@5.8-arduino11...
builtin:ctags@5.8-arduino11 already downloaded
Installing builtin:ctags@5.8-arduino11...
builtin:ctags@5.8-arduino11 installed
Downloading missing tool builtin:serial-discovery@1.0.0...
builtin:serial-discovery@1.0.0 already downloaded
Installing builtin:serial-discovery@1.0.0...
builtin:serial-discovery@1.0.0 installed
Updating index: library_index.json downloaded
Error during Upload: There were errors loading platform indexes

Running that command yesterday with the verbose flag yielded the same error. Another step I tried was running arduino core update-index, which seemed to be successful, as this was part of the output:

INFO[0003] Loading package Move38-Blinks-Library from: /Users/JonathanWest/Documents/Arduino/hardware/Move38-Blinks-Library
INFO[0003] Loaded platform                               platform="Move38-Blinks-Library:avr@"
INFO[0003] Loading package packages from: /Users/JonathanWest/Documents/Arduino/hardware/packages
INFO[0003] Loading package tmp from: /Users/JonathanWest/Documents/Arduino/hardware/tmp
INFO[0003] Adding libraries dir                          dir=/Users/JonathanWest/Documents/Arduino/libraries location=user
INFO[0003] current best: Move38-Blinks-Library:avr@      bundle=false managed=false version=
INFO[0003] Adding libraries dir                          dir=/Users/JonathanWest/Documents/Arduino/hardware/Move38-Blinks-Library/avr/libraries location=platform

Now however I’m back to the issue where the program is looking for a hex file within the sketch folder - more or less square one :neutral_face:

Hmmm… not sure where that url came from, but it is not right in so many ways!

I think something is got messed up here.

Can you try uninstalling the SDK you’ve got and installing using these instructions and see if that helps?

Hmmm… not sure where that url came from, but it is not right in so many ways!

I’ll be honest I’m not entirely sure where I grabbed that url from either… Adding the link in in your instructions seems to have worked successfully though, so that error is fixed!

Now though I’m still running into the issue where the program is searching for a .hex file in the sketch directory to upload… I’m sure it’s just something I’m doing wrong with the upload command but I haven’t figured out what yet.

Maybe you need to do a compile command first to create the HEX files before doing the upload?

2 Likes

Maybe you need to do a compile command first to create the HEX files before doing the upload ?

You were right, I didn’t realize that’s what was going on with the IDE when you compiled. I had to run a few extra steps to get the compiler working properly, namely run arduino-cli core install arduino:avr to make sure the right compiler was installed, but after that the hex file was getting dropped into the project directory for upload.

I didn’t have my Blinks on hand to actually test the upload, so I’ll confirm that everything works later today or tomorrow morning, but I’m assuming that was the big fix. Thanks for your help!

EDIT: When I confirm that I get everything working I’ll make a last post summing up the steps I took to get this working for the Blinks Dev Kit, in case anyone else wants to make use of it in the future.

3 Likes

Alright, so I think I have this figured out. Naturally, I was over-complicating things when I tried to do this the first time around.

  1. Install Arduino-CLI for your OS of choice (I’m on mac, so I just used brew).
  2. Run arduino-cli config init to create a configuration file. The program should give you an output telling you where the config file was placed. It should be named arduino-cli.yaml.
  3. Edit the config file to include https://github.com/bigjosh/Move38-Arduino-Platform/releases/latest/download/package_move38.com-blinks_index.json in the “board_manager” section under “additional urls”. It should look like this:
board_manager:
  additional_urls:
    - https://github.com/bigjosh/Move38-Arduino-Platform/releases/latest/download/package_move38.com-blinks_index.json
  1. Save the changes to the config file and run arduino-cli core update-index for the changes in your config to take place.

  2. Make sure you have the proper compiler installed by running arduino-cli core install arduino:avr

All of these above steps are explained in more detail in their own docs, which you can follow in case my instructions aren’t very clear. I just thought it would be helpful to include the proper board strings and package urls for Blinks.

From here, you should be able to compile and upload the sketch using the arduino-cli program. However, make sure you are in the parent directory of your sketch folder, not in the sketch folder itself. Otherwise these commands get a little confused.

  • **Compile (Verify) Sketch: ** arduino-cli compile --fqbn Move38-Blinks-Library:avr:blink SketchName

  • **Upload: ** arduino-cli upload -b Move38-Blinks-Library:avr:blink -programmer SketchName

Note that the above commands take the name of the sketch without the ‘.ino’ extension. Arduino-CLI is assuming that the name of the sketch is within a folder that matches the name of the sketch file. The IDE also behaves this way, but the CLI program is a little less obvious about it.

Hopefully this helps, if there’s anything I missed let me know. This will probably be the way I handle my workflow on my macbook from here on out!

4 Likes

Hey, I’m trying to get command line tools working, and successfully followed most of the steps here. I had to change Move38-Blinks-Library to move38 (retrieved from board listall), because my board is not showing up in the board list. This allowed me to successfully compile from the command line, but when I try to upload, I get:

Error during Upload: uploading error: cannot execute upload tool: exec: “echo ERROR_TELL_JOSH_UPLOAD_WAS_CALLED”: executable file not found in $PATH

so, HEY JOSH, UPLOAD WAS CALLED

This is code that I have been able to compile and upload to blinks in the Arduino IDE. Any hints?

You are not supposed to be able to do an “UPLOAD” because there is no such thing as an upload for this board, but apparently the CLI let’s you try to do it anyway. :slight_smile:

In Arduino-speak, UPLOAD means “send to bootloader over serial connection”. What we want to do to program a blink is called “Upload Via Programmer” by the IDE.

I do not see any way to explicitly do that with the CLI, so it looks like we will need to explicitly specify the programmer like this…

arduino-cli.exe upload --fqbn move38:avr:blink --programmer usbtinyisp

if you are using the usbtiny programmer (red rectangle), or…

arduino-cli.exe upload --fqbn move38:avr:blink --programmer usbasp

if you are using the usbasp programmer (plugs directly into the USB port).

Note that the “–programmer list” option does not seem to work as documented

>arduino-cli.exe upload --fqbn move38:avr:blink --programmer list
Error during Upload: programmer 'list' not available

…so I got the names of the programmers directly from the programmers.txt file in case you are trying to use a different programmer.

thanks perfect, this worked a treat