總網頁瀏覽量

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



2014年3月15日 星期六

新開發 Arduino 感測器(Terminal)介紹

最近開發了一些Arduino感測器及周邊套件可以直接接到 Arduino S4A IO Board / S4A Sensor Board:






1. 按鈕開關:  (數位訊號)





2. 紅色 LED 輸出元件: (數位訊號) 
  





3. 光感測元件(光敏電阻): (類比訊號)

  

4. OH49E 霍爾感測器: (類比訊號)


  


5. DHT11 溫濕感測器 : (數位訊號)





6. DS18B20 水溫感測器: (類比訊號)







7. 微動開關 : (數位訊號)






8. PIR 人體紅外線感測器: (數位訊號)

  



2014年1月25日 星期六

S4A IO Board/Shield for Arduino 詳細介紹

一.簡介

    S4A IO Board/shield主要設計給ArduinoS4A初學者使用的一塊擴充板,除了支持一般杜邦接頭3 pin腳位外還可以連接10RJ11的接頭(五組數位及五組類比)感測元件(另購),如溫濕度感測器、土壤濕度感測器等。另外預留一個藍芽孔位給需要無線傳輸的使用者,可利用此無線傳輸跟Android手機或電腦溝通。此外也提供外部電源切換。此擴充板相容於Arduino Duemilanove UNOLeonado




二.   內容說明及特點:


特點:
1. 五組RJ11(6P4C電話線)數位接頭及五組類比接頭容易外接其他裝置或感測器,可以連接至少10公尺長距離的終端感測器或裝置(另購)
2. 電源紅色LED
3. 一顆 綠色LED 連接D13腳位
4. 預留一個藍芽孔位(UART)
5. Jumper可切換Vcc為內部電源(5V)或外部電源供給。


三. RJ11(6P4C電話線)接頭腳位說明
RJ11接頭中其中兩接腳為VCCGND,另外兩根接腳為IO訊號接腳,也就是說連接RJ11的感測元件可以利用此兩根IO溝通訊號,例如I2C訊號就可以利用A4A5那個孔位連接裝置。


四. 安裝藍芽模組說明
        



  


#### 請注意安裝藍芽模組腳位一定要正確對應IO Board上的藍芽預留孔位###


參考網站:  http://motoduino.com



2014年1月5日 星期日

Raspberry (樹莓派) 與 Arduino Shield 橋梁: MotoPiduino 介紹及I2C檢測

此塊MotoPiduino的功能之前大概說明過,這次說明一下IO 腳位的用途及對應Raspberry Pi的腳位.
從下圖板子可以看出有兩排腳位,此腳位剛好可以對應Arduino 腳位, 相容於Arduino UNO/Deumilanove. 也可以接兩顆DC馬達.




下圖是使用MotoPiduino時, Raspberry Pi 跟 Arduino腳位的對應. 可以看出都是Digital Pin腳位對應Raspberry Pi, 只有 A4及A5對應到Raspberry GPIO02 GPIO03, 主要是I2C 控制IO. 所以可以把以前接Arduino的 I2C 周邊接到此處(A4/A5). 



接下來說明如何 enable raspberry Pi 的 I2C 功能. 把MotoPiduino連接到Raspberry Pi後,如下圖.




sudo nano /etc/modules
#加入底下兩行
i2c-bcm2708
i2c-dev
#安裝I2C tools
sudo apt-get install python-smbus
sudo apt-get install i2c-tools
#修改raspi-blacklist.conf
sudo nano /etc/modprobe.d/raspi-blacklist.conf
#blacklist spi-bcm2708   ß 前面加個 #
#blacklist i2c-bcm2708   ß 前面加個 #
#Check連接的裝置
sudo i2cdetect -y 1



看到顯示48表示MotoPiduino上的 I2C address為 48(16進制) 處於溝通狀態. 接下來試試疊上一個Arduino Proto Shield, 在Proto Shield上有一個I2C介面重力加速度計及陀螺儀 (9DOF), Data Pin接到A4及A5. 如下圖.





在試著在command line下 sudo i2cdetect -y 1 則可以看到顯示 53數字, 表示偵測到9DOF的裝置(I2C address為 0x53).



#下一次再來說明接I2C LED 七段顯示器如何顯示數字,如下圖!







2013年9月20日 星期五

樹莓派(Raspberry Pi)手機遙控車(Part 1) = MotoPiduino + Raspberry Pi (樹莓派) + USB WiFi dongle

最近開發的MotoPiduino持續改良修正問題,目前MotoPiduino搭配Raspberry Pi測試已告一段落,預計下個月應該可以上市! MotoPiduino主要是搭起Raspberry Pi跟Arduino之間的橋樑,可以把Arduino的擴充板直接插在MotoPiduino上作運用,除此,MotoPiduino還有內建馬達驅動IC,可以直接驅動兩顆DC直流馬達. 此影片範例即是利用Android手機遙控Raspberry Pi來控制馬達運轉!  在Part 2中將接上Raspberry Pi專用的攝影模組,可以即時傳輸影像(這是Arduino所辦不到), 敬請期待!!













使用材料:
1. Raspberry Pi
2. MotoPiduino
3. 5V 行動電源
4. 9V 電池 (驅動馬達)
5. USB WiFi Dongle
6. 圓形車體

遙控車程式(Python):

----------------------------------------------------
#Get the GPIO module
import RPi.GPIO as GPIO
#Get the time module
import time
#Get the socket module
import socket
#Some IP constants for this, the server
UDP_IP = "192.168.0.113"   // 請修改成自己的 IP Address
UDP_PORT= 8888              // default port : 8888
#A routine to control a pair of pins
def ControlAPairOfPins(FirstPin,FirstState,SecondPin,SecondState):
    print("Controlling pins")
    if FirstState == "1":
        GPIO.output(int(FirstPin),True)
    else:
        GPIO.output(int(FirstPin),False)
    if SecondState == "1":
        GPIO.output(int(SecondPin),True)
    else:
        GPIO.output(int(SecondPin),False)
            #Just retur
    return

####Main body of code
#Get rid of warnings
GPIO.setwarnings(False)
#Set the GPIO mode
GPIO.setmode(GPIO.BOARD)
#Set the pins to be outputs
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
GPIO.setup(15,GPIO.OUT)
#Set up the IP related details
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
print "Pi_Robot server started ...."

while True:
#Wait for a UDP command to be received
    print("Waiting for UDP command")
    MyChar, addr = sock.recvfrom(1024) #buffer size is 1024
    print "I received: " + MyChar
    if MyChar == "forward":
        ControlAPairOfPins("12","1","13","1")
        ControlAPairOfPins("11","1","15","1")
        print "Forward"
    elif MyChar == "stop":
        ControlAPairOfPins("12","0","13","0")
ControlAPairOfPins("11","0","15","0")
        print "Stop"
    elif MyChar == "back":
        ControlAPairOfPins("12","1","13","0")
        ControlAPairOfPins("11","1","15","0")
        print "Back"
    elif MyChar == "left":
        ControlAPairOfPins("12","1","13","1")
        print "Left"
    elif MyChar == "right":
        ControlAPairOfPins("11","1","15","1")
        print "Right"
    else:
        print "Not a command"

----------------------------------------------------------------

  
相關資訊:
http://www.motoduino.com  (motopiduino user guide and android app download)
http://sinocgtchen.blogspot.tw/


2013年9月11日 星期三

S4A IO Board/Shield for Arduino

此版本增加兩顆LED,一顆紅色(power led), 一顆綠色(連接arduino Pin 13),其它維持之前版本,尺寸依然是5.3 x 8.7 cm,且方便接上需要的感測器或裝置叫 S4A IO board for Arduino , IO 腳位也針對S4A Scratch 設計容易使用,可以外接電源提供給伺服馬達. IO腳位可以用一般的杜邦線接頭,也可以用RJ11電話線接頭(目前正在開發許多RJ11接頭的感測器),可以取代Arduino Sensor Shield的功能, 目前板子準備量產中.............


2013年8月9日 星期五

S4A IO Board for Arduino

一些使用者反應 S4A Sensor Board (圖一)尺寸太大,且上面一些感測元件用不到,最近開發出一塊尺寸小(5.3 x 8.7 cm)且方便接上需要的感測器或裝置叫 S4A IO board for Arduino (圖二), IO 腳位也針對S4A Scratch 設計容易使用,可以外接電源提供給伺服馬達. 目前板子測試中.............


(圖一) S4A Sensor Board for Arduino






(圖二)  S4A IO Board for Arduino




(圖三) S4A IO board 疊在 motoduino 上