TI E2E Community
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!).
Blink Multiple LED'sLevel: Beginner Exercises Covered:Blink 1 LEDChange Pin on Microcontroller for OutputAdd LED's to the Blink LED Program
Theory Lessons:What are Pins (on a Microcontroller)? Parts of an Energia Program-Sketch
What you will need:
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
-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.
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.
------------ 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. - Open Energia 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).
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. **
Here's an amazing reference for the hardware: Energia Hardware Exercise2.a: Continue to change Pin... Connect LED A to Pin3 Let'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.
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 .
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.
Nice post. Great for beginners.
The jumper wires you're using look really useful. Did you purchase them? Where?
Thanks in advance.
Here are the ones I reccomended in the post. www.sparkfun.com/.../9140 there are 10 in this pack and it isn't too spendy.
however, if you are looking for more and are willing to spend a little more, Mouser has the exact ones that I used a 100 pack www.mouser.com/.../920-0023-01
Hope that helps!
I've bought those from Sparkfun. They work fine, I just like the look of the ones from Schmartboard better, but for the price, I think I'll stick to the ones from Sparkfun, they work as well.
Thanks for the reply ;).
No problem, I also looked at these which have the nice finished heat shrink wrapped ends the ones from mouser have.
Sent from my iPhone,
I'll keep the links for when I need to buy some more.
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?
Thank you very much!
Sorry for being so ignorant and not reading previous post...It has its own memory so you can connect it to power supply and it will work!! Thanks anyway and once again sorry :)
No problem Boris-
I hope this helps you learn and we get to see your project!
I am porting the mechatronics course from PIC to MSP430 + energia this term and was just sitting down to rewrite the labs. This blog post saved me a bunch of work!
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!
"Start with connecting a 560K resistor "
This is 560 Ohm resistor.
The University Program blog is a part of the TI Blogs and talks about all things education. Check back every day for topics on the latest TI teaching tool packages, industry trends, research projects, and academic-relevant opinion pieces. Join the TI University Program in industry—university collaboration to provide a more comprehensive and robust education for your electrical engineering students.
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.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.