Adding a new Library to Energia IDE and using it

Let’s see how to add a library for MPU6050 (Gyroscope + Accelerometer + Temperature) module.

Here, we will be using Korneliusz Jarzebski’s MPU6050 library from GitHub. This library is for Arduino but works for Energia as well.

Download this library from here.

Download and extract the library and add its folder in the libraries folder of Energia IDE.

Example: See the image given below. The added library is highlighted. The library folder in Energia already consists of many libraries like MQTTClient, OneWire, etc. Hence, their folders are present from the time of download of the Energia IDE.

 

Adding Library the Energia IDE MSP430

Once this is done, open the Energia IDE. We can find the examples from the added library in the Examples tab under Examples from Custom Libraries as shown below.

Note: If you had the Energia IDE open while adding any library, you will need to close the IDE and open it again for it to appear in the Examples tab.

 

Library Example TI launchpad Energia IDE MSP430

 

We can select any one of the example sketches from the added library. For example, we can select the "MPU6050_accel_pitch_roll" sketch and directly upload it to our board just like we do for built-in examples.

 It is also possible to use the functions defined in this library by simply including the header file for this library in the application sketch that we create.

 

Header File TI launchpad Energia IDE MSP430

Just like we include standard libraries like stdio.h, string.h, etc.; include the MPU6050.h in your application sketch.

Once this is done, we can use any of the functions that are declared in the MPU6050.h file (defined in the MPU6050.cpp file) in our application sketch.

This process can be done for any custom library that we want to add and use.


Components Used

TI Launchpad MSP-EXP430G2
TI Launchpad MSP-EXP430G2
1
Ad