Laboratory
Laboratory
Using libraries (UPM & MRAA)
Do not misunderstand me , UPM and MRAA are great libraries, they really make things easier, specially when you are starting and you would like to get a prototype up and running fast, instead of struggling in how to get the values from your sensors and devices.
So first let's recap. MRAA is used to communicate to the device through I2C, PWM,SPI, etc.. on top of that UPM is used so at the end you just have to instantiate an object of the class of your device or sensor. lets see how we can do that:
1. Check if the sensors are supported by MRAA
At the beginning we stated that we are going use the LCD RGB Backlight Display and the Barometric sensor, please go to http://iotdk.intel.com/docs/master/upm/modules.html and find out either using the search on the top right corner or manually browse the sensor list to see if our sensors are supported by MRAA.
So far you should have found the following info about our sensor and display:
Barometric Sensor: MPL3115A2
LCD Display: Jhd1313m2
2. Writing some code with UPM/MRAA, LCD
Let's write a program to display a string in our RGB LCD.
Go to your Edison's command-line and use nano or vim to create a file called lcd_temp.cpp and add the following code:
3. Compiling our UPM/MRAA code with a Makefile
Now lets create a Makefile with vim/nano to compile easily compile the program every time we do a change.
Quick question!, can you identify the upm libs needed to compile our program?
Our Makefile should look like this:
Now you can type make, to trigger the compilation of our program, after that type ./lcd to run the program, to stop it just press CTRL+c
If you do some changes you can recompile using make, sometimes when you do some changes and recompile, it will tell you that there are no changes, on those occassions you can do make clean and then make that will erase the tempfiles created by vim when editing as well as the executable binary.
4. Writing some code with UPM/MRAA, Temperature
Now lets read the temperature from the Barometric sensor and display it in our RGB LCD.
Go to your Edison's command-line and use nano or vim to create a file called lcd_temp.cpp and add the following code:
Our Makefile should look like this:
Now compile
Want to learn more about the Makefile system? click Here: GCC and Make Compiling, Linking and Building C/C++ Applications
Using UPM/MRAA wasn't hard ins't it?, and it speed-up things if your sensor is already supported, but if not, you can write your own code and share it with the community, later we will explore how to add our not supported sensor to UPM.
Last updated