Sunday, September 17, 2017

Running Energia on Mac OS X

Energia is a programming environment for the Texas Instruments LaunchPads, based on the Wiring and Arduino frameworks. It took a bit of effort to get it working on my Mac. I'm running OS X 10.11.6, El Capitan; hopefully these instructions will work for the more recent OS X 10.12, Sierra.

1) The most obvious thing is to go to energia.nu/guide/guide_macosx instead of the windows page.

2) After starting Energia, go to the Tools -> Board -> Board Manager menu item and choose your target board. You should see a list of boards. For instance, you can choose

Energia MSP432 boards by Energia
Boards included in this package:
MSP_EXP432P401R

Clink Install for the entry corresponding to your target board. (I believe the entry listed above is for the black MSP432 Launchpad. If you have a red board, you should probably install the "MSP432 EMT Red boards" instead -- just a guess.)

3) Now quit Energia, since we'll need to implement an annoying workaround. When I first tried compiling a program, I got a dialog box with this error:

To use the "java" command-line tool you need to install a JDK.

Some discussion about this error may be found here. After doing a lot of google searching and hitting my head against the table a lot, I came up with a somewhat annoying but not utterly dreadful workaround.

If you open up a Terminal and type which java, it will tell you: /usr/bin/java

If you type java -version, it will tell you: No Java runtime present, requesting install.

Based on this webpage, I discovered /usr/bin/java is a link to

/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

Instead, it should be a link to

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

You can't readily change the /usr/bin/java link without disabling something called System Integrity Protection (SIP), which isn't really something I wanted to do.

So, here's my hack:

3A) In the Terminal, type

sudo ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java” /usr/local/bin/java

That puts a link in /usr/local/bin, which SIP doesn't complain about.

3B) We need to get into the "package" of Energia.app. (I'm assuming you put it in your main Applications folder.) In the Terminal, type

cd /Applications/Energia.app/Contents/MacOS

In that folder, you'll find a file called Energia, which starts up the program. Let's rename it something else that we can call from our own Energia script. Type:

mv Energia Energia_main

3C) Then create a text file called Energia that contains these three lines:

#!/bin/bash
export PATH=/usr/local/bin:$PATH
./Applications/Energia.app/Contents/MacOS/Energia_main

Now, when you double-click on the Energia icon, it will change your path to put /usr/local/bin before /usr/bin so Energia will find the correct java command line program. This path change is restricted to this running of Energia, so hopefully this won't mess up any other program that for whatever reason really should have /usr/bin before /usr/local/bin in the path.

Usual caveats apply; your mileage may vary. Use the above information at your own risk (although I don't think I'm suggesting that you do anything particularly risky.)

2 comments: