Home TI-Nspire Scripting HQ STEM HQ Getting Started with TI LaunchPads TI LaunchPad Lesson 1


Lesson 1: My first LaunchPad sketch - Blink an LED

Energia Reference page


Connecting Computer and LaunchPad

So, you have your LaunchPad (or your TI Innovator™ Hub), and you have downloaded and installed Energia and the required drivers for your system. Open Energia and connect the LaunchPad via USB to your computer (I will be showing screenshots from my MacBook, but the main features should be readily transferable across platforms.)

Go to the Tools menu and check under "Board" and "Serial Port". You should see something similar to the following:

You will need to ensure that you select the correct board (there is only one MSP432 but there are several MSP430 varieties, so make sure that you have the right one!). Then check that your serial port is active - if not, try unplugging and replugging the board, or quitting and restarting the software. Occasionally, I have needed to reboot my computer with the device plugged in. Normally, though, it should work automatically - there is good trouble-shooting support at the Energia site.


Hacking the Hub™

This activity requires no adjustment to work with the Hub - simply connect using the micro-USB cable to the Hub power port, use Energia as instructed and make those LEDs flash!

Remember: You can always reflash your Innovator Hub to return it to its original state, using the tools that TI has made available (just follow the Resources tab, and then "Keep your Innovator up to date"). So it is possible to explore coding the Hub in new ways!



TI Innovator™ Hub (with MSP432 LaunchPad)

My First Sketch

From the File menu, select 'New' and you should see something similar to the images above. The sketch is named with the date (you should rename it to something meaningful when you save it!), and consists of two parts: 'setup' and 'loop'. As the names imply, the first section is used to initialise variables and other housekeeping, the loop is where things happen - over and over! (The "void" means that the software does not expect any result returned from these functions, unlike most functions which return a result).

Before we try creating our own sketches, it is highly useful to learn from what others have done before us! Go to the File menu once again, and choose 'Examples'. You should see many sub-menu options, with the first ten being excellent tutorials. Begin with Basics, and choose 'Blink'.

As noted in the text, this is the essential starting sketch - doesn't get much simpler. Most of the text you will see (everything in green) is just comment to explain what is going on). In fact, if you copy and paste the non-green text, what you get is very simple:

#define LED RED_LED

void setup()
pinMode(LED, OUTPUT);

void loop()
digitalWrite(LED, HIGH);
digitalWrite(LED, LOW);

You can copy the text from here and paste it into your 'new' sketch, or just use the example sketch provided by the software.

Look closely at each line of the sketch above. It begins by defining a variable (called 'LED') which represents a special term - 'RED_LED'. The code is case-sensitive, so be careful - well worth a browse of the Energia Reference page. Also make sure you end each command line with a semi-colon (';') - my most common cause of errors!

In the setup, we tell the board that the red led will be used as an output. Then we write to that component - 'HIGH' will switch it on, 'LOW' will turn it off, and in between there will be a 1 second delay (yes - the delay is measured in milliseconds).

Compile Your Sketch (check for errors)

It all looks OK, so first we check our code by 'compiling' it. Click on the check mark in the red circle at the top left of the window and watch the bottom of the window - lots of text flows past as it verbosely reports everything that is happening, and then (hopefully) it will report 'Done compiling'. If not, then go back and check that there is a semi-colon where required, or have a look at the error message in the report.

Upload Your Sketch (send to the board)

If all is correct, then you can proceed to 'upload' the sketch to the board using the 'upload' button (round red right-pointing arrow next to the Compile button at the top left of the window.) Uploading may take a little while, even for a short sketch like this (mine takes around 30 seconds). Once you finish and get the "Success" message, you should see the red LED flashing on and off on your board.

Congratulations! You have run your first sketch!


Some Challenges

Now go back and change some of the values to see what happens. The MSP432 has RED_LED, GREEN_LED and BLUE_LED (the MSP430 has only RED and GREEN, and the CC3200 has red, green and yellow!). Try each of these and try different delay settings.

MSP430: Try having it flash red, then green!

MSP432: Try having it flash red, then green, then blue!

Now go back and try a few more examples from the examples menu! Much fun awaits!


Back to Top


Home TI-Nspire Scripting HQ STEM HQ Getting Started with TI LaunchPads TI LaunchPad Lesson 1