Teensy = Arduino* (for small quantities of Arduino)

A fair amount of my free time lately has been consumed by getting back into electronics, specifically microcontrollers. I took two years of electronics in high school and dabbled with it a little after. Life kind of got in the way, and it fell so far to the back burner than it wasn't even warm anymore.

I recently became aware of the Arduino development platform, and about the same time, another little device called the Teensy. Since then my 'entertainment budget' has been funneled into the bank account of SparkFun for various transistors, switches, regulators, and the all-important LEDs; and of course to PJRC for a Teensy... but just what is a Teensy?

The result of a project by Paul Stoffregen, the Teensy is a microcontroller development board based on the Atmel AT90USB162 AVR. The Arduino, also based on Atmel AVRs, differs from the Teensy in a few important ways:


  • The Arduino is 100% open source. While almost everything about the Teensy is open, the bootloader is not.


  • Most Arduino form factors are MUCH larger than the Teensy. This is good for instant development, as most of them come with header blocks attached so you can just start plugging things in, but it can be limiting when it comes time to put your project into a case.


  • Despite most Arduinos having USB ports, it does not actually do USB communications. A USB/Serial converter is used, which limits the speed at which it can be communicated with.


  • The Teensy, using native on-chip USB can, with only a few simple commands, be made to show up as either a USB/Serial device, a mouse, a keyboard, and with a little more work a mass storage device. These can be done with the Arduino, but it's a fair bit more involved.


  • And while the Teensy's older brother Teensy++ also has analog inputs, the original Teensy lacks the Arduino's analog input options. It does have PWM output, though, just as the Arduino and one can always wire a DAC circuit in if needed.

  • So why Teensy; why didn't I go with the more popular Arduino? There are a lot of reasons I could state, but what it comes down to are two very important ones.


  • Cost... the Teensy is a little cheaper, and having more flash for code storage at less cost, it just made sense to my wallet.


  • Possibly more important... community.

  • "What? The Arduino has a huge community!" Yes, yes it does... and when I bought my Teensy I didn't know ANY OF THEM. I did, though, know someone that had a Teensy. A community of two is much more useful than one of thousands when you know each other personally, and can just show up on the other's doorstep at any time. I'm a visual learner; five minutes of watching someone else do something is worth weeks of reading about it for me, so having someone in my own little part of the world I could compare notes with if needed played a huge part in my decision.

    The best part is I am not separated from the very large and very active Arduino community. Paul is actively developing what he calls Teensyduino, a plugin for the Arduino IDE that lets most Arduino sketches (the source code for controlling an Arduino, so named because it's based off the Processing programming language whose IDE is called a sketchbook) run with only a little modification. So I get the small form factor, faster communications if I needed it, a local fellow developer, and most of the resources of the Arduino development community for $22 ($19 if you get it without header pins). That's a cost of entry I can deal with.

    Of course, it hasn't been all happiness and sunshine. Teensyduino is still in early beta, so some sketches aren't as easy to make work as I'd like just yet. I recently ran into a small issue with serial communications. Specifically the Serial.available() function. Per the Arduino website, it should return the number of characters waiting in the buffer to be read. As I don't have an actual Arduino to test the code on I can't be sure, but the example code agrees with the description. On the Teensy (at least as of Teensyduino v0.4) it returns something else, though I'm not sure just what the number means. So I had to come up with a far less elegant solution... the conversation went something like this:

    Me:
    void setup() {
      Serial.begin(9600);
    }

    void loop() {
      if (Serial.available() > 0) {
        Serial.println(Serial.read(), DEC);
      }
    }


    Teensy: -1

    Me: That shouldn't be happening, -1 means there's no data to read if there is no data Serial.available() should be 0, and you shouldn't be reading.

    Teensy: Whatever...

    Me: Don't give me any lip, I'll reflash you, and do something else.

    Teensy: As if, you're my beotch, and you'll do what I say now.

    Me:
    int receivedByte = 0;

    void setup() {
      Serial.begin(9600);
    }

    void loop() {
      receivedByte = Serial.read();
      if (receivedByte >= 0) {
        Serial.println(char(receivedByte));
      }
    }


    Teensy: I don't have anything to show you... you need to send me something.

    Me: HA!

    Teensy: Curses, foiled again!


    Yes, that's pretty much how it went... or at least that's how it went in my head. I blame Wil Wheaton... and his iTunes.

    So that's what I've been up to. That work has even fallen over into my still not released write up on GeekTool, which will be out by the end of this week. I just keep finding other things to put in it, so it's never actually done. I guess it's time for a 'feature freeze'.