This tutorial is to introduced that how can we access to some Grove module on linkit smart 7688 with UPM.
UPM is a high level repository for sensors that use MRAA. The UPM repository provides software drivers for a wide variety of commonly used sensors and actuators. These software drivers interact with the underlying hardware platform (or microcontroller), as well as with the attached sensors, through calls to MRAA APIs.
Programmers can access the interfaces for each sensor by including the sensor’s corresponding header file and instantiating the associated sensor class. In the typical use case, a constructor initializes the sensor based on parameters that identify the sensor, the I/O protocol used and the pin location of the sensor.
Things you need:
Linkit smart 7688 *1
Breakout for LinkIt smart 7688 *1
Grove - Digital Light Sensor *1
USB Cable *1
The connection is the same as tutorial #2. We just need to attach the LinkIt smart 7688 to the Breakout board and connect the Grove - Digital Light to the I2C Grove interface on the Breakout board.That is fine. And if you don’t have a Breakout board , you could connect the sensor’s SDA pin to P20 of 7688 and the SCL pin to P21, of course connect the VCC and GND to the right position too.
As the UPM repository provides software drivers for a wide variety of commonly used sensors and actuators , how can I know that which sensors or actuators do it supports? Here are the way to do this. Click this link: https://github.com/intel-iot-devkit/upm/tree/master/examples/python
And find your module in the example list. For example, we are going to find out the Grove - Digital Light Sensor. According to the wiki of this Grove module:
http://www.seeedstudio.com/wiki/Grove_-_Digital_Light_Sensor ,we know that this module is based on the I2C light-to-digital converter TSL2561. Then we could check the keyword “tsl2561” in the example list above :
The example in red frame should be what we want. Run the code to check it and have a view that how to access Grove - Digital Light Sensor with UPM.
In tutorial#2 we have introduced how to use Grove - Digital Light Senor with MRAA , and now we will access this sensor with BBGW. Differently with MRAA library, you are able to use getlux() method to read the sensor’s data directly when you are using UPM, which is more convenient.
And now let’s paste tsl2561.py , which we found just now, to Linkit Smart 7688. Save and run.
import time, sys, signal, atexit
import pyupm_tsl2561 as upmTsl2561
# Instantiate a digital light sensor TSL2561 on I2C
myDigitalLightSensor = upmTsl2561.TSL2561()
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
# This function lets you run code on exit, including functions from myDigitalLightSensor
# Register exit handlers
print"Light value is"+ str(myDigitalLightSensor.getLux())