udev rule for FTDIBasic from SparkFun


The ESP8266 came with pins already soldered, so I needed to use a breadboard to connect it to the FTDI. It's ugly but it's just an experiment.

The ESP8266 came with pins already soldered, so I needed to use a breadboard to connect it to the ftdi. It's ugly but it's just an experiment.

I've been fiddling with an ESP8266 this week that is being powered by an FTDIBasic board from SparkFun.  The setup is simple enough and it's easy enough to get a simple web server running on it but I don't have a power switch so the whole thing is powered through the FTDI board.  When I unplug the FTDI from the USB hub and plug it back in I get a different ttyUSBx port under linux.  That means whatever serial terminal I'm using (arduino's or Minicom, for example) has to change after I connect the power.  But I want to see whatever the ESP8266 prints immediately at boot.  There is no way to manually switch ports in the terminal fast enough for this.  The solution is to use the same ttyUSBx port every time.  The way to do that is with a simple udev rule.

First, let's look at the rule:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001",
   GROUP="mjhammel", MODE="0660", SYMLINK+="ttyUSBFTDI"

This line (and that's a single line, it's just broken to make it readable on the web) is placed in a new file called /etc/udev/rules.d/99-usb-serial.rules.  You need root permission to do this.   With the file saved, I plug in the usb connector on the FTDI board to a usb port on a hub of my Linux (fedora, in my case) computer.  Then I can check that it worked by listing out the ttyUSB ports.

$ ls -l /dev/ttyUSB*
crw-rw---- 1 root mjhammel 188, 0 Feb 15 14:26 /dev/ttyUSB0
lrwxrwxrwx 1 root root 7 Feb 15 14:26 /dev/ttyUSBFTDI -> ttyUSB0

What this rule did was tell udev to create the ttyUSBx port – in this case ttyUSB0 – with a group of mjhammel that has read and write permissions on it.  That group is the group I'm using for my user id.  The other thing it did was to create a symbolic link from it to a device called /dev/ttyUSBFTDI.  That means that no matter what real device is created when I plug in the FTDI board I'll always have a link to it with the ttyUSBFTDI filename.  Now I don't have to worry about which port is actually in use.  I can always use the symbolic link.

If this doesn't work out of the box for you then you probably just need to find the right vendor and product IDs.  List out the devices on the USB hub.

$ lsusb
...
Bus 008 Device 011: ID 0403:6001 Future technology Devices International, Ltd FT232 Serial (UART) IC

...

Look for the future technology devices international (re: FTDI) entry.  The two 4-digit hex numbers next to ID are the vendor ID and the product ID, respectively.  Replace idVendor and idProduct in the rules file to match your setup.  Then save the file, unplug and replug the FTDI into the USB port and you're done.

Note that this didn't really solve my problem, since unplugging the FTDI will drop the port and minicom and the Arduino monitor drop connection to it and do not automatically reconnect.  But at least you don't have change your settings to figure out which port to connect to the next time you open the serial console to the ESP8266.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.