Input from Serial (FTDI) to a php/python script
Question: I and some other people are working on a project that includes using an
Arduino with an Ubuntu Server (running Ubuntu 10.04 64 bit). Currently we have
the device connected and we can see the Arduino putting data in /dev/ttyUSB0.
I can successfully cat it to another file.

We have a MySQL database that this information will be translated to, via
either a python or php script. I need to know how to get the input from the
serial port to be the input for that script. The device will be responding at
least 20 times a second. The script essentially just needs to take whatever
response it gets and insert the corresponding row to the MySQL database.

Has anyone done this before who could help out?


Answer: It seems you are doing just fine. You could directly open `/dev/ttyUSB0` like
a file in your code, but as write and read access should be done at a certain
pace (serial baudrate, ...), it may be problematic (but still possible: I
never tried it, but you can [configure the
TTY](http://arduino.cc/playground/Interfacing/LinuxTTY) to directly write in
it).

The missing link is you have to access `/dev/ttyUSB0` like a serial port.

You mentionned Python: with it you can use
[PySerial](http://pyserial.sourceforge.net/). It also makes your code more
portable toward other operating systems. A quick `apt-get install python-
serial` or `apt-get install python3-serial` should work.

You have some examples in the [Arduino
playground](http://arduino.cc/playground/Interfacing/Python):

    
    
    import serial
    ser = serial.Serial('/dev/ttyUSB0', 9600)
    while 1:
        ser.readline()
    

There are plenty others in the [PySerial
introduction](http://pyserial.sourceforge.net/shortintro.html).

