RB Peripherals programming using UPM
LibUPM:
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](https://github.com/intel-iot-devkit/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.
We endorse additions that implement the generic C and C++ interfaces provided with the libraries. Multiple sensor and actuator types have been defined, for instance:
Light controller
Light sensor
Temperature sensor
Humidity sensor
Pressure sensor
Gas sensor
Analog to digital converter
Simple diagram below depicts the use of Lib-UPM to interface various sensor modules.

The developer community is welcome to submit feedback on existing categories or suggest new ones. http://ruggedboard.wixsite.com/rugged-board/forum.
1. Temperature and Humidity sensor (aht25) Testing with upm library
Description
To test the Temperature and Humidity sensor on i.mx6ul-rugged board.
Required Hardware
Sensor Tag
i.mx6ul-rugged board
USB cable
Step-by-step guide
Connect the sensor tag on M1 connector of the Rugged board.
Boot the board with SD card/NAND.
Copy the below file to mnt directory of rugged board through tftp protocol.
vi aht25_sensor.py
from __future__ import print_function
import time
from datetime import datetime
from upm import pyupm_ahtxx as sensorObj
# Global variables for temperature and humidity
globalTemperature = 0.0
globalHumidity = 0.0
def readTemperatureAndHumidity():
global globalTemperature, globalHumidity
# Initialize the sensor
sensor = sensorObj.AHT25(0, 0x38)
# Send command to measure temperature and humidity
sensor.sampleData()
globalTemperature = sensor.getTemperature()
globalHumidity = sensor.getHumidity()
# Get the current time
currentTime = datetime.now()
timeString = currentTime.strftime("%Y-%m-%d %H:%M:%S")
# Print the data to the console
print(f"Time: {timeString}, Temperature: {globalTemperature:.2f}°C, Humidity: {globalHumidity:.2f}%RH")
def main():
while True:
readTemperatureAndHumidity()
# Add a 5-second delay
time.sleep(5)
if __name__ == '__main__':
main()
Run the above code with below command in rugged board.
$ python3 aht25_sensor.py
Expected Output
root@ruggedboard-imx6ul:home#python3 aht25_sensor.py
Time: 2024-06-06 07:25:25, Temperature: 28.91�°C, Humidity: 61.94%RH
Time: 2024-06-06 07:25:30, Temperature: 28.93�°C, Humidity: 61.82%RH
Time: 2024-06-06 07:25:35, Temperature: 28.94�°C, Humidity: 61.88%RH
Time: 2024-06-06 07:25:41, Temperature: 29.36�°C, Humidity: 64.39%RH
Time: 2024-06-06 07:25:46, Temperature: 30.59�°C, Humidity: 66.07%RH
Time: 2024-06-06 07:25:51, Temperature: 30.71�°C, Humidity: 65.36%RH
Time: 2024-06-06 07:25:56, Temperature: 31.81�°C, Humidity: 69.97%RH
Time: 2024-06-06 07:26:01, Temperature: 31.56�°C, Humidity: 67.55%RH
Time: 2024-06-06 07:26:06, Temperature: 31.02�°C, Humidity: 65.18%RH
Time: 2024-06-06 07:26:12, Temperature: 30.80�°C, Humidity: 65.61%RH
Time: 2024-06-06 07:26:17, Temperature: 30.55�°C, Humidity: 64.91%RH
Time: 2024-06-06 07:26:22, Temperature: 30.47�°C, Humidity: 64.37%RH
Time: 2024-06-06 07:26:27, Temperature: 30.23�°C, Humidity: 63.33%RH
Time: 2024-06-06 07:27:22, Temperature: 28.86�°C, Humidity: 61.58%RH
^C
root@ruggedboard-imx6ul:home#
Last updated
Was this helpful?