Getting started with Teensy (Usb rubber ducky)

Got your teensy? Alright, here is how we get started. There are several different ways to get code onto your board. Some people prefer to do it from the command line, but I am a huge succor for the Graphical User Interfaces.

You will need to download 3 separate programs. If you have done any programing in the past with arduinos, you most likely already have the first one. Even if you do, re download it to make sure you have the latest version.

I recommend that you don’t plug in your teensy just yet. You already did plug it in? Don’t worry, nothing broke. I’ll tell you when it’s time to plug it in later on.

Download all 3 of these programs:

1.Arduino IDE – Free, cross platform and can program almost every atmel microprocessor you will probably run into.

wpid-wpid-finder-2010-10-21-21-342-2010-10-21-21-343.png

2.TeensyDuino – A plug in that adds Teensy support to the standard Arduino environment. It runs under the hood so you won’t actually see anything going on. Its purpose is to let the Arduino IDE set whether the teensy shows up a serial port, keyboard or a flash drive.

3.Teensy Loader – Absolutely essential for getting the code on to the board. Has a nice graphic that shows whether you are in ‘running’ or ‘programing’ mode.

wpid-wpid-1____finder-2010-10-21-21-342-2010-10-21-21-343.png

The first step is to get arduino software installed on your computer.  Getting this installed is pretty straight forward. Follow the directions on the Arduino website http://arduino.cc/en/Main/Software

When you have that installed, you are ready for the next step.

Close out of the Arduino program and run the TeensyDuino plugin that you downloaded in step 2. (Mac users, no need to copy the program to the application folder, once you run it, you can then delete the installer. I know, it looks like a program, but really it is just a plug-in.

You will be asked to find the location where the arduino software is installed. *You may run into problems here if you renamed your arduino program, or if you are running older versions. You must point the installer to the same folder that you installed the Arduino IDE.  Trying to install it to Program Files or the Applications folder will not work. This trips up many people the first time they try and install it.

If the next button doesn’t highlight even though you have selected the arduino folder, re download all 3 programs making sure that they are the latest versions, then start over. Also triple check that you selected the correct ardunio folder. My machine has multiple hard drives, so I had to navigate until I found the right one.

Alright, you made it this far, just one last step. Install the Teensy Loader program. It should go pretty quick. When that is done, you should see a screen like this. You need to leave this running.

wpid-wpid-teensy-2010-10-21-21-342-2010-10-21-21-343.png

Sweet! Now you can plug in your teensy (I told you I would let you know when) and fire up the arduino software.

You will most likely be presented with a blank screen.

wpid-wpid-arduino-2010-10-21-21-342-2010-10-21-21-343.png

Lets check a couple of settings. First lets go to “Tools>Board” and select the type of teensy you purchased. (Most likely you have version 2.0) If you aren’t sure, then check your receipt. If you can’t find what I am talking about, then you most likely need to reinstall the TeensyDuino Plugin. See step 2.

wpid-wpid-arduino1-2010-10-21-21-342-2010-10-21-21-343.png

Ok Lets start programming. First we will make a simple program to make the onboard led blink. Here is the format for every program you will write. Start out with 2 functions. A Setup() function and a Loop() function, both are returning void.

wpid-wpid-1____arduino-2010-10-21-21-342-2010-10-21-21-343.png

The setup() runs once whenever power is applied. You put in setup your initialization of the pins, and your global variables. After that it proceeds to the loop function and will do just what it says, loop endlessly.

Ok, now lets tell the board where the LED is. we know from the documentation that there is a built in led on pin 11. Every pin on the board can be either an input or an output. Outputs are for controlling an external device, (led, motor, buzer). Inputs are for sensors and interrupts.

This is how we setup the led on pin 11. It goes in the setup function.
wpid-wpid-2____arduino-2010-10-21-21-342-2010-10-21-21-343.png

Now in the loop function, lets turn on the led for 2 seconds, then turn it off for 1 second.

wpid-wpid-3____arduino-2010-10-21-21-342-2010-10-21-21-343.png

digitalWrite(11,HIGH);                 – sends 5 volts to pin 11.
delay(2000);                         – waits 2000 milliseconds (aka 2 seconds) before moving on.
digitalWrite(11,LOW);                 – sends 0 volta to pin 11.
delay(1000);                                 – waits 1000 milliseconds before moving on.

Great, you have your first program written. Lets upload it to the board.

Compiling & uploading your program

Compiling your code will convert it from english to the 1’s and 0’s the microprocessor understands. In the arduino software, you can compile by pressing the “play button” in the left top corner.
wpid-wpid-4____arduino-2010-10-21-21-342-2010-10-21-21-343.png

Click Compile then after a couple seconds you should see “Done compiling” in the bottom message box. If you don’t, double check your code. Every digitalWrite should be orange if you spelled it correctly, and every { should be matched with a }. If you get an error about only finding version 1.05 of the teensyduino software, go to the download page and re download version 1.06. Apparently the download link sometimes points to an out of date version. You must have version 1.06.
wpid-wpid-5____arduino-2010-10-21-21-342-2010-10-21-21-343.png

Bring your Teensy Loader program into focus with alt tab or click the icon in the dock / start bar (You did leave it running didn’t you?).

To upload your now compiled code, push the physical button on your teensy. Pushing the button will set the microprocessor to “programming mode”.

Once you do that you will see your Teensy Loader program change its picture.

The screen should switch from this
wpid-wpid-1____teensy-2010-10-21-21-342-2010-10-21-21-343.png

to this

wpid-wpid-safari-2010-10-21-21-342-2010-10-21-21-343.png

Ok, now we are ready to upload. Leave the Teensy Loader application open, and switch back to the arduino software. Press the Upload button.

wpid-wpid-1____arduino1-2010-10-21-21-342-2010-10-21-21-343.png

Uploading your first program should only take a couple of seconds. When it finishes your teensy should automatically restart and start running your script. You know that you didi it correctly if the led turns on for 2 seconds then off for 1, repeating for ever.

Other things to try.

What happens if you change the pin 11 to pin 12?

What happens if you change the 2000 to 5000?

Will the code compile if you delete the setup function?

If you are ready for some more advanced ideas, check out DaberManias blog here

Advertisements

About spuder
spuder is a "super computer" support engineer by day, and tinkerer / hobbyist by night.

2 Responses to Getting started with Teensy (Usb rubber ducky)

  1. DaberMania says:

    Great Teensy getting started guide!!! I thought I would share my blog with you. (http://dabermania.blogspot.com/) I have a few more Teensy tutorials there to include using it as a USB keyboard, transferring files through Windows HID drivers, and interacting with an SD card with Teensy.

    • spuder says:

      Hey thanks for the kind words. I will add a link to your site. Looks like you have a lot of great postings.

%d bloggers like this: