Jetson/Tutorials/Program An Arduino

Introduction
This tutorial describes how to program an Arduino microcontroller from a Jetson TK1 (instead of from a PC). Whereas the tutorial to get your Arduino communicating with a Jetson TK1 is at Communicate To An Arduino.

Arduino devices are very simple-to-use microcontroller boards commonly encountered in embedded projects, and can communicate with a Jetson TK1 via Serial UART or I2C, or can be programmed from a Jetson TK1 through USB (ie: allowing you to develop Arduino code using a Jetson TK1 instead of using a PC for development).

FTDI kernel module
Upon connecting an Arduino's USB port to the Jetson, we can see the Arduino uses an FTDI serial-to-USB converter:

ubuntu@tegra-ubuntu:~$ lsusb Bus 002 Device 006: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC

However support for the FTDI converter device is not set in the kernel configuration by default:

ubuntu@tegra-ubuntu:~$ zcat /proc/config.gz | grep FTDI
 * 1) CONFIG_USB_SERIAL_FTDI_SIO is not set
 * 2) CONFIG_USB_FTDI_ELAN is not set

We will need to compile the FTDI kernel module from source to use the device.

L4T kernel source
First, download the kernel sources from https://developer.nvidia.com/linux-tegra-rel-19 and copy the archive to the Jetson, into the ubuntu user home directory. Then extract the tarball to :

tar xvjf kernel_src.tar.bz2

Configuring the kernel
Copy over the Jetson's existing kernel configuration to the newly-extracted kernel source:

zcat /proc/config.gz > ~/kernel/.config

Next build & launch the  tool to configure the kernel options. requires ncurses to be installed, hence the apt-get command first.

sudo apt-get install ncurses-bin libncurses5-dev make menuconfig

Navigate to

Choose 'M'odule for

Save changes and exit.

Verify that the FTDI component is now set to build as module:

ubuntu@tegra-ubuntu:~/kernel$ cat .config | grep FTDI CONFIG_USB_SERIAL_FTDI_SIO=m
 * 1) CONFIG_USB_FTDI_ELAN is not set

Building modules
make prepare make modules_prepare

make M=drivers/usb/serial/ Building modules, stage 2. MODPOST 2 modules CC     drivers/usb/serial/baseband_usb_chr.mod.o  LD [M]  drivers/usb/serial/baseband_usb_chr.ko  CC      drivers/usb/serial/ftdi_sio.mod.o  LD [M]  drivers/usb/serial/ftdi_sio.ko

Installing the FTDI module
sudo cp drivers/usb/serial/ftdi_sio.ko /lib/modules/$(uname -r)/kernel sudo depmod -a

Verify installation
Now when the Arduino is plugged in, we see the FTDI module loaded and  node assigned:

ubuntu@tegra-ubuntu:~/kernel$ dmesg | grep usb [  57.385970] usb 2-1.5: new full-speed USB device number 5 using tegra-ehci [  57.407931] usb 2-1.5: New USB device found, idVendor=0403, idProduct=6001 [  57.407950] usb 2-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [  57.407964] usb 2-1.5: Product: FT232R USB UART [  57.407976] usb 2-1.5: Manufacturer: FTDI [  57.407987] usb 2-1.5: SerialNumber: A601NG2B [  57.479238] ftdi_sio: version magic '3.10.24 SMP preempt mod_unload ARMv7 p2v8 ' should be '3.10.24-gf455cd4 SMP preempt mod_unload ARMv7 p2v8 ' [  57.504885] usbcore: registered new interface driver ftdi_sio [  57.507384] usbserial: USB Serial support registered for FTDI USB Serial Device [  57.508073] ftdi_sio 2-1.5:1.0: FTDI USB Serial Device converter detected [  57.508917] usb 2-1.5: Detected FT232RL [  57.508934] usb 2-1.5: Number of endpoints 2 [  57.508948] usb 2-1.5: Endpoint 1 MaxPacketSize 64 [  57.508960] usb 2-1.5: Endpoint 2 MaxPacketSize 64 [  57.508971] usb 2-1.5: Setting MaxPacketSize 64 [  57.511143] usb 2-1.5: FTDI USB Serial Device converter now attached to ttyUSB0

In this case, the port has been assigned to. Remember this for when using the Arduino IDE.

Using the Arduino IDE
Running the Arduino IDE on the Jetson is easy, as it's included in the Ubuntu 14.04 repository, and allows one to use the Jetson to develop & upload sketches directly to the Arduino board.

sudo apt-get install arduino arduino-core





Testing with Blink example
Test the Jetson's ability to connect & upload sketches to the Arduino by running the Blink example. At this point, the directions for using the Arduino are the same as from any other platform (like Windows/MacOS), as can be followed at http://arduino.cc/en/Guide/Windows#toc6

Using the Arduino Due with the Jetson
The Arduino Due is a massively more powerful version of a standard Arduino that uses the Atmel SAM3X8E ARM Cortex-M3 CPU. This is a 32-bit ARM core microcontroller that runs with an 84 MHz clock. This contrasts to the Arduino Uno that uses an ATmega328 8-bit RISC microcontroller running at only 16 Mhz. The Due is a real powerhouse. Unfortunately, it cannot be used with the older version of the Arduino software that is available using apt-get. It requires the 1.5+ version of Arduino. If you want to use the Due you can download a pre-compiled version of Arduino 1.5.4 for the Jetson here: http://neurorobotictech.com/Projects/Jetduino/ArduinoDueonJetsonTK1.aspx. It has instructions on how to configure your Jetson to be able to run the 1.5.4 software. Also, if you are interested in how to recompile the Arduino software from scratch so it will work on the Jetson, or other ARM systems, then this blog entry has detailed descriptions explaining the steps you will need to follow: http://neurorobotictech.com/Community/Blog/tabid/184/ID/4/Compiling-Arduino-154-for-the-Jetson-Tk1-and-ARM--Part-1.aspx

Communication between an Arduino and a Jetson
If you need your Arduino to communicate with your Jetson TK1, then read the Arduino Communication page.