Teensy 3.1 First Look – Features, Installation, and Compiling Blink

I purchased a Teensy 3.1 several months ago and finally got around to having a look at it. The Teensy is made by PJRC and full details can be found at http://www.pjrc.com/teensy. I purchased mine from Sparkfun.

These notes apply to the 3.1. While there are similarities between it and the older versions, there are differences, and I have not spent time learning the differences and, so, do not discuss them.

My primary reason for purchasing the Teensy is because it can act like a USB HID device such as a keyboard or a mouse. While the Arduino Leonardo can do the same thing, the Teensy has many more capabilities than Arduino MCUs so I wanted to have a look.

Here is a comparison between the Teensy and Arduino Mega 256:

Teensy 3.1 Arduino Mega 256
CPU 72MHz 16MHz
Flash Memory 256KB 256KB
RAM Memory 64KB 8KB

The CPU is 4.5X faster and it has 8X as much RAM. Flash is a healthy 256KB for both MCUs while the Mega has 2X the EEPROM.  RAM is always my bottleneck, so having 8X more memory is the most significant difference for me.

The Teensy is a 3.3V MCU, but its digital pins are 5V tolerant, so you can use 5V components on those pins. The analog, AREF, PROGRAM, and RESET pins are NOT 5V tolerant and you can’t exceed 3.3V on those pins.

The Teensy also has real analog output rather than just PWM. Don’t know if I’d ever make use of it, but I’ll try to file that factoid away for possible future use.

The Teensy supports 3 serial connections, 2 I2C connections, CAN bus, and you can solder on a crystal and add a battery to give it a built-in realtime clock.

And, as I said before, the Teensy’s USB port can be used for many purposes besides just loading software into the MCU. It can act as a serial port, a mouse, a keyboard, a joystick and even a MIDI port.

Here is the Teensy pin out, courtesy of PJRC:

First Use

The Teensy comes with the Blink sketch preloaded. Simply connect it to a power supply via its micro USB port and you know immediately that it is working properly.

Unlike the Arduinos, where the USB port is only for programming and serial communication, the Teensy’s port can have other uses. Therefore, you must signal that you want it to download new code. This is done by pressing a button on the Teensy. Pressing the load button invokes the Teensy’s HalfKay loader program which communicates with the PC to download new code.

Downloading Fast Blink Sample Code

The PJRC website (http://www.pjrc.com/teensy/loader_vista.html)will step you through downloading binary code from your PC into the Teensy. While different from the arduino, it is a simple process.

Essentially, you will run teensy.exe which appears as follows:Teensy-FL-Fig01

You then press the loader button on the Teensy and teensy.exe changes to look like this:Teensy-FL-Fig02

File | Open Hex file and open blink_fast.hex:Teensy-FL-Fig03
Now select Operation | Program:


You will then see download complete:


Now select Operation | Reboot:


and now you should see the LED on the Teensy flashing much faster.

You can also select automode:


Once you do this, pressing the loader button on the Teensy will automatically download and reboot.

Installing Teensyduino

To write code for the Teensy MCU, you need to install Teensyduino. Teensyduino simply inserts itself into your existing Arduino IDE install. You then just select Teensy as the board and write code like you would for an Arduino. I daresay much of what you would write for an Arduino will run on the Teensy.

Teensyduino is found at http://www.pjrc.com/teensy/td_download.html

On my first test install, I let Teensyduino install straight into my existing Arduino IDE. I decided I didn’t like that. It adds a lot of different settings and examples. While that is fine if I’m working with the Teensy, I don’t want that stuff if I’m working with Arduino.

So I copied my working c:\arduino-1.0.6 directory to c:\teensy-1.0.6 and then installed Teensy into that new directory.

When you run the install program make sure you run it as administrator!

Since I was installing Teensy separate from arduino, I let it install all libraries.

Compiling Blink in Teensyduino

Here is a quick example of how to get a test program compiled and running.

First select the appropriate board:


Select the appropriate use for the serial port (use just serial unless you plan to emulate one of the other devices):


Select the CPU speed. 72MHz is the fastest w/o overclocking so that is what I expect to normally use:


Now open the blink sketch:


The LED pin is already set correctly for the Teensy 3.1:


Now compile and upload the sketch:


Once compilation/upload is complete, press the loader button to actually upload the code and reboot:


A Difference when using Serial.print() to Debug

When debugging with an Arduino, when you start a terminal emulator, the Arduino will restart so you can start seeing text displayed from the beginning.

Teensy doesn’t do this. When you attach your terminal emulator, you start seeing text at the location currently being executed. And there is no reset button either to force the Teensy to begin from the beginning.

My first work-around to this problem is to simply wait for DTR to go high right after doing a Serial.begin():

while (!Serial.dtr()) {}

Not very sophisticated, but it will do until I need something better.

This entry was posted in c-tinys and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s