This blog, and the accompanying YouTube videos, will describe how to setup the Jetduino on the Jetson TK1, and then show how easy it is to use the incredible number of GPIO lines that the Jetduino makes available. It took me a bit longer to get this finished than I had hoped. Part of that was that it took a while to get the Jetduino repo to a usable state, but I also ran into some issues trying to record decent looking video from the Jetson. Special thanks to Jim at JetsonHacks for pointing me towards a hardware solution that worked like a charm. It allowed me to produce a small video showing how to setup the Jetduino, and then a slightly longer one showing how to control both the Arduino and Jetson I/O lines using the Jetduino libraries for Python and C. I am working on a number of videos and blogs for the next few weeks that show how to use all kinds of Grove and RobotGeek modules with the Jetduino and Jetson TK1. For now though, lets see how to setup the Jetduino!
The code and install scripts for the Jetduino are all included in its GitHub repository (https://github.com/NeuroRoboticTech/Jetduino). The Jetduino was modeled on the GrovePi from Dexter Industries. In fact, the Jetduino repo was a fork from the GrovePi repo that I have modified to work with the Jetson TK1 instead of the Raspberry Pi. (Big thanks to Dexter Industries for making this open source. It made using this for the Jetduino much, much easier!) Below is a list of the commands you will need to run in order to download the repo and install the Jetduino modules. This was all tested on a stock 21.4 Tegra kernel for the Jetson TK1. The install script will download some python utilities needed to use the Jetduino, and will then install the Jetduino python modules so they can be used globally.
$ sudo apt-get install git git-gui gitk
$ git clone https://github.com/NeuroRoboticTech/Jetduino.git
$ cd Jetduino/Script
$ sudo ./install.sh
you can test that it worked by trying to import the jetduino python module
# sudo python
>>> import jetduino
Next you need to upload the firmware sketch for the Arduino. Please note that you only need to use this sketch if you want to use the provided jetduino libraries. If you would prefer, you can handle the communications between the Arduino and Jetson on your own and use your custom sketches. The firmware that comes in the repo works with the libraries to give you direct access to the Arduino lines, and has built in control code for a number of the more advanced Grove modules. This is done using the GEN2 I2C line of the Jetson. It is connected to the Arduino Due, and the Jetduino libraries talk to the Arduino firmware sketch over I2C for setting and reading digital and analog values, controlling servos and more.
You will need to use the latest 1.6.7 version of the Arduno IDE to upload the sketch. I ran into a bug while trying to use a previous version. The I2C code for the Due did not handle repeated start sequences correctly, and this prevented the smbus python modules from working correctly. Since I do not yet have the 1.6.7 version of the IDE working on the Jetson you will need to use another Windows or Linux computer to upload the sketch.
Once the firmware is uploaded then you are done. That's it for setting up the Jetduino. Now you can use the Python or C interface to control things on the Arduino or the Jetson. Please note that there are examples for other types of interfaces in the Software folder, like C#, NodeJS, and Scratch. However, I only have the C and Python examples working at the moment. I plan to convert those over later. Here is a quick sample Python script that reads a touch sensor and uses that input to control a Grove LED, or Grove relay, or any other Grove module with a digital input.
import timeimport jetduinofrom jetduino_pins import *# Connect the Grove Button to digital port D4# SIG,NC,VCC,GNDbutton = ARD_D4led = ARD_D6jetduino.pinMode(button, INPUT_PIN)jetduino.pinMode(led, OUTPUT_PIN)while True: try: val = jetduino.digitalRead(button) print ("LED %d" % val) jetduino.digitalWrite(led, val) time.sleep(.1) except IOError: print ("Error")
This code first imports the jetduino and pin mappings, and then defines the pin ids for the touch sensor and led using ARD_ pins (ARD for Arduino, JET for Jetson). It uses the pinMode method to set the touch sensor to an input, and the led to an output. It then enters a loop and reads from the button and sets the led. Pretty simple. You use the exact same methods to read and write from the Jetson GPIO as well. A C library is also available, and the way to use it is virtually identical.
Here are two videos that demonstrate how to do all this. The first one shows you how to setup your Jetduino. The second shows how to interface with the digital I/O using both Python and C. If you like the Jetduino then please subscribe to my newsletter so you can be notified as I add new videos, and so you can know when the crowdfunding campaign goes live so you can order your own Jetduino!
Notify me of followup comments via e-mail
Please subscribe to my Newsletter!
NeuroRobotic Technologies is dedicated to creating the next generation of intelligent, adaptive robotic systems by building autonomous controls systems that mimic the brains of real animals.