Teensy boards are Arduino compatible but have a few idiosyncrasies. This guide will run you through the basics to start programming your Teensy.
What you’ll need
Install Arduino IDE
- Go to https://www.arduino.cc/en/main/software and download the correct IDE for your operating system if you don’t already have it.
- Once downloaded, install the package by opening it and following any prompts.
- Once installed open it and close it again.
Install Teensy Loader
The Teensy Loader application uploads programs to your Teensy board and lets you run them. When you use Arduino, this will be done automatically, but doing it manually is a simple way to check that your board works.
Download the correct Teensy Loader for your OS and install it.
Install Teensyduino
Teensyduino looks pretty much like Arduino IDE but is tailored for Teensy.
Note that you’ll need to have installed Arduino IDE for Teensyduino to work.
- Go to https://www.pjrc.com/teensy/td_download.html and download the correct version of Teensyduino for your operating system.
- Install Teensyduino.
Run LED blink
Blink slow comes preinstalled on all new Teensy boards.
Power your teensy with the mini USB cable. The built-in LED should flash every second.
Load a new programme
- With your Teensy connected to your computer, open Teensyduino.
- Go to Tools>Board and in Teensyduino select the appropriate Teensy board.
- Copy and paste the following code:
/* Blink without Delay
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
const int ledPin = 11; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 100
; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
- Save the sketch.
- Upload the code to your Teensy by clicking on the right-pointing arrow on the Teensyduino window.
- Press the button on the Teensy.
Your Teensy should now be flashing rapidly.