Wednesday, May 1, 2013

Raspberry Pi Direct USB to UART using FT232RL and Zigbee


Raspberry Pi Direct USB to UART for Zigbee communication.

I could not find complete information about using FT232RL USB to UART on the internet hence decided to put everything in writting.





Use the following information from FTDI website to install and check the FT232RL drivers



Sponsor: www.avmicrotech.com/shop  eshop for your electronic needs




**********************************************************

D2XX for Linux
--------------

As Linux distributions vary these instructions are a guide to installation 
and use.  FTDI has tested the driver and samples with Ubuntu 12.04 (kernel 
version 3.2) for i386 and x86_64, and Debian 6 'squeeze' (kernel version 
2.6.32) for arm926.

FTDI developed libftd2xx primarily to aid porting Windows applications 
written with D2XX to Linux.  We intend the APIs to behave the same on
Windows and Linux so if you notice any differences, please contact us 
(see http://www.ftdichip.com/FTSupport.htm).

FTDI do not release the source code for libftd2xx.  If you prefer to work
with source code and are starting a project from scratch, consider using
the open-source libFTDI.

libftd2xx uses an unmodified version of libusb 
(http://sourceforge.net/projects/libusb/).  Source code for libusb is 
included in the driver distribution.



Installing the D2XX shared library and static library.
------------------------------------------------------

1.  tar xfvz libftd2xx1.1.12.tar.gz

This unpacks the archive, creating the following directory structure:

    build
        arm926
        i386
        x86_64
    examples
    libusb
    ftd2xx.h
    WinTypes.h

2.  cd build/arm926

3.  sudo -s 
  or, if sudo is not available on your system: 
    su

Promotes you to super-user, with installation privileges.  If you're
already root, then step 3 (and step 7) is not necessary.

4.  cp lib* /usr/local/lib

Copies the libraries to a central location.

5.  chmod 0755 /usr/local/lib/libftd2xx.so.1.1.12

Allows non-root access to the shared object.

6.  ln -sf /usr/local/lib/libftd2xx.so.1.1.12 /usr/local/lib/libftd2xx.so

Creates a symbolic link to the 1.1.12 version of the shared object.

7.  exit

Ends your super-user session.

     ---I did not spent time on below----

Building the shared-object examples.
------------------------------------

1.  cd examples

2.  make -B

This builds all the shared-object examples in subdirectories.

With an FTDI device connected to a USB port, try one of the 
examples, e.g. reading EEPROM.

3.  cd EEPROM/read

4.  sudo ./read

If the message "FT_Open failed" appears:
    Perhaps the kernel automatically loaded another driver for the 
    FTDI USB device.

    sudo lsmod

    If "ftdi_sio" is listed:
        Unload it (and its helper module, usbserial), as follows.

        sudo rmmod ftdi_sio
        sudo rmmod usbserial

    Otherwise, it's possible that libftd2xx does not recognise your 
    device's Vendor and Product Identifiers.  Call FT_SetVIDPID before
    calling FT_Open/FT_OpenEx/FT_ListDevices.



Building the static-library example.
------------------------------------

1.  cd examples/static

2.  rm lib*

Cleans out any existing libraries built for another target.

3.  cp /usr/local/lib/libftd2xx.a .

4.  make -B

5.  sudo ./static_link

This example demonstrates writing to, and reading from, a device with
a loop-back connector attached.



The examples show how to call a small subset of the D2XX API.  The full
API is available here:
http://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer%27s_Guide(FT_000071).pdf

-----------End of skipped portion---------
***************************************************************



Sponsor: www.avmicrotech.com/shop  eshop for your electronic needs





Now check if your FTDI drivers have loaded properly. Insert your FTDI board into raspberry pi USB port and enter the command dmesg on Raspberry pi terminal. If you see this output at the end, you have your USB to UART, FT232RL installed.

[ 3194.136661] usb 1-1.2: Product: FT232R USB UART
[ 3194.136675] usb 1-1.2: Manufacturer: FTDI
[ 3194.136687] usb 1-1.2: SerialNumber: AH001BVN
[ 3194.188124] usbcore: registered new interface driver usbserial
[ 3194.190895] usbcore: registered new interface driver usbserial_generic
[ 3194.192574] USB Serial support registered for generic
[ 3194.192618] usbserial: USB Serial Driver core
[ 3194.207107] usbcore: registered new interface driver ftdi_sio
[ 3194.209875] USB Serial support registered for FTDI USB Serial Device
[ 3194.210233] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[ 3194.210754] usb 1-1.2: Detected FT232RL
[ 3194.210781] usb 1-1.2: Number of endpoints 2
[ 3194.210797] usb 1-1.2: Endpoint 1 MaxPacketSize 64
[ 3194.210812] usb 1-1.2: Endpoint 2 MaxPacketSize 64
[ 3194.210826] usb 1-1.2: Setting MaxPacketSize 64
[ 3194.212075] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0
[ 3194.212192] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver

Now testing time........

Please note that FT232RL  baud rate is that of the Xbee module's UART interface. I have both my Zigbee set at 115200. Hence data going out from FT232RL should be at 115200.

Option 1:- Add minicom program on raspberry pi and X-CTU Terminal on your PC. Please do not forget to configure both minicom and X-CTU to Hardware Flow control to "No".


minicom -b 115200 -o -D /dev/ttyUSB0

Alternatively you can configure minicom using

minicom -s


You exit minicom by typing first ctrl A   then Z and X (without ctrl).

Option 2:-Use the python code as mentioned in this link   http://elinux.org/Serial_port_programming. You will have to change your serial port to ttyUSB0. On PC side use X-CTU Terminal.

import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)
port = serial.Serial("/dev/ttyUSB0", baudrate=115200, timeout=3.0)
while True: port.write("\r\nSay something:") rcv = port.read(10) port.write("\r\nYou sent:" + repr(rcv))

This code too does a round trip data flow hence test both direction communication.




Sponsor: www.avmicrotech.com/shop  eshop for your electronic needs




.....cont