This video demonstrates the capabilities of libmraa.
Hi, I'm Daniel Holmlund. In this video, we're going to walk through some examples that will demonstrate the capabilities of libmraa.
The MRAA library must be linked into your software. Typically, you must first initialize MRAA using the mraa_init function. Let's start with a simple example of a digital input device such as a push button. When the switch is depressed, a high voltage level is placed on the pin, otherwise a low voltage level is present. Only two states can be represented. For example, in a 5-volt system, low might refer to 0 volts and high might refer to 5 volts. Typically, however, high is represented in the computer as a 1 and low is represented in the computer as a 0.
Digital devices can be set up on an input or an output. For use as an input device, you would use MRAA to read the digital pin and return a value indicating whether the voltage was low or high. Conversely, writing to a digital pin causes the digital pin to be driven low or high. MRAA provides an API for reading and writing the states of a digital pin. In addition, it's possible to attach a user-supplied interrupt handler to a digital pin that will fire when the pin is changed.
An analog device is one that provides data in the form of a changing voltage level, from 0 to whatever the maximum voltage support is. This data is typically referred to as the analog reference voltage, or AREF. For example, if an analog pressure sensor provides data starting at 0-- indicating there is no pressure, it can then increase as the pressure goes up to its maximum level. This sensor's voltages are then interpreted and converted to a digital number by a device called an analog-to-digital converter, or ADC. The software controlling the sensor then reads this number generated by the ADC.
This example demonstrates how the sensor works by connecting it to pin A0, or Analog 0. The following code example shows how to initialize MRAA and the A0 pin, read in print its value, and then release the pin at the end of the program.
Here is the digital output example. In fact, it's the famous LED blinking example using libmraa. As you can imagine, the digital output is fairly straightforward. The example causes the digital pin to be driven high and then low, with a 1 second sleep interval between.
MRAA simplifies the process of accessing and manipulating I/O capabilities on IoT devices and gateways. MRAA is a powerful library that provides a consistent approach to using analog, digital, PWM, I squared C, UART, and SPI devices. In addition, it adds a layer of abstraction so that your code can be ported to different IoT devices.
Thanks for watching. To learn more, check out the links provided. Don't forget to like this video and subscribe to the Intel Software YouTube channel.