MRAA and UPM are libraries that simplify the development of applications that interface with sensors. Documentation can be found here.
libgpiod
, libiio
and libserialport
The following sections are deprecated and kept for historical reason only. You may want to jump to LibIIO now.
MRAA 2.2.0 is available in Yocto Honister with support for C/C++ and additional packages are built to support python3 and nodejs.
out/linux64/build/tmp/work/<arch>-poky-linux/mraa/1.9.0-gitAUTOINC+nnnn-r0/deploy-debs/<arch>/
for manual installation. For manual installation use:
dpkg -i node-libmraa.deb
or
dpkg -i python3-libmraa.deb
Alternatively, add these packages to edison-image.bb for automatic installation into you image.
High speed uart (HSU) works.
I2C works see example below.
Settings GPIO’s works with the non-ACPI image only.
Selecting a pinmux on vanilla linux is supposed to be done by devicetree or ACPI, which has been disabled that in mraa for Linux kernels > 4.0. Currently we have I2C, SPI and HSU selectable configurations available in the form of ACPI tables. For the non-ACPI image, I2C and HSU pinmuxes are preset in the platform code in the kernel.
UPM 2.0 is available in Yocto Honister with support for C/C++ and additional packages are built to support python3 and nodejs.
out/linux64/build/tmp/work/<arch>-poky-linux/upm/1.6.0-gitAUTOINC+cc7fec9ae0-r0/deploy-debs/<arch>/
for manual installation. For manual installation use:
dpkg -i node-upm.deb
or
dpkg -i python3-upm.deb
Alternatively, add these packages to edison-image.bb for automatic installation into you image.
The UPM documentation is very comprehensive, but does not give you a walk through on how to start. In the following we hope to provide step-by-step instructions for a sample sensor, the TSL2561, which is a simple I2C based light sensor.
modprobe -i i2c-dev
before running any of the code below. On the non-ACPI enabled image, don’t forget to run the I2C scriptIn the UPM repository you can find the following sample code:
//Modified: Abhishek Malik <abhishek.malik@intel.com>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "tsl2561.h"
#include "upm_utilities.h"
#define TSL2561_Address 0x39
int main()
{
tsl2561_context dev = tsl2561_init(6, TSL2561_Address, GAIN_0X, INTEGRATION_TIME1_101MS);
float abc = 0;
if(tsl2561_get_lux(dev, &abc) != UPM_SUCCESS){
printf("ERROR !! ERROR !! ERROR!!");
}
printf("value retrieved: %f\n", abc);
return 0;
}
We need to modify the bus to i2c-6 and the address to 0x39 for this example to work.
On Edison build using:
gcc -I /usr/include/upm/ -lupmc-tsl2561 tsl2561.c
Then run
root@edison:~# ./a.out
value retrieved: 12.000000
On Edison we need to make the tsl2561 module known to node:
npm install /usr/lib/node_modules/jsupm_tsl2561/
The example code needs similar modification as the C version.
/*
* Author: Zion Orent <zorent@ics.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
var digitalLightSensor = require('jsupm_tsl2561');
// Instantiate a digital light sensor TSL2561 on I2C
var myDigitalLightSensor = new digitalLightSensor.TSL2561(6, 57, 0, 1);
setInterval(function()
{
console.log("Light value is " + myDigitalLightSensor.getLux());
}, 1000);
// Print message when exiting
process.on('SIGINT', function()
{
console.log("Exiting...");
process.exit(0);
});
Then run:
root@edison:~# node tsl2561.js
Light value is 4712
Light value is 4715
Light value is 4661
Light value is 3546
Light value is 509
Light value is 208
Light value is 76
Light value is 118
Light value is 3919
The example code needs similar modification as the C version.
#!/usr/bin/env python
# Author: Zion Orent <zorent@ics.com>
# Copyright (c) 2015 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import time, sys, signal, atexit
from upm import pyupm_tsl2561 as upmTsl2561
def main():
# Instantiate a digital light sensor TSL2561 on I2C
myDigitalLightSensor = upmTsl2561.TSL2561(6, 57, 0, 1)
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit, including functions from myDigitalLightSensor
def exitHandler():
print("Exiting")
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
while(1):
print("Light value is " + str(myDigitalLightSensor.getLux()))
time.sleep(1)
if __name__ == '__main__':
main()
Then run:
root@edison:~# python3 tsl2561.py
Light value is 109
Light value is 61
Light value is 17165
Light value is 25085
Light value is 21554
Light value is 101
Light value is 177
Light value is 110
You need to prepare the working directory for the SDK.
After this, put the C source example along with a suitable make file.
OBJECTS =
ifdef DEBUG
OPT_FLAGS= -g -O0
else
OPT_FLAGS=-O3 -DNDEBUG -flto
endif
INCDIRS = -I=/usr/include/upm/
WARNING_FLAGS=-Wall -Wextra -Wno-sign-compare
CXXFLAGS+= $(WARNING_FLAGS) $(OPT_FLAGS) $(INCDIRS)
CFLAGS+= $(WARNING_FLAGS) $(OPT_FLAGS) $(INCDIRS)
BINARIES=tsl2561
all: $(BINARIES)
tsl2561: tsl2561.o $(OBJECTS)
$(CXX) -o $@ $^ $(CXXFLAGS) -lupmc-tsl2561
clean:
$(RM) $(BINARIES) *.o
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
%.o: %.cc
$(CXX) $(CXXFLAGS) -o $@ -c $<
and run make all
.
The copy tsl2561
to Edison and:
root@edison:~# ./tsl2561
value retrieved: 0.000000
root@edison:~# ./tsl2561
value retrieved: 14.000000
root@edison:~# ./tsl2561
value retrieved: 1523.000000
© 2018 Ferry Toth