Teensy 2++

Teensy 2++ a lot of micro controller for not much dosh!

As some of you know I may be a bit of a geek, one of the tools I use is the Teensy, it is very smiler in use and specification to an Arduino while not being a pure clone unlike the Diavolino.

My preferred member of the family is the Teensy 2++, I am yet to try using the Teensy 3 (mainly because I have yet to out grow the Teensy 2++).

While the Teensy is not pin compatible with the Arduino, it does fit nicely on solder less breadboard.

The general highlights of the Teensy:

  1. Can emulate several USB devices without the need of expensive additional integrated circuitry.
  2. Extensive, liberally licensed code examples at pjrc.com that provide access to USB device classes.
  3. The board is very affordable
  4. The board is very small
  5. Loading code is easy

The main reason I started using a Teensy was because it uses a microcontroller that can do USB natively without the use of additional circuitry like the Arduino. The Arduino relies heavily upon FTDIs popular FT232RL chip that converts TTL to serial emulated USB in hardware. The FT232RL is an insanely expensive integrated circuit typically running around $3.50.

RGB LEDs with 3 x 220 Ω resistors

RGB LEDs with 3 x 220 Ω resistors

One of the first fun (and quite easy to do) things to do with a new platform is make lights flash.

LED Pinout

RGB LED Pinout for the Clear package LEDs.

I have a number of RGB LEDs both in Clear and diffused packages.

  • Clear: you can see all inner features distinctly. When lit, you can see the glow at the internal junction.
  • Diffuse: the plastic is somewhat cloudy, and the whole surface glows.

The first code I have flashed onto the Teensy is this:

int redPin =  14;
int greenPin =  15;
int bluePin =  16;

// The setup() method runs once, when the sketch starts

void setup()   {
  // initialize the digital pins as an outputs
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}

// the loop() method runs over and over again,

void loop()
{
  digitalWrite(redPin, HIGH);
  delay(500);
  digitalWrite(greenPin, HIGH);
  delay(500);
  digitalWrite(bluePin, HIGH);
  delay(500);
  digitalWrite(redPin, LOW);
  delay(500);
  digitalWrite(greenPin, LOW);
  delay(500);
  digitalWrite(bluePin, LOW);
  delay(500);
}
Additive Colour

Additive Colour

While this code does flash the LED a bunch of colours, its not very pretty… must try harder… as you can see if you follow the additive colour circle round, we are not just seeing three colours.

The graph below approximates all the colours that the LED should be able to show (the areas outside the Black Triangle are approximated as the colour space of the screen you are using can not faithfully represent them).

Our favourite encyclopedia has lots to say on the RGB colour model, so if you want to read have a look.

gamut

The Website I found the above Triangle also has this diagram on it:

ledvsconesThe top graph is the common output curve of LEDs, and the bottom is the response by the human eye (the three different cones).

int RedPin =  14;
int GreenPin =  15;
int BluePin =  16;

int RedIntensity = 0;
int GreenIntensity = 0;
int BlueIntensity = 0;

void setup()
{
  pinMode(RedPin, OUTPUT);
  pinMode(GreenPin, OUTPUT);
  pinMode(BluePin, OUTPUT);
}


void loop()
{
  while (RedIntensity < 255)
  {
    while (GreenIntensity < 255)
    {
      while (BlueIntensity < 255)
      {
        analogWrite(RedPin, RedIntensity);
        analogWrite(GreenPin, GreenIntensity);
        analogWrite(BluePin, BlueIntensity);  
        BlueIntensity++;
     }
     BlueIntensity = 0;
     GreenIntensity++;
   }
   GreenIntensity = 0;
   RedIntensity++;
 }
RedIntensity = 0;
}

While the above code does cover all 16581375 colours its also not very pretty.

At some point soon I will be trying to use analogue inputs to make the colours controllable (may even aim for RS485 control).