9

Reading http://playground.arduino.cc/Linux/Udev there appears to be a way to write out to a FTDI USB-Serial EEPROM to set a given SerialNumber, allowing you to identify a given nano/other arduino to handle it specifically in UDEV.

I have a nano-style boad with a QinHeng Electronics HL-340 USB-Serial adapter, which clearly isn't an FTDI chip, and the FTDI programmer therefore doesn't work. Does anyone know of an alternative utility/where I can find information to do the same with this chip?

Currently the device identifies itself with:

[ 6850.608080] usb 2-1.2: new full-speed USB device number 7 using ehci-pci
[ 6850.701496] usb 2-1.2: New USB device found, idVendor=1a86, idProduct=7523
[ 6850.701505] usb 2-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 6850.701510] usb 2-1.2: Product: USB2.0-Serial
[ 6850.702201] ch341 2-1.2:1.0: ch341-uart converter detected
[ 6850.704210] usb 2-1.2: ch341-uart converter now attached to ttyUSB0

Which is essentially useless, as I can't identify the given board attached (when I attach two, their details are the same).

  • 3
    possible duplicate of In Linux, how to identify multiple Arduinos connected over USB? – PhillyNJ Dec 21 '14 at 13:33
  • 1
    Unfortunately, this isn't really an answer to either: the question (as it doesn't answer whether there is a way to assign a new serial number as one can do for FTDI chips), or resolve the issue (as the udev serial for all these boards, like the Leonardo, is 0, therefore udev can't distinguish between multiple boards attached to the same computer. – jvc26 Dec 21 '14 at 19:25
  • My link is to my answer which talks about creating udev rules for each device. – PhillyNJ Dec 22 '14 at 12:44
  • 1
    If you can read chinese(I can't) this page might help: wch.cn/products.php?page=procontent&id=40 – Craig Dec 22 '14 at 17:52
  • 3
    Unfortunately @Phil Vallone the issue is that there is no unique serial to identify the device via udev. In order to detect and identify a unique device, you need something unique to differentiate them. These devices have the same iSerial, so you can't diff them on that, and they share the same Product and Vendor IDs - so there isn't a differentiator ... Thanks for your help, unfortunately it doesn't fix this issue! – jvc26 Dec 22 '14 at 20:02
3

There is no storage on the CH340 and family of UARTs where you could put a unique ID. This is also a problem for the PL2303 type. I have been trying to find solutions for this problem. First and easiest is the position of the device on the USB bus. It will be unique for each device. If you're using linux you can find each device under /dev/serial/by-path . There is also a /dev/serial/by-id but there will only be one entry there for this device because it shows the last one connected. FTDI chips will each have unique entries here. Cheap chips won't, but they each have an entry under /dev/serial/by-path. This position, and the device names, should persist across reboots. If you have a lot of changes to your USB devices, plug all the CH340 devices into the same hub, then plug that in. The devices will enumerate in the order that they are plugged in to the hub. This one-hub trick should work for MacOS and windows too, they should come up in the same order.

Harder method- udev rules. For devices with a unique ID such as FTDI you can set a udev rule that sees it's serial number and then creates a symlink to that device, it's straightforward.

For devices with the same or no Serial number, it's a lot more complex. I created a udev rule that looks like this:

SUBSYSTEM=="tty", ATTRS{product}=="USB2.0-Serial", RUN+="/usr/local/bin/cheapduino.py %k", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ENV{ID_MM_DEVICE_IGNORE}="1"

when the device matches the product and vendor of the cheap arduino, it runs the script 'cheapduino.py' with the device as argument, for instance

cheapduino.py ttyUSB0

Then the cheapduino script connects by serial to the device and sends the string 'ID' and the software on the device responds DEVID=THX1138 or whatever. The script then creates a symlink /dev/THX1138 that points to /dev/ttyUSB0

There are a lot of drawbacks to this method. The script must time out if the software on the cheapduino doesn't answer. Also this is not using the SYMLINK function of udev so it won't clean up dead links on disconnect, but it will overwrite them on reconnect. All of your cheapduinos must have this functionality in their software, with different device IDs set. They all must use the same baud rate as the script unless you want to write a very complex script that takes a long time. Finally, this method works much better at low baud rate than at high baud rate, which for timing reasons may not succeed every time. (cheapduinos are cheap!) 9600 works much better than 115200 which works after several tries. But since all your CH340 arduinos must be the same speed with this method, you can only go as slow as your fastest device.

This method DOES work though, and it's what I'm using because I bought way too many of these cheap things.

In the end, buy genuine Arduinos or at least ones with FTDI chips or something else that sends a unique device ID.

=Rich

2

If what you want is to tell apart 2 devices that are basically identical, you have 2 ways:

  • always plug them in the same ports and use the USB tree to differentiate them
  • create an handshake protocol, where each Arduino uses a code that you have previously stored in their respective EEPROMs. It might even be possible to write a helper function for UDEV, so that the helper function does the handshake and tells UDEV the serial that is stored in each EEPROM. That would allow to write a UDEV rule for your devices.
2

CH340B (not the G) has an EEPROM where you can store the serialnumber.

https://www.mpja.com/download/35227cpdata.pdf

There is a windows tool as well to read/write it:

http://www.downxia.com/downinfo/196126.html

Will try to install and see how the G version behaves...

  • Can you tell me where to click on that Chinese stuff to download that tool? I found some links to a RAR file but they time out. – Elmue Feb 28 at 18:43
1

Put a Maxim DS18S20 on your board, each has a unique serial number and are very inexpensive. There are a lot of software examples on the internet using this device. You could dead-bug it to the nano. to operate it needs a 4.7K resister connected to +5 and a ground connection. You can connect both the 5V and Ground connections of the device to ground. It would be easy to dead bug this to the nano then by simple communication via one pin you can get the serial number. There are several packages available. With care you could use an input pin, read the serial and save it for future use. When it Inits it will do this again. Just be sure the input is not driven low during the init process.

Good Luck,

Gil

  • Once you aren't solving the problem in the USB serial, but rather with something which requires the cooperation of the processor on the board to discover, you might as well just modify the bootloader to contain a serial number readable both there and in an application program (ie "sketch") – Chris Stratton Oct 30 '15 at 0:34
  • What a nonsense. The DS18S20 is a digital thermometer! – Elmue Feb 28 at 18:52
  • Yes it is a thermometer; Yes it has a unique serial number that does not require changing the code or eeprom on each board. Inexpensive and simple. Drawback the micro has to respond. It will work with out changing IDE or any firmware etc however it requires a pin which can be worked around with a mux if needed. – Gil Mar 4 at 19:19
1

I hate to say it, but the answer is no, there is not way to uniquely identify multiple 340 based usb-serial converters.

I have the same problem, where I have multiple (4+) usb-serial converters, any one could be plugged into any port, and they were purchased at the same time and therefore are identical in every way (including iSerial of 0).

Basically, if I move things around, I have to connect by hand to see what's attached, peruse dmesg output, etc. It's a big pain.

tom

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.