總網頁瀏覽量

2014年4月16日 星期三

樹莓派溫度感測 = Raspberry Pi + MotoPiduino + LM35 + S4A IO Board

利用 MotoPiduino的 ADC(Analog to Digital) 和 I2C 功能特點來製作一個溫度感測裝置.

一. 使用材料:
       1. Raspberry Pi
       2. MotoPiduino
       3. LM35 temperature Sensor
       4. S4A Sensor Board (option)

二. 接線:
      1. LM35 接在 A0 (Analog 0位置)

三. 接線方式如圖:







四. I2C Library 軟體下載點:
1. 下載 ADS1015 (I2C) Library : https://github.com/m3m0ry/Adafruit-Raspberry-Pi-Python-Code
2. 編寫Python LM35 程式 motopiduino_lm35.py 如下(請該檔案建立在adafruit_ADS1x15目錄下)
 
#!/usr/bin/python
import time, signal, sys
from Adafruit_ADS1x15 import ADS1x15

def signal_handler(signal, frame):
        print 'You pressed Ctrl+C!'
        sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
#print 'Press Ctrl+C to exit'

ADS1015 = 0x00  # 12-bit ADC

# Select the gain
gain = 6144    # +/- 6.144V
#gain = 4096  # +/- 4.096V

# Select the sample rate
sps = 250  # 250 samples per second

# Initialise the ADC using the default mode (use default I2C address)
# Set this to ADS1015 depending on the ADC you are using!
adc = ADS1x15(ic=ADS1015)

while(True):
     # Read channel 0 in single-ended mode using the settings above
     volts = adc.readADCSingleEnded(0, gain, sps)
     # 10mv per degree
     lm35_c = ((volts/ 10.0)-1.5)
     # To read channel 3 in single-ended mode, +/- 1.024V, 860 sps use:
     # volts = adc.readADCSingleEnded(3, 1024, 860)

     print "%.6f" % (lm35_c)
     time.sleep(1);


五. 執行:
 $ sudo python motopiduino_lm35.py



Informatiom:  http://motoduino.com



沒有留言:

張貼留言