A-Star & adding serial numbers

with 2 a-stars i am unable to distingush between them, so i only see one of them.
normally i use the serial number to do this; with multiple uno’s it’s 3 udev rules.
system is debian jessie on a i5 laptop.
.
one bad way as they’re only for me would be to play with the usb vendor / product id’s :frowning:
these appear in the boot loader.
.
so how would one add a serial number to an a-star?
.
stephen

Hello, Stephen.

The ATmega32U4 has a set of 32 read-only signature bytes and 10 of those bytes actually contain a serial number, though it isn’t documented in the datasheet. If you want to see the serial number on your A-Star (or an Arduino Leonardo or any other board with an ATmega32U4), you can run this sketch:

#include <avr/boot.h>

char serialNumber[30];

char nibbleToHex(uint8_t n)
{
  if (n <= 9) { return '0' + n; }
  else { return 'a' + (n - 10); }
}

void readSerialNumber()
{
  char * p = serialNumber;
  for(uint8_t i = 14; i < 24; i++)
  {
    uint8_t b = boot_signature_byte_get(i);
    *p++ = nibbleToHex(b >> 4);
    *p++ = nibbleToHex(b & 0xF);
    *p++ = '-';
  }
  *--p = 0;
}

void setup()
{
  readSerialNumber();
}

void loop()
{
  Serial.println(serialNumber); 
  delay(1000);
}

By the way, this code also works on the ATmega328PB, and the serial number for that AVR is documented in its datasheet.

It would probably be sufficient for you to just make the sketch report this serial number to the computer as a standard USB serial number, without modifying the bootloader. That would allow you to assign different serial port names to each board when it is running the sketch, using udev rules (for Linux) or by changing the COM port in the Device Manager (for Windows).

The USB code that gets loaded in your Arduino sketches is stored in the Arduino IDE and you can modify its source code to add support for the serial number. Here is a patch showing the changes you could make to the Arduino IDE verison 1.5.8 to enable serial number support:

arduino_1.5.8_serial_number.patch (2.05 KB)
I also posted it here: gist.github.com/DavidEGrayson/b … f62ffb6989

You can either read this patch file and make the specified modifications by hand, or just go into the Arduino 1.5.8 installation directory and run:

patch -p0 < arduino_1.5.8_serial_number.patch

–David

Edit: For an updated patch that works with Arduino 1.6.12, see this thread: A-Star USB Serial number

i’m trying to do this at astar connection, not from within a sketch.
when i plug them both in, they are distingushed by the bus/device they
appear as, but i only get a single device.
the serial number needs to be in the usb packet sent from the device in the
handshake resulting from the ‘insertion’.
.
as i said i normally use a udev rule to distingush between each uno etc…
so i normally see in /dev something like:-

/dev/Uno1 --> /dev/ttyACM0
/dev/ttyACM0
/dev/Uno2 --> /dev/ttyACM1
/dev/ttyACM1
.
snippet from /etc/udev/rules.d/25-Arduino.rules, ignore wrapping
SUBSYSTEMS==“usb”, ATTRS{idVendor}==“2341”, ATTR{serial}==“64938333932351506212”, MODE=“666”, GROUP=“dialout”,SYMLINK+="Uno1"
SUBSYSTEMS==“usb”, ATTRS{idVendor}==“2341”, ATTR{serial}==“74937303936351E07031”, MODE=“666”, GROUP=“dialout”, SYMLINK+="Uno2"
SUBSYSTEMS==“usb”, ATTRS{idVendor}==“2341”, ATTR{serial}==“553303336303518150C0”, MODE=“666”, GROUP=“dialout”, SYMLINK+=“Uno3”

where/what do i change to add the ATTR{serial}, i did look in the Project directories with a grep.
got the feeling it’s not trivial.
.
i’m still using /dev/ttyACMn in the port selection drop down.
unplugging one & then plugging it in again gives it incrementing port
number syndrome, which is a pain.
must be a way in udev rules to cater for that. :slight_smile:
.
stephen

When you plug the A-Star 32U4 into USB, it is usually running a sketch instead of the bootloader. It would only be running the bootloader if the sketch had been erased, and there is no option to do that in the Arduino IDE so it is not a common state. Therefore, if you follow my instructions above to modify the sketch to have a serial number, it should allow you to distinguish different A-Stars using udev rules like the ones you posted.

What do you mean by “they are distingushed by the bus/device they appear as, but i only get a single device”? Each A-Star really should get its own /dev/ttyACMn device when you plug it in, regardless of whether it has a serial number or not, and regardless of whether it is running the bootloader or the sketch. What happens when you plug in two A-Stars and run ls /dev/ttyACM* in a shell? What messages about the A-Stars do you see in the output of dmesg?

–David

apols i do see ttyACM0 & ttyACM1; and i also see mouse event inputs.
my udev rules have to be wrong.

my astar-rules is from yours:

# Linux users can copy this file into /etc/udev/rules.d/ to prevent
# ModemManager from taking over the virtual serial port of the A-Star
# 32U4.

SUBSYSTEM=="usb", ATTRS{idVendor}=="1ffb", ATTRS{idProduct}=="0101", ENV{ID_MM_DEVICE_IGNORE}="1"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1ffb", ATTRS{idProduct}=="2300", ENV{ID_MM_DEVICE_IGNORE}="1"

SUBSYSTEMS=="usb", ATTRS{idVendor}=="1ffb", ATTRS{idProduct}=="2300", \
 MODE="666", GROUP="dialout", SYMLINK+="A_STAR"

i think i’m expecting to see /dev/A_STAR0 /dev/A_STAR1 etc
also looked at /lib/udev/rules.d/77-mm-usb-device-blacklist.rules

lsusb with both

Bus 002 Device 005: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)
Bus 002 Device 004: ID 1bcf:000b Sunplus Innovation Technology Inc. 
Bus 002 Device 016: ID 1ffb:2300  
Bus 002 Device 009: ID 1ffb:2300  
Bus 002 Device 003: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub

and for one, then both

ls -lt /dev|head -n 20
total 0
crw-rw-rw-  1 root tty         5,   2 Dec 10  2014 ptmx
lrwxrwxrwx  1 root root            12 Dec 10 23:11 A_STAR -> input/mouse2
drwxr-xr-x  2 root root          3480 Dec 10 23:11 char
drwxr-xr-x  4 root root           500 Dec 10 23:11 input
crw-rw-rw-  1 root dialout   251,   2 Dec 10 23:11 hidraw2
crw-rw-rw-  1 root dialout   166,   0 Dec 10 23:11 ttyACM0
drwxr-xr-x  4 root root            80 Dec 10 23:11 serial
drwxrwxrwt  2 root root           120 Dec 10 23:09 shm
crw-rw----  1 root tty         7,   7 Dec 10 23:08 vcs7
crw-rw----  1 root tty         7, 135 Dec 10 23:08 vcsa7
crw--w----  1 root tty         4,   1 Dec 10 23:08 tty1
prw-r-----  1 root adm              0 Dec 10 23:08 xconsole
crw-------  1 root root       10,  55 Dec 10 23:08 vboxnetctl
crw-------  1 root root       10,  57 Dec 10 23:08 vboxdrv
crw-rw-rw-  1 root root       10,  56 Dec 10 23:08 vboxdrvu
brw-rw----  1 root disk        8,   3 Dec 10 23:07 sda3
brw-rw----  1 root disk        8,   4 Dec 10 23:07 sda4
drwxr-xr-x  3 root root           220 Dec 10 23:07 snd
drwxr-xr-x  4 root root            80 Dec 10 23:07 v4l
e]0;stephen@i5: ~astephen@i5:~$ ls -lt /dev|head -n 20
total 0
lrwxrwxrwx  1 root root            13 Dec 10 23:11 A_STAR -> input/event17
drwxr-xr-x  2 root root          3580 Dec 10 23:11 char
crw-rw-rw-  1 root dialout   251,   3 Dec 10 23:11 hidraw3
crw-rw-rw-  1 root dialout   166,   1 Dec 10 23:11 ttyACM1
drwxr-xr-x  4 root root           540 Dec 10 23:11 input
crw-rw-rw-  1 root tty         5,   2 Dec 10 23:11 ptmx
crw-rw-rw-  1 root dialout   251,   2 Dec 10 23:11 hidraw2
crw-rw-rw-  1 root dialout   166,   0 Dec 10 23:11 ttyACM0
drwxr-xr-x  4 root root            80 Dec 10 23:11 serial
drwxrwxrwt  2 root root           120 Dec 10 23:09 shm
crw-rw----  1 root tty         7,   7 Dec 10 23:08 vcs7
crw-rw----  1 root tty         7, 135 Dec 10 23:08 vcsa7
crw--w----  1 root tty         4,   1 Dec 10 23:08 tty1
prw-r-----  1 root adm              0 Dec 10 23:08 xconsole

this is the only line that differs between captured separate outputs of lsusb -v -v -d 1ffb:2300

Bus 002 Device 045: ID 1ffb:2300
Bus 002 Device 106: ID 1ffb:2300

dmesg after plugging both in again

[ 1039.184673] usb 2-1.1.2: new full-speed USB device number 114 using ehci-pci
[ 1039.280379] usb 2-1.1.2: New USB device found, idVendor=1ffb, idProduct=2300
[ 1039.280386] usb 2-1.1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1039.280390] usb 2-1.1.2: Product: USB IO Board    
[ 1039.280394] usb 2-1.1.2: Manufacturer: Unknown    
[ 1039.280785] cdc_acm 2-1.1.2:1.0: This device cannot do calls on its own. It is not a modem.
[ 1039.280812] cdc_acm 2-1.1.2:1.0: ttyACM0: USB ACM device
[ 1039.283288] input: Unknown     USB IO Board     as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1.2/2-1.1.2:1.2/0003:1FFB:2300.0013/input/input33
[ 1039.283629] hid-generic 0003:1FFB:2300.0013: input,hidraw2: USB HID v1.01 Mouse [Unknown     USB IO Board    ] on usb-0000:00:1d.0-1.1.2/input2
[ 1052.926000] usb 2-1.1.3: new full-speed USB device number 115 using ehci-pci
[ 1053.021725] usb 2-1.1.3: New USB device found, idVendor=1ffb, idProduct=2300
[ 1053.021731] usb 2-1.1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 1053.021735] usb 2-1.1.3: Product: USB IO Board    
[ 1053.021738] usb 2-1.1.3: Manufacturer: Unknown    
[ 1053.022148] cdc_acm 2-1.1.3:1.0: This device cannot do calls on its own. It is not a modem.
[ 1053.022182] cdc_acm 2-1.1.3:1.0: ttyACM1: USB ACM device
[ 1053.024465] input: Unknown     USB IO Board     as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.1/2-1.1.3/2-1.1.3:1.2/0003:1FFB:2300.0014/input/input34
[ 1053.024835] hid-generic 0003:1FFB:2300.0014: input,hidraw3: USB HID v1.01 Mouse [Unknown     USB IO Board    ] on usb-0000:00:1d.0-1.1.3/input2

what i would like to do is modify this output

usb 2-1.1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 2-1.1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0

to

usb 2-1.1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=123
usb 2-1.1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=456

i agree they both run a sketch after the bootloader times out, but i shouldn’t need to run a
sketch to get the 32u4’s id codes to distingush each.
my assorted serial interfaces and uno’s all have their own serial numbers.

i’d also like to know how/what i could use the USB HID interfaces they appear to have

stephen

I think the udev rule you posted just adds a symlink named A_STAR (without a number) and I don’t know how to automatically add numbers to it.

The A-Star should be running the sketch immediately after you power them on; you should not have to wait for the bootloader to time out (which takes 8 seconds). Are you sure you have to wait for the bootloader to time out? How long do you have to wait and what does lsusb say during that time?

The USB product ID for the A-Star 32U4 sketch is 0x2300 and the product ID for the bootloader is 0x0101, so your lsusb output shows that the devices are running the sketch. If you follow my instructions above to add serial number support to the sketch, then those devices will have serial numbers that you can use to distinguish them. If you added serial number support to the bootloader, the serial number wouldn’t be usable until the board is in bootloader mode.

Having serial number support in the bootloader will probably not help you much, because the Arduino IDE does not really use the name of the serial port in order to find the correct serial port for the bootloader. After telling the A-Star sketch to restart and go into bootloader mode, the IDE just waits until any new serial port appears, and then the IDE connects to that port, regardless of its name, assuming that the port will be from the bootloader.

If you want to modify the bootloader, you would need to recompile the bootloader source code and then load it on to the A-Star using an AVR programmer.

The HID interface on the A-Star 32U4 sketch can be controlled with the Arduino Mouse and Keyboard libraries.

–David