arduino-cli icon indicating copy to clipboard operation
arduino-cli copied to clipboard

using a stable /dev --port name on Linux

Open atannen opened this issue 8 months ago • 4 comments
trafficstars

Describe the request

I use arduino-cli on Intel Linux to compile and upload sketches to my Arduino, which is an Adafruit Feather M4 CAN. Usually, the feather comes up as /dev/ttyACM0. Sometimes it's /dev/ttyACM1.

My request is that I would like to deal with the port device name in a clear stable way.

I had been resolving this problem by putting this code in my arduino-cli bash wrapper script:

PORT=$(echo /dev/ttyACM?) arduino-cli upload --port $PORT etc.

That has worked reliably for me. But I wanted to try making a udev rule for a /dev/feather_m4_can with a symlink, so I could just say:

PORT=/dev/feather_m4_can arduino-cli upload --port $PORT etc.

without ambiguity, in my scripts. I have not been able to make this work reliably.

I know that when I run arduino-cli upload, the udev system does several bind/unbind and add/remove operations on the usb device, and its ID wiggles between a normal 239a:80cd and a bootloader 239a:00cd.

When I run lsusb (in a loop) during an arduino-cli upload, it shows this:

Bus 001 Device 026: ID 239a:80cd Adafruit Feather M4 CAN Bus 001 Device 027: ID 239a:00cd Adafruit Feather M4 CAN Express Bus 001 Device 028: ID 239a:80cd Adafruit Feather M4 CAN

I wrote a new local udev rule /etc/udev/rules.d/99-myfeatherm4.rules that looks like this:

SUBSYSTEM=="tty", ATTRS{idVendor}=="239a", ATTRS{idProduct}=="80cd", SYMLINK+="feather_m4_can" SUBSYSTEM=="tty", ATTRS{idVendor}=="239a", ATTRS{idProduct}=="00cd", SYMLINK+="feather_m4_can"

It makes a good-looking symlnk, but arduino-cli doesn't work with it.

$ ls -l /dev/ttyA* /dev/feather* lrwxrwxrwx 1 root root 7 Feb 24 13:28 /dev/feather_m4_can -> ttyACM0 crw-rw---- 1 root dialout 166, 0 Feb 24 13:28 /dev/ttyACM0

$ ~/bin/arduino-cli_1.2.0 upload --port /dev/feather_m4_can --fqbn adafruit:samd:adafruit_feather_m4_can mysketch.ino --input-dir /home/me/lib/ardbin/mysketchdir No device found on feather_m4_can Failed uploading: uploading error: exit status 1

I know I can use: PORT=$(echo /dev/ttyACM?)

or even PORT=$(readlink -f /dev/feather_m4_can)

but I'd like to just use: PORT=/dev/feather_m4_can

if possible.

Is my problem with my udev rule? Or is it a problem with the way arduino-cli is treating the symlink? (why does it work with /dev/ttyACM0 but not with the symlink?) Is there a best simple way to specify the port?

Describe the current behavior

When I use my udev rule device name with a symlink to my feather, it fails. (I keep my bin/arduino-cli versions with version number in the name, then I symlink bin/arduino-cli to the version I want)

$ ~/bin/arduino-cli_1.2.0 upload --port /dev/feather_m4_can --fqbn adafruit:samd:adafruit_feather_m4_can mysketch.ino --input-dir /home/me/lib/ardbin/mysketchdir No device found on feather_m4_can Failed uploading: uploading error: exit status 1

Arduino CLI version

latest 1.2.0, also earlier versions

Operating system

Linux

Operating system version

6.8.0-53-generic ubuntu

Additional context

No response

Issue checklist

  • [x] I searched for previous requests in the issue tracker
  • [x] I verified the feature was still missing when using the nightly build
  • [x] My request contains all necessary details

atannen avatar Feb 24 '25 19:02 atannen