The temperature sensor that we are gong to use for this post is from Grove. This sensor outputs the voltage that represents the temperature hence we will need the ADC module on the Intel Galileo/Edison to interface with this peripheral.
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
import pyupm_grove
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.
Other parts:
part0:Getting started
part1:GPIO LED
part2:GPIO button
part3:PWM
part4:ADC
part5:Temperature sensor
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
import pyupm_grove
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.
Other parts:
part0:Getting started
part1:GPIO LED
part2:GPIO button
part3:PWM
part4:ADC
part5:Temperature sensor
No comments:
Post a Comment