Wednesday, March 11, 2015

Hello World, or blinking an LED

Let's get started on the basics - blinking an LED with the LaunchPad.  Along the way we will discuss some of the differences between Arduino boards and LaunchPads.  I'll be using the MSP-EXP430F5529LP (a favorite of mine with lots of capability at a great price), but will point out differences between it and some of the other LaunchPads.

First, get Energia installed if you haven't already done so.

Here is the schematic:

 
Not much too it really but let's discuss how it differs from Arduino...
  1. The pin connections on the top of the LaunchPad are male instead of female - you are going to need male-female jumpers instead of male-male jumpers to get over to a breadboard.  Note that some LaunchPads do have male on one side of the board and female on the others however which is a plus.
  2. The pin arrangements are different than Arduino.  Keep this in mind!  I like to use the nomenclature shown in the schematic although Energia allows alternate naming and I am going to call it Pin "2" here.  Note that on the board it is labelled P6.5 (uses a period instead of an underscore).  If you do want to use this nomenclature you must use an underscore, i.e. P6_5 or it won't compile. 
  3. The LaunchPads have LEDs on the boards which you can use.  In the case of the 5529 there are two which you can address with the names RED_LED and GREEN_LED.
Bottom line - get familiar with the diagrams for your LaunchPad and make sure your pin declarations are correct!  This caused me way too much consternation when I was getting started.

Note also that LaunchPads for the most part are 3.3 V devices (the MSP430FR5969 is a 1.8 V device).  It isn't going to matter in this case but 3.3 V logic frequently won't work with 5 V chips and 5V input can damage a 3.3V device.  Pay close attention to this!

I'm not going to provide beginner level details on code - there are plenty of other sites for that.  I will provide working code and a bill of materials with links to where you can get selected items.

Bill of materials:
MSP-EXP430F5529LP or other LaunchPad
Breadboard
Male-Female Jumpers
LED
330 ohm (or so) Resistor

Connections:

LED anode      MCU digital pin 2 (P6_5 in this example)
LED cathode   330 ohm resistor and then GND

Code:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
*/

 
const int LED = 2;          // note that this is the same as P6_5 on the 5529
                            // Pin 2 should work on most LaunchPads

void setup()
{                
  pinMode(LED, OUTPUT);     // initialize the digital pin as an output. 
}

void loop()
{
  digitalWrite(LED, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(LED, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}


No comments:

Post a Comment