Using UPM in Python

UPM is an open source sensor and peripheral driver repository based on libmraa APIs. LinkIt Smart 7688 development board already has a pre-installed UPM library 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 library.

UPM comes with bindings in C++, Python and Node.js. In this example you’ll learn how to use UPM in 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 GND3V3SDA (P20) and SCL (P21) on the LinkIt Smart 7688 development board.

  2. Import pyupm_adxl345 module from the UPM repository to your program. This module is used to support the the ADXL345 chipset on the Grove 3-Axis Digital Accelerometer (±16g) .

  3. Create a Python script with following content:

    import pyupm_adxl345 as adxl  
    import time  
    device = adxl.Adxl345(0)  
    while True:      
        a = device.getAcceleration()      
        print "(x,y,z)=%5.1f, %5.1f, %5.1f" % (a[0], a[1], a[2])      
  4. Execute the Python script in system console with the following command: 


You'll now have the acceleration values printed repeatedly. Try moving the sensor around to see changes in the values. For a list of other available Python modules in the UPM repository, check here. The UPM repository also comes with a handful of examples for your reference.