Wednesday, April 8, 2015

Python on Intel Galileo/Edison - Part 5:Temperature sensor with mraa and upm

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.

https://gist.github.com/navin-bhaskar/aeba281a7e3f94a5d9dd
 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.

https://gist.github.com/navin-bhaskar/3653acce435f6a79c728
Other parts:
part0: Getting started on Galileo/Edison
part1: GPIO output
part2: GPIO input(button)
part3: pwm
part4: adc
part5: Temperature sensor
part6: Light sensor


 

5 comments:

  1. […] What next? You can check the following tutorials on using Python to program Galileo: part0: This post part1:GPIO output part2:GPIO input(button) part3:pwm part4:adc part5:Temperature sensor […]

    ReplyDelete
  2. […] Other parts: part0: Getting started on Galileo/Edison part1:GPIO output part2:GPIO input(button) part3:pwm part4:adc part5:Temperature sensor […]

    ReplyDelete
  3. […] Other parts: part0: Getting started on Galileo/Edison part1: GPIO output part2: GPIO input(button) part3: pwm part4: adc part5: Temperature sensor […]

    ReplyDelete
  4. […] Other parts: part0: Getting started on Galileo/Edison part1: GPIO output part2: GPIO input(button) part3: pwm part4: adc part5: Temperature sensor […]

    ReplyDelete