Reading the temperature with mraa:
The temperature sensor is connected to the pin A1. ADC is used to get the voltage reading out of the temperature sensor. The following code prints out the temperature onto console. The formula used here is taken form example code found here.
Reading the temperature with upm:
As mentioned in one of my previous posts, upm can be used to interface with sensors. Either you can write code using mraa to drive your sensor (in the process write initializing code and supporting code in case of more complicated components) or you can leverage on the work done by good folks at Intel and use upm.
upm supports an array of sensors and peripherals for you to use. The following script does the same thing as done by the previous script but this time with upm and you can see how simple things can get with the upm. In the script below, we import the upm library using
and specify the ADC in pin that you want to use
temp = pyupm_grove.GroveTemp(1)
You can read the temperature using the “value” method.