Thursday 19 July 2012

Connecting an Arduino Uno to OpenWRT


Connection an Arduino Uno to TPlink mr3020n running OpenWRT.

After about a days of playing around with OpenWRT I have finally have it communicating with an Arduino Uno. 
The process is too complex to put into a single post so I will have to break the process up into small steps/posts. 
The process requires you to know your way around vi/vim as the base openWRT images do not have a webserver installed. I high recommend you use a usb-ttl serial adapter to connect to the serial console of the router during the process. 

There are also a few things to watch out for,

  1. The wireless and wireless nic has the same MAC address. Don't use both at the same time to connect to the same access point. Your DHCP server does not like this.
  2. After flashing the openWRT image the default IP address is with not gateway set and until there is a root password set there is no SSH. So you need to telnet into the router and set a password and using vi change the network settings in /etc/config/network      
  3. Only 4MB flash. The router is very tight on space. After flashing the openWRT you have only 1.2MB of space free and this disappears quickly. To get more space you need to add a something like a USB flash drive. But by the time you have installed the USB drivers, Filesystem drivers and web interface you are down to less the 150k. I recommend you format the drive as EXT2 and set it up as extroot as the first thing you do otherwise you will be out of space before you have even finished installing your basic drivers. Note that if you get down to less then 100k programs like vi will not let you save changes so try and keep as much flash free. After setting up the USB storage you can then go on installing things like Python and anything else until your heart is content (or until you run out of space on your USB drive)  
  4. Arduino Uno uses usb-cdc so install kmod-usb-acm. The Uno will be detected and mounted as /dev/ttyACM0
    The older Arduino boards with FTDI chips require kmod-usb-serial-ftdi and will be detected and mounted as /dev/ttyUSB0 
    I was having a lot of issues using /dev/ttyACM0 like a serial port so piping data to it does not appear to work too well but if you install socat you can bind a TCP port to it using the following command
    socat tcp-l:1234,reuseaddr,fork file:/dev/ttyAMC0,nonblock,raw,echo=0,waitlock=/var/run/tty,b9600
    After binding a TCP port you can use a loopback connect or a remote telnet connection to port 1234 to communicate to your Arduino.  


  1. Hi, I'm interested in doing this. Could you send me the complete instructions? Thanks!

  2. Hi, I'm interested in doing this. Could you send me the complete instructions? Thanks!