Blinking Multiple LED's with MSP430 Energia

Now that you know how to blink one LED, what's the next step? Blinking multiple LED's!

This post is a follow up from the previous Post- Blinking one LED found here. (There is a more in depth presentation about detailed set up if you weren't able to do the exercise before, or you can comment and ask questions!).

You really don't need to get a whole lot of extra from the previous post.

Concepts Used: How to Wire Up a Breadboard How to Wire a Breadboard with an LED Using Energia Examples

Concepts to Learn:Wiring more than 1 LED microcontroller pin out changing and modifying a program

Getting Started:

-verify you LaunchPad is working. Plug your LaunchPad into the computer.

**If your LaunchPad is brand new, the LED should blink red and green back and forth. **If your LaunchPad is from the previous post, then the indicator LED will be lit up (LED2).

Wire up your breadboard.Connect 1 of the jumper wires from the side of the breadboard you are using - (blue) to the GND terminal on the LaunchPad. This is providing power the the breadboard.

In the previous post you wired up 1 LED.

Start with connecting a 560K resistor from the negative column to the row you will be connecting the negative of the LED. (suggest from the Blue (-) rail one end of the resistor and connect the other end of the resistor to row 3 column c). Hold up the LED, there is a long leg and a short leg.

borrowed from A Modular Life

orient the LED so the short leg is going into row 3 and the long leg is going to row 2- ( suggest plugging into column e). Then you will connect the jumper wire. This will be your positive. Connect the jumper wire from the positive of the LED (remember we plugged it into row 2, so you will want to plug the jumper into one of the 4 remaining spots on row 2).

Normally you would connect the jumper wire to the pin on the LaunchPad, but in this case we're going to leave that last wiring until later. However, we will use this opportunity to test the LED.

Take the jumper (with the female end) and touch it to the VCC pin of the LaunchPad. You should see the LED light up. Keep it disconnected and move to the next LED.

**For help here, look at this tutorial on how to use a breadboard and wire 1 LED by ScienceOnline here

Wire up the rest of the LED's, testing each one of them as you go along (touching the end of the positive jumper to VCC) and verifying that the LED does work. This is how I wired mine:

LED A

LED B

LED C

LED D

LED E

LED F

LED G

+ or Cathode (longer lead of LED)

e2

e6

e10

e14

e18

e22

e26

- or Anode (shorter LED Lead)

e3

e7

e11

e15

e19

e23

e27

560K Resistor side 1

c3

c7

c11

c16

c19

c23

c27

560 K Resistor side 2

-3

-7

-11

-16

-19

-23

-27

Jumper Wire breadboard side)

a2

a6

a10

a14

a18

a22

a26

Jumper Wire LaunchPad Side

?

?

?

?

?

?

?

------------

Exercise1: Blink 1 LED If you did the previous post, you may skip this section Now that you have the hardware all wired up, you're ready to start to connect the LaunchPad to the wires. The first is to open up the Blink LED Example and load and execute the program. If you have it open from the previous post, feel free to use that, but the first few steps may repeat what you have already done.

Load the Blink LED Program. This turns on the LED for 1 second then turns it off for one second. - File--> Examples--> Basic--> Blink LED - hit the LOAD Button -Let the load complete. -See the LED on the LaunchPad blink for 1 second then off for 1 second.

Exercise2: Change the pin for the LED:-now go back to Energia and notice the following lines of code.

This is to blink only 1 LED. If you notice it, pin 14 is what is called out. Go through each line of the code and change it to pin 3.

When you are done, hit LOAD. -See the LED Turn off. Now that the LED has turned off, this means that your program has loaded. Instead of turning Pin 14 on and off... it is now turning on and off Pin 3. But, you don't have anything connected on Pin 3.

So, Let's wire something to Pin 3, but first, we need to know what are Pins.

THEORY: What are Pins?When you look at your Energia Sketch, you see that it declares a "Pin" The Pin that the sketch is referring to is the "Pin" on the Microcontroller. The microcontroller on the LaunchPad is the MSP430G2553, which has 20 Pins. It's useful to learn what your microcontroller's "Pin out" is, which you can usually find in the microcontroller's datasheet (page 3 for the top figure).

The one thing you need to pay attention to is where the numbers are on pin-out. These numbers correspond to each of the device's Pin's. This is what Energia is calling out when it says, Pin 14.

Luckily the LaunchPad also has 20 pins and it aligns nicely with the pin-out on the MSP430G2553 device. This means that when we refer to Pin 3 on the Microcontroller, you can easily count the header pins to find Pin 3.

The LaunchPad's header pins have a "silkscreen" that labels each of the pins to help make it easier for users. You can use the silk screen to help you remember what each pin does.

**You should already have VCC and GND connected to jumper wires to the + bus (red) of the breadboard and the - (blue) bus. This means you have Pins 1 and Pins 20 tied to + and -.

Here's a reference:

This will be particularly important when: 1. want to take the microcontroller off of the LaunchPad and place it on the breadboard 2. have a microcontroller that may have less pins (such as the MSP430G2231 with 14 pins) than what the LaunchPad has.

**For now it's important for you to know that the software (Energia) is talking to the microcontroller, but the physical part (the wires and the breadboard) are talking to the LaunchPad. If you want to move a pin, you will need to make sure to make a change in both, the microcontroller and the wires. **

Exercise2.a: Continue to change Pin... Connect LED A to Pin3Let's get back to our breadboard. So, we have loaded already a program is making the LED blink for 1 second on and 1 second off for Pin 3. On the MSP430G2553 Pin 3 is the third pin on the left hand side of the launchpad labeled with a silk screen P1.1.(You can either count the pins starting from Pin 1 to get to Pin 3, or you can use the silk screen to find P1.1. ) Take the jumper from LED A that isn't connected to anything (the other 6 should still be disconnected since only the + and - buses are connected) and connect it to Pin 3.

The LED A should begin to flash.

Now, we are ready to make the rest of the LED's blink. The hardware (in this case the breadboard) is already wired up. All we need to do is get the program modified and ready to work and then connect the hardware. So, getting working on the program first...

------

To be able to modify the microcontroller to have more LED's we need to change the program or "sketch" to have the extra pins. Let's first understand the parts of a sketch.

THEORY: Parts of a "Sketch"(Energia Program) Go back to the Energia Window and look at how the program is put together. In general you will declare variables- although this program doesn't have any yet. Then you need to initialize the pins that are getting used (tell the program what microcontroller pins it should be paying attention to). Then it runs the program.

So, looking at the Blink LED Program (above) we can read it to be: There are no variables. Set up pin 3 (connected to LED A) to be an output. When the program runs, it will do a digitalWrite of pin 3 to be HIGH or "on" delay for 1000 mili seconds. (keep it on high for 1 second). Then do a digitalWrite of the same pin (pin3) to be LOW or "off" and delay for 1000 milliseconds. then it repeats (the loop).

and modify the program to basically add another LED. we'll need to Set Up that pin. Then add it to the program.

Exercise: Add LED's to the Blink LED Program.

modify your program to look like this: hook up LED B cable to Pin4. Now you should have LED A blink for one second, then turn off. Then LED B blinks for one second then turns off.

continue to add the rest of the pins.

If you wanted to only to have each LED blink for 1 second in sequence you can use this method. Make sure to connect your LED's to the board to the corresponding pins.

Example Code is attached to the end of this post. You can either open that code and copy and paste it over your existing program or you can choose to type it out .

LED A

LED B

LED C

LED D

LED E

LED F

LED G

+ or Cathode (longer lead of LED)

e2

e6

e10

e14

e18

e22

e26

- or Anode (shorter LED Lead)

e3

e7

e11

e15

e19

e23

e27

560K Resistor side 1

c3

c7

c11

c16

c19

c23

c27

560 K Resistor side 2

-3

-7

-11

-16

-19

-23

-27

Jumper Wire breadboard side)

a2

a6

a10

a14

a18

a22

a26

Jumper Wire LaunchPad Side

3

4

5

6

7

8

9

Once you have the new program loaded and the LED's wired to the correct pins you should have all seven LED's blinking one at a time and repeating.

Congratulations, you've blinked all seven LED's... You can stop here and play with the delay times, change the order of the blocks of code (if you put the code in different orders, you'll get different routines)

Now that you can blink them in order, what can you do with it?Here's a quick one that spells out a team name for Football Sunday :-) (may be hard to see in the beginning).

otherwise, try modifying the code to make the LED's blink out of order!

Preview: the next post will cover the coding that will cover making more complicated routines.

Hello. I am a complete beginner and I have a question...Does this MSP430 Energia only when it is connected via usb to computer or it has its own memory and can work, when it is just connected to power supply?

HI Martin, I'm glad that the post help. Thank you so much for letting me know if helps. If you need any help, let me know! I'd love to see what you are doing in your Mechatronics course sometime, I hope you share!

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.