Your very own IoT: Energia dev environment -

Your very own IoT: Energia dev environment


Welcome back! In my last post, we discussed the convenient, versatile development board known as the SimpleLink Wi-Fi CC3200 LaunchPad and focused mainly on the hardware aspects of the board. In this post, we will learn how to prepare the board for programming, take a look at the development environment called Energia, review its benefits and best practices, and (finally!) write (and run!) our very first firmware application.

If you haven’t read the first installment in this series, I recommend you do it now. I’ll wait…

If you are not in the mood — I know, you will do it later, I trust you — you can download the latest version of Energia here. (You will need it if you wish to follow along.) Another thing you need is Java runtime environment, it can be downloaded here.

As you will notice fairly quickly, Energia is a development environment that requires no complicated switches, flags, or options that might become a pitfall especially if you are fairly recent to the trade. Mostly, it streamlines your work, making most actions just a matter of writing your logic and clicking a button to both compile and upload to the platform. As part of this strategy, most of your solutions will consist of creating a single source file, so returning to previous work after period of absence will be as simple as a one-sweep review.

Another huge benefit is the built-in libraries that come with Energia; we will review some of these in later posts. This collection of libraries will make your programming experience more pleasant than you can imagine! In fact, because of these libraries, most complicated tasks (like talking to a peripheral over I2C or UART) can be achieved with two to three lines of code.

There are several best practices you can follow to enhance your experience further:

  1. Do not be shy. If you feel that your project is complicated enough to justify it, add a second file (or third, or as many as you feel comfortable with)! Clear representation is as important in Energia as it is in any other IDE.
  2. On the same subject, header files are less explicitly presented when first starting with Energia, but they can be used just like in any other IDE. Adding and including .h files will do the job.
  3. Energia comes with a large variety of libraries that make your life easy, but they only help if you take your time to get familiar with them. Sometimes you might find yourself implementing a mechanism that already exists.
  4. Although it looks different, Energia uses a good old C++ compiler, so (almost) anything that works in normal C++ should work here.
  5. Remember the limitations of your hardware platform. Code space is precious, so if you find yourself writing elaborate mechanisms and drifting to over-complicating your project, it might be wise to stop, review, and simplify. It is hard to describe the anguish of finishing a beautiful piece of code only to see your world shatter when a compiler says your program will not fit on the device.

Before we begin, you will need to install the appropriate drivers to allow your LaunchPad to be properly recognized and enumerated. Like most modern development boards, LaunchPad is equipped with an FTDI chip that emulates serial and JTAG protocols over USB; this will be our way to communicate with and program the LaunchPad. (If you are on a Mac, the appropriate driver can be downloaded here.)

After downloading, you will need to unpack the ZIP file, run the resulting PKG file, and restart your Mac.

At this stage, we are safe to connect the LaunchPad to the computer — it should be recognized automatically. If you have any problems or doubts, it is possible to verify proper enumeration in several ways:

  1. Check the output of “sudo dmesg” command — it should look something like:

FTDIUSBSerialDriver:       0 451c32a start – ok

  1. Check the list of /dev/cu.usbserial-* devices; a new one should appear in the list once you connect the LaunchPad. (In my case, it was conveniently named /dev/cu.usbserial-cc3101B , but it might differ slightly for you.)

Next, we will prepare the board for programming. 

Next page >

To prepare the board for programming, there is a simple step we need to complete:While holding the LaunchPad such that USB connector is facing upwards,look at the row of jumpers in the middle section. Find the jumperlabeled J8 ; it should be on the far left of the board. Attach a wire to the upper leg labeled TCK . Now locate a jumper labeled J15 in a section labeled SOP on the far right of the board, and attach the other end of the wire to its lower leg, which is labeled 2 . In other words J8 –>SOP2 .

This is how the connection should look:

Lastly, a few things to note: If you are familiar with Arduino IDE,you will recognize an almost exact replica but in red instead ofaquamarine. Also, I will be doing all the work on my Mac, so thelocation of the menu might differ slightly for you if you work on adifferent platform, but the options should be consistent.

Let’s start the environment now.

Before we forget (as I often do), the first thing we need to do isselect the correct board for which we will be doing the compilation.Let’s go to Tools->Board and select LaunchPad w/ cc3200 (80MHz).

Here is the menu option we need to select:

Next, we select the proper port for the connection. Let’s go to Tools->Serial Port and select /dev/cu.usbserial-xxxxx . (NOTE: Do not confuse this with /dev/tty.xxxxxx ).

Here is the proper selection for serial port:

We can now test the setup. Let’s upload one of the simple examplesfrom those included with the Energia IDE. The programs in Energia arecalled “sketches,” so let’s look at a pre-loaded examples sketch calledFade. Click File->Examples->1.Basics->Fade.

Here is the correct selection:

Lastly, press the Upload button — the circularbutton with arrow pointing right. This will cause your solution to becompiled and uploaded to the LaunchPad.

If all went well, you will witness the glorious sight of a small LEDlight fading in and out repeatedly on the board. (If not, this is a goodtime to check your cable connection and the selection of the board andthe serial port.)

The last feature we will cover is the serial monitor that comesbuilt-in with the Energia environment. It is a very useful tool thatcreates an immediate console-style communication channel with the boardas long as the USB cable remains connected. To demonstrate, we will useanother pre-loaded example sketch called ASCIITable. Click File->Examples->4. Communication->ASCIITable.

Now, upload the example the same way we did with the previous one.

This example utilizes the serial communication channel to print out an ASCII table to the serial port.

To see the result, look for a small button with an icon of amagnifying glass in the upper right-hand corner of the window; it shouldshow you the printout of your program as it executes on the LaunchPad.If you wish to repeat the execution, simply press the reset button onthe LaunchPad to restart the MCU.

This is the best way to quickly debug small issues when you do yourdevelopment: Open the serial channel and print out whatever values ormessages you like. Since all the communication is done via the FTDI USBchannel, you do not actually waste any precious pins on your board.

That is it for today! We have learned how to use the Energia IDE andtried uploading two different programs to the board. We also touched asimple debugging technique by utilizing serial monitor functionality.

Next time, we will look at some of the standard Energia libraries, dosome sensor readings, and finally talk a little bit about thepossibilities of using CC3200 WiFi capabilities.

Stay tuned!

1 thought on “Your very own IoT: Energia dev environment

  1. “Looking forward for the CC3200 examples as the WI-Fi profiles are a little confusing.nBTW, there is a pretty awesome Energia community at 43oh:n”

    Log in to Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.