Easiest way to configure arduino-cli for UNO and NANO

I swallow back these words.

I must now learn how to parse the JSON data. I believe it isn't that hard

It was hard. There is a json array in a json array and I did not know you could do method chaining. Thankfully I have a coworker who is more at home in json than me. He learned some java from me today :joy:

But I can succesfully fetch the fqbn and corrsponding com port from the connected arduino.

This makes me wonder something.. If I can fetch the fqbn string and com port, than why do we al need enter an fqbn and comport number in me build and upload files?

Provided that this work with bare atmegas and ch340 chips, I could make better pyhton build + upload scripts.

Regards,

Bas

Nice!

Unfortunately, no. The board identification is only possible when the board produces a port that has unique properties. In the case of the serial ports, the properties used are the USB VID/PID pair. Arduino purchased a vendor ID from USB-IF, which makes it possible for Arduino to program the USB chip on the UNO and other Arduino boards to produce a port with a unique VID/PID pair dedicated exclusively to the UNO board model. Other boards manufacturers also own their own VID, so this identifiable characteristic is not exclusive to official Arduino boards.

The CH340 uses the VID/PID pair provided by the manufacturer of the chip WCH. This is very convenient for people making their own boards because they aren't forced to spend thousands of dollars to purchase their own VID from USB-IF, but it also means that every device with a CH340 chip has the same VID/PID pair. Arduino CLI has no way of knowing which board is on the other side of that chip, or even if it is an Arduino board at all rather than some random consumer device that uses the chip.

The same situation occurs with boards that use any of the other general purpose USB to serial chips (e.g., FTDI FT232R, Silicon Labs CP2102). In fact, even the official Arduino Nano (which uses an FT232R chip) is not identifiable.

So you can use the information from arduino-cli board list to enhance the port selection experience for the user (similar to how the Tools > Port menu works in Arduino IDE, or the board selector on the Arduino IDE 2.x toolbar), but there probably isn't any way to completely automate the process in a way that will work perfectly 100% of the time with any board and the environment of the computer of any user.

Thou wisdom knows no limits :wink:

How unfortunate news :smiling_face_with_tear: though I suspected as much. I vaguely remembered that those usb-ttl chips used by arduino were programmable. iirc you could even let an arduino uno take control of your mouse and issue keystrokes like a leonardo can by hacking that firmware.

I just got my scripts my processing function working. I can detect that there is a board present, what board it is and ofcourse which com port is assigned.

I also vaguely remember that a ch340 chip registers as "unknown" when you ask arduino-cli. Call it dirty but I think it is almost safe to assume it is either an uno or a nano with an exceptional mega. Anyways it would tell me atleast which com port I should use. And if that fails too, I must code some kind of number entry box...

I am atleast happy I finally have control over this in Processing opposed to the batch file, so it's a win regardless.

Concerning the fqbn string. I was thinking to do trial and error. Since 80% of people 'propably' uses an uno and the remainder 'propably' a nano. But I recall that flashing an uno program in a nano (or vice versa) can take a lot of time before avrdude gives up and tosses an error.

I therefor think I am best off by adding a clickable thingy in the application. So you can choose between a few boards.

Or even worse... add a "config.ini" file :confounded: (than again, I could use it to let users set their own prefered colours in the UI :thinking: )

Imma gonna need some time to think things through.
Brainfarts over a 'serial monitor' and simulation mode are already coming to me

Kind regards :tumbler_glass:

Bas

1 Like

Hi, me again.

I am still having a problem with the exported folder. I am using coworkers' PCs during breaks to test the folder.

The program does succesfully find com-ports. And the the upload program buttons works well on my own PC.

But on the other computer, it just won't work. I believe the problem lies in my install batch file.

I am currently trying out this batch file to initialize arduino-cli

echo off

set ARDUINO_DIRECTORIES_DATA=%~dp0\Arduino-cli\configFiles
set ARDUINO_DIRECTORIES_USER=%~dp0\Arduino-cli\configFiles

Arduino-CLI\arduino-cli config init --overwrite
Arduino-CLI\arduino-cli core update-index
Arduino-CLI\arduino-cli core install arduino:avr
Arduino-CLI\arduino-cli lib install servo
pause

Had to make a picture of the dump unfortunately/

That path behind the 'config file written' line is correct.

platform arduino:avr@1.8.6. already installed.

It claims that the core is already installed (I ran the file more than once)
and dito for the servo library.

Yet when my application "FunctionBloX" tries to build I get this feedback:

Platform 'arduino-avr' not found.

What I suspect is that the the 2 SET lines of my batch files aren't working.

I forgot to examin the configFiles folder to see that the batch script did and did not add. I'll try to that this week.

My program on my PC executes this line.. with succes

buildCommand: C:\Users\sknippels\Documents\hobbyProjects\functionBloX\Arduino-cli\arduino-cli.exe compile -b arduino:avr:uno -v C:\Users\sknippels\Documents\hobbyProjects\functionBloX\arduinoProgram

My exported folder, does contain the needed avr core and servo library. I think in the batch I should not even need to run these lines:

Arduino-CLI\arduino-cli core install arduino:avr
Arduino-CLI\arduino-cli lib install servo

Can you or anybody else perhaps spot the mistake I'm making?

Kind regards :coffee:

Bas

These will only set the environment variable within the scope of the batch file. If you later use Arduino CLI from a different scope then that environment variable won't be set. This is a problem because the arduino-cli config init command wrote the configuration file to the data directory so if the ARDUINO_DIRECTORIES_DATA environment variable isn't set the Arduino CLI won't use the configuration file and will instead use the default configuration and thus the default data directory location. The arduino-cli core install arduino:avr command installs the arduino:avr platform to the data directory, so this is why Arduino CLI doesn't recognize that installation anymore.

Ok, clear. Thanks.

So the easy fix would be to let the application run 1 or 2 batch files for building/uploading so I can add the SET lines there as well?

I think I will also try to add the set lines in the processing application.

Regards :coffee:

Bas

I added these 2 strings named SET1 and SET2 to the final strings I will launch. I added semicolons to separate the commands but it does not work unfortunately.

    String SET1 = "set ARDUINO_DIRECTORIES_DATA=%~dp0\\Arduino-cli\\configFiles;" ;
    String SET2 = "set ARDUINO_DIRECTORIES_USER=%~dp0\\Arduino-cli\\configFiles;" ;
    boolean status = false ;

    // String arduinoCliPath = "C:\\Users\\Gebruiker\\Documents\\arduino-cli14\\arduino-cli.exe " ;
    String arduinoCliPath = myPath + "\\Arduino-cli\\arduino-cli.exe " ;
    String sketchPath     = myPath + "\\arduinoProgram" ;

    BufferedReader in ;

    if( selectedBoard == 255 ) { setMessage(1,"no board selected"); return ; }

    CheckBox box = checkBoxes.get(selectedBoard) ; // get FQBN from selected board..
    fqbn = "arduino:avr:" + box.getName() ;
    
    String buildCommand   = "compile -b " + fqbn + " -v " + sketchPath ;
    String uploadCommand  = "upload -v " + sketchPath + " -b " + fqbn + " -v -p "+ COM_PORT ;

    //println("buildCommand:  ",buildCommand) ;
    //println("uploadCommand: ",uploadCommand) ;
    try
    {      
        command = SET1 + SET2 + arduinoCliPath + buildCommand ; // compile (can't toss errors really..)
        println("buildCommand:  ",command) ;
        Process p = launch(command);

Output:

buildCommand: set ARDUINO_DIRECTORIES_DATA=%~dp0\Arduino-cli\configFiles;set ARDUINO_DIRECTORIES_USER=%~dp0\Arduino-cli\configFiles;C:\Users\sknippels\Documents\hobbyProjects\functionBloX\Arduino-cli\arduino-cli.exe compile -b arduino:avr:uno -v C:\Users\sknippels\Documents\hobbyProjects\functionBloX\arduinoProgram

uploadCommand:
set ARDUINO_DIRECTORIES_DATA=%~dp0\Arduino-cli\configFiles;set ARDUINO_DIRECTORIES_USER=%~dp0\Arduino-cli\configFiles;C:\Users\sknippels\Documents\hobbyProjects\functionBloX\Arduino-cli\arduino-cli.exe upload -v C:\Users\sknippels\Documents\hobbyProjects\functionBloX\arduinoProgram -b arduino:avr:uno -v -p COM4

:frowning:

I decided to get rid of the SET instructions in the installation script. So I don't have to modify the other scripts. This does mean that all settings and all are installed.. elsewhere. And because windows complains about security and persissions, the install batch scripts raises like 8 pop-ups in which you need to hit 'yes'.

But... it does.. actually work now. With my Zip file on a USB stick (and internet connection for the install script) I had everything I need to program and flash the arduino board. This turns my program into a fully functional IDE with function 'upload program' button. Even with automatic COM port detection.

I have a dedicated webpage in Dutch and I am yet to translate this to English.

Kind regards,

Bas

1 Like

Very cool! Thanks for taking the time to post an update and share your project.

Regards,
Per

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.