We need:
- Arduino with firmata library (Firmata - Arduino)
- Raspberry Pi with python and firmata package (Firmata - Raspberry Pi)
- Temperature sensor LM35 (specification: http://www.ti.com.cn/cn/lit/ds/symlink/lm35.pdf)
Sensor LM35:
Connections schema:
Photo from my LM35 connections:
Example python app lm35_test.py:
from pyfirmata import ArduinoMega
from pyfirmata.util import Iterator
import time
board = ArduinoMega('/dev/ttyUSB0') # connect to arduino usb port
iterator = Iterator(board) # start reading analog input
iterator.start()
pinTemp = board.get_pin('a:0:i') # set valid in analog pin
while True:
voltage = pinTemp.read() # read voltage input
if voltage is not None: # first read after startup is somtimes None
temp = 5.0*100*voltage # convert voltage to temperature
print "{0} Celsius".format(temp)
time.sleep(1) # 1 second waiting
Run python environment (see Firmata - Raspberry Pi (part 2)), for example:
# cd robot/python_firmata_test/and run app:
# source bin/activate
# python2.7 lm35_test.pyScreenshoot form app:
LM35 is theoretically appropriately calibrated but in my opinion, given the temperature is overestimated by about 2-4 degrees Celsius. I had a reference (room thermometer;) ) thermometer.
links:
http://raspberrypi-aa.github.io/session3/firmata.html
http://www.ladyada.net/learn/sensors/temp36.html
http://www.ti.com.cn/cn/lit/ds/symlink/lm35.pdf
No comments:
Post a Comment
Note: only a member of this blog may post a comment.