Difference between revisions of "Jetson/Tutorials/Communicate To Arduino"

From eLinux.org
Jump to: navigation, search
(Added intro title)
 
Line 11: Line 11:
 
On the Jetson side, the user would <code>open()</code> <code>/dev/ttyUSB0</code> and perform read/write calls on the returned descriptor, using <code>termios.h</code> for configuring options like baud rate, etc.
 
On the Jetson side, the user would <code>open()</code> <code>/dev/ttyUSB0</code> and perform read/write calls on the returned descriptor, using <code>termios.h</code> for configuring options like baud rate, etc.
  
TODO example serial code
+
A tutorial, by Chris Heydrick, for communicating with an Arduino Uno via an Ubuntu system can be found [http://chrisheydrick.com/2012/06/24/how-to-read-serial-data-from-an-arduino-in-linux-with-c-part-4/ here].
 +
The C code for the example above can be found on Chris' [https://github.com/cheydrick/Canonical-Arduino-Read Github].
 +
This code has been tested successfully for read/write on a Jetson with an Arduino Uno (Grinch Kernel 19.3.3).
  
 
== I2C communication ==
 
== I2C communication ==

Latest revision as of 15:31, 25 March 2015

Introduction

There are multiple ways an Arduino or any microcontroller can communicate with a Jetson TK1. The easiest & recommended method is to use serial UART communication. It is also possible to use I2C (faster than serial), SPI (faster than I2C), or direct GPIO, but these are slightly more tricky than serial UART communication.

Serial UART communication

User applications that need two-way communication between the Jetson & Arduino can implement it using serial UART. UART on Arduino typically runs at aroud 100kHz (115,200 Hz) but it can actually run at upto 1MHz.

On the Arduino side, communication is implemented with the Serial API.

On the Jetson side, the user would open() /dev/ttyUSB0 and perform read/write calls on the returned descriptor, using termios.h for configuring options like baud rate, etc.

A tutorial, by Chris Heydrick, for communicating with an Arduino Uno via an Ubuntu system can be found here. The C code for the example above can be found on Chris' Github. This code has been tested successfully for read/write on a Jetson with an Arduino Uno (Grinch Kernel 19.3.3).

I2C communication

To use I2C on Jetson TK1, be aware that the I2C connections on Jetson TK1 are either 1.8V or 3.3V, while some Arduino's & microcontrollers need 5V signals. There is some info about bidirectional voltage tanslation for this on the GPIO Electrical Connections page. There is also an I2C page for Jetson TK1. I2C normally runs at 100kHz, but it can run at 400kHz with a code change. I2C allows the master device to send data to a slave device, or to request data from a slave device (see more info).

SPI communication

SPI is often running at 100kHz, but it can run at 4MHz (or even 8MHz if you use a 16MHz Arduino, since it will be at half the CPU clock rate).

Direct GPIO communication

The GPIO tutorial shows how to send a 5V voltage signal to an Arduino or microcontroller from a Jetson TK1. This can be used if you only need one-way signals or communication from Jetson TK1 to an Arduino, rather than two-way communication. The Arduino or microcontroller can either "poll" for the signal (repeatedly read the value over & over again until it changes), or be configured to automatically trigger an interrupt when the voltage changes between 0 and 5V.