Teensy 3.1 Command Line Compile

The Teensy

The Teensy is a microcontroller based development platform produced by PJRC. Several different version have been produced but the Teensy 3.1 is based on an ARM processor with 64K of RAM and 265K of plash for programs and static data. Programs are developed on a PC and uploaded to the Teensy via USB.


For development, PJRC provide an extension for the Arduino development environment to add support for Teensy, called Teensyduino. This is great for getting started but personally I find the Arduino editor a bit clunky and wanted to use something else. Fortunately it's possible to possible to separate the Teensy compile/upload environment from the Arduino editor so that you can use whatever editor you like. I'll explain how in 4 easy steps:

These instruction are for Linux, the process might be adaptable to MacOS or Windows but I have not tried it. They are also specific to Teensy 3.1 and will not work for other version of the Teensy.

1. Install Arduino IDE + Teensyduino

In order to compile from the command line we need Teensyduino installed and in order to install that we need the Arduino IDE, so the first step is to get the Arduino IDE and Teensyduino working. If you're reading this then you've probably already done that but if not, start by going to the Teensyduino download page and downloading the installer. On the same page you can check which versions Arduino Teensyduino is compatible with. This is important as they will need to match.

Once you've down that you need to download Arduino. In most cases it can be installed from your package manager but if not, or the version there is not compatible with Teensyduino, you can get it from the Arduino download page and install it using the instructions on this page.

After installing Arduno, install Teensyduino following the instructions on the Teensyduino download page. Once this is done check that everything is working by sending a few examples to the Teensy and making sure that they download and run correctly. If this doesn't work then the next part work either.

3. Download the Makefile and set it up

Once you've done that you need the modified Makefile which you can download from here. Save this to the the directory where you will be putting your source code. You will need to modify the makefile to specify the path to your arduino/teensyduino installation. Find this part:

# Path to your arduino/teensyduino installation
ARDUINOPATH = /usr/bin/arduino

and change the path to the directory where you installed Arduino and Teensyduino. For example for me this was:

# Path to your arduino installation
ARDUINOPATH = /home/dave/Build/arduino-1.6.3

4. Try it out

You should now be in a position to complile something from the command line. To try it out, download this c++ source file and save it as main.cpp in the same directory as the Makefile. Now connect your Teensy and run "make". You should get a successful compilation and the program should automatically upload to the Teensy. If it works you'll get a blinking LED which is on for 0.9 of a second and off for 0.1 of a second.

If get a problem where the compiled program won't upload to the Teensy, it may be because of the USB type being used. To fix this, load the Arduino/teensyduino IDE, set the USB type to serial and flash one of the example programs. Then try the command line compile again, it should work.

If you want to monitor the USB serial output of the Teensy, you can do that with the following command:

screen /dev/ttyACM0 115200,N,8,1

Assuming the Teensy is using the USB serial device /dev/ttyACM0. It probably will be but change it if it isn't.

5. Examples

This zip file contains three examples of using the Makefile, one with a C program, one with a C++program and one with a C++ program with multiple source files and using the Arduino convention of having a setup() and loop() function. To try the examples you will need to set ARDUINOPATH as per step 3 above.

Previous page: Home
Next page: Game-o-Tron 3000