Assign specific device name and group to Arduino

I built a PWM fan controller using Arduino. It’s for my file server’s external fans. I wrote a small python script for setting PWM values to it.

I also wanted to control it from a web page, so I wrote a CGI script. The CGI script did not work because the Apache server is running with Apache’s user/group ID which is www-data/www-data while the Arduino’s serial port is root/dialout.

Since the Arduino is a “finished product” and I want a stable name, I can use the Arduino product name and serial number to assign a specific name.¬†For this, you use a udev rule. Here is the one I created for it.


SUBSYSTEM=="tty", ACTION=="add", ATTRS{manufacturer}=="Arduino*", ATTRS{serial}=="64131383331351F09291", GROUP:="www-data", SYMLINK+="serverfan"

and I named it /etc/udev/rules.d/75-arduino.rules.
After that, you unplug and plug back in the Arduino.
Now the CGI script can talk to the Arduino.

How to get to the Arduino serial number

It’s a good thing that Arduino has a serial number so that you can spot a specific one. Here is how you get the serial number.

$ sudo udevadm info  --attribute-walk  --name=/dev/ttyACM0 | grep serial
    ATTRS{serial}=="64131383331351F09291"
    ATTRS{serial}=="orion-ehci.0"

So I copy & paste the ATTRS{serial}==”64131383331351F09291″ part in the udev rule.

Leave a Reply

Your email address will not be published. Required fields are marked *