總網頁瀏覽量

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的功能, 目前板子準備量產中.............