FTDI on WGT634u Running OpenWRT Backfire

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 24-04-2012-05-2008

0

In this post I will document the modules that installed to get a WGT634u running OpenWrt Backfire to recognize a DFRobot.com FTDI (http://www.dfrobot.com/index.php?route=product/product&filter_name=ftdi&product_id=147).  In order to trouble shoot this better I am connected to the router via a usb to serial TTL cable.  Instructions on how to build one can be found here.

First we need to install the USB modules. This router seems to support usb2 and ohci so these are the ones that I installed.

opkg update
opkg install kmod-usb2
opkg install kmod-usb-ohci

Note: You can use the following command to see what usb is supported (uhci or ohci):

cat /proc/bus/usb/devices

Next we will install the modules for the FTDI:

opkg update
opkg install kmod-usb-serial-ftdi

Note that when you plug the FTDI into the Arduino you should connect the tx to tx, rx to rx, and gnd to gnd. It seems that the usb on my router does not have the output to power the Arduino through the FTDI so I am powering it separately with a 9v DC adapter.

Python Interface for Arduino Uno Using a Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 29-11-2011-05-2008

0

Edit:  I abandoned this method in favor of a simpler method.  I am using a FTDI to communicate and just executing serial commands with PHP.  You can see how I am doing this in this post.  I left this up thinking that it may be useful to someone else.  However, keep in mind it may not be complete.

In this post I will show you how I was able to communicate with my Arduino Uno connected to my Netgear WGT634u running OpenWrt Backfire.  This is a baby step toward being able to control the Arduino Uno from a website hosted by the Netgear WGT634u.

Setup

First we will install Python (python_2.6.4-3_brcm47xx.ipk) :

opkg update
opkg install python

Next we will install the PySerial module (pyserial_2.4-1_brcm47xx.ipk):

opkg update
opkg install pyserial

Now we need to edit the PySerial module to disable DTR, I discus this a bit (here):

cd /usr/local/lib/pythonX.Y/site-packages/serial
rm serialwin32.pyc
vi serialwin32.py

Change the following line:

self._dtrState = win32.DTR_CONTROL_ENABLE

to:

self._dtrState = win32.DTR_CONTROL_DISABLE

Now lets create a sample script and test it. First make a folder to put the python script in:

mkdir /python

Create the sample script:

vi /python/arduino_com.py
import sys
import arduino
 
ser = arduino.Serial('/dev/ttyACM0',9600)
 
if (len(sys.argv) >; 1):
print sys.argv[1]
ser.write(sys.argv[1])

Now lets test it.. To test the script I am using the LED example included with the Arduino software. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino. After you upload the sketch, plug it into the WGT634u and lets test it out. In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.

Turn the LED on:

/python/arduino_com.py H

Turn the LED off:

/python/arduino_com.py L

You can call you script from a webserver using cgi. Place the following file in your bin-cgi folder:

#!C:\Python27\python.exe -u
#!/usr/bin/env python
import cgi
import cgitb; cgitb.enable() # for troubleshooting
import arduino # For serial com (modified pyserial)
 
print "Content-type: text/html"
print
 
print """
Sample CGI Script

Sample CGI Script

"""
 
form = cgi.FieldStorage()
arg = form.getvalue("arg")
 
print """
str value: %s
""" % cgi.escape(arg)
 
ser = arduino.Serial('\dev\ttyACM0',9600)
ser.write(arg)

Visit it with your web browser using http://localhost:8080/cgi-bin/arduino_com.py?arg=H to turn the light on and http://localhost:8080/cgi-bin/arduino_com.py?arg=L to turn it off.

You can also call it from a webserver using PHP:

#button {
	font-weight: bold;
	border: 2px solid #fff;
}

How to Disable Serial COM Auto Reset on Arduino Uno

Posted by Max Power | Posted in Arduino | Posted on 29-11-2011-05-2008

2

Edit:  I gave up on trying to disable the auto reset through software.  The capacitor method works but is cumbersome.  The easiest solution is to use an external FTDI as I show in this post.

To test the following solutions I am using the LED example included with the Arduino software to test it. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino.  After you upload the sketch, plug it into the WGT634u and lets test it out.  In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.  However, you might notice that the LED blinks a bunch of times and does not stay light.  This is because the serial port resets.  When we are trying to communicate with it via the COM port this is annoying.  However there are ways to fix this.

Hardware Solution

Here are some hardware solutions that you might want to try: http://www.arduino.cc/playground/Main/DisablingAutoResetOnSerialConnection.  I was able to make it work by adding a 10uF capacitor between the RESET and GND.  One note though, you need to plug in the Arduino first to let it start, then you can add the capacitor.  If you have the capacitor connected before you connect the USB cable it will not work.  Here is a reference: http://tushev.org/articles/electronics/38-preventing-arduino-from-auto-reset-when-com-port-openscloses

Software Solution

The other option is to set Data Terminal Ready (DTR) to false or disabled for the port that hosts your Arduino.

Python

Here is an example of how to do this in Python.  I downloaded the pySerial package and modified it as follows:

  1. Copy the folder c:\Python27\Lib\site-packages\serial to c:\Python27\Lib\site-packages\arduino
  2. In the arduino folder, delete the file serialwin32.pyc
  3. Edit the file serialwin32.py, replace the line self._dtrState = win32.DTR_CONTROL_ENABLE to say self._dtrState = win32.DTR_CONTROL_DISABLE
  4. Save the file and use import arduino to use the modified package

Here is the code that I am using to turn on the LED on pin 13.  This uses the PhysicalPixel sketch mentioned above.

import arduino
ser=arduino.Serial('COM4',9600)
ser.write('L')

Arduino Uno Forward Serial to Telnet With ser2net on Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 29-11-2011-05-2008

1

This is how I used a WGT634u running OpenWrt Backfire to forward the serial port with the Arduino Uno to a telnet port.  This could be used as a cheap alternative to an ethernet shield or connecting the USB to your computer.  I was able to send commands to my Arduino via telnet over wireless network with the WGT634u in client mode.

Setup

Install ser2net:

opkg update
opkg install ser2net

Start ser2net:

ser2net -C "8082:raw:600:/dev/ttyACM0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS"

Now you should be able to communicate with your Arduino on port 8082.  Open up a telnet window and connect to your router.

Start on Boot

Next I will show you how to set it up so that ser2net will run on boot.

Edit the conf file:

vi /etc/ser2net.conf

Comment everything out and add this line at the bottom:

8082:raw:600:/dev/ttyACM0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS

Edit the startup file:

#!/bin/sh /etc/rc.common
START=10
STOP=15
start(){
ser2net
}
stop(){
killall ser2net
}

Enable the service:

/etc/init.d/ser2net enable

Arduino Uno Connected Via USB to Netgear WGT634u Running OpenWrt

Posted by Max Power | Posted in Arduino, Netgear WGT634u | Posted on 28-11-2011-05-2008

2

In this post I will show you how I connected an Arduino Uno to my Netgear WGT634u running OpenWrt Backfire via the USB port.  One thing to note is that it is much easier to trouble shoot if you are connected to the router with a serial cable.  I have another post (here) that outlines the process for building and connecting to the router with a serial cable.

Setup

First we need to make sure that we have the USB drivers that we need:

opkg update
opkg install kmod-usb-ohci

Next we will install the drivers package that will support the Arduino:

opkg update
opkg install kmod-usb-acm

Now when you plug the Arduino into the WGT634u, you should see that it is recognized (you will only see this if you are connected to the router with the serial cable):

usb 2-1: new full speed USB device using ohci_hcd and address 3
usb 2-1: configuration #1 chosen from 1 choice
cdc_acm 2-1:1.0: ttyACM0: USB ACM device

We should be able to find a new addition for the Arduino in the following location:

/dev/ttyACM0

Testing

Now that we have the Arduino installed, lets test it to see if we can send serial commands to it.  We can use the LED example included with the Arduino software to test it. Using your computer, upload the PhysicalPixel sketch from File > Examples > Communication > PhysicalPixel to the Arduino.  After you upload the sketch, plug it into the WGT634u and lets test it out.  In this example when we send a “H” the LED on the Arduino will light and when we send a “L” the LED will go off.

Turn off the led:

echo "L" > /dev/ttyACM0

Turn on the led:

echo "H" > /dev/ttyACM0

If this does not work for you, don’t fret…  It didn’t work for me either.  I appears that the older Arduino Uno boards reset the serial connection and so the light will flash but will not stay light.   I have a post (here) about how to fix this.

Summary

So now you have successfully connected your Arduino Uno to your Netgear WGT634u via the USB port and demonstrated that you can communicate with it via serial commands.