MediaTek LinkIt™ Smart 7688 Developer's Guide
© 2015, 2016 MediaTek Inc.
Page 66
This document contains information that is proprietary to MediaTek Inc.
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
11)
Now you’re ready to run this Node.js application. In the
app
directory, type following
command to run
app.js
:
node app
The W-Fi LED on LinkIt Smart 7688 should blink every second.
Press
<Ctrl> C
to terminate the program..
5.2.
How to use UPM to access sensors and peripherals
is an open source sensor and peripheral driver repository based on libmraa APIs. Among the
popular sensor drivers such as I2C accelerometers and many others are available from this
repository.
LinkIt Smart 7688 system image is pre-installed with UPM and you can start programming on
existing sensors immediately – but if the default implementation is not available, you can use
opkg package manager to update the UPM library.
UPM is similar to libmraa in the way that it comes with bindings in C++, Python and Node.js. Let’s
get started with an example where you’ll learn how to use UPM and Python to receive values from
an I2C accelerometer – a Grove 3-Axis Digital Accelerometer (±16g).
1)
Connect the Accelerometer to your board. If you have the breakout board, you can attach
it to the I2C grove interface. If not, you can also connect the pins from the accelerometer
to the corresponding pins GND, 3V3, SDA (P20) and SCL (P21) on LinkIt Smart 7688 board.
2)
Import
pyupm_adxl345
module from the UPM repository in your program, you’ll do this in
the next step. This module is used because the Grove 3-Axis Digital Accelerometer (±16g)
uses the ADXL345 chipset.
3)
Create a Python script
adxl.py
with following content:
import pyupm_adxl345 as adxl
import time
device = adxl.Adxl345(0)
while True:
device.update()
a = device.getAcceleration()
print "(x,y,z)=%5.1f, %5.1f, %5.1f" % (a[0], a[1], a[2])
time.sleep(0.3)
4)
Execute the Python script in system console by typing the following command:
# python adxl.py