SlideShare a Scribd company logo
1 of 26
Download to read offline
自走車
日期:2017/03/30
L298N馬達驅動板
1
2 3 4 5
6
1
2
3
4
5
6
馬達連接端子OUT1、OUT2
數位邏輯輸入電源(正極)
外部電源(正極)驅動馬達
接地(負極)
連接GPIO腳位,控制馬達正反轉
馬達連接端子OUT3、OUT4 2
3
馬達方向控制
馬達A 馬達B
旋轉方式 IN1 IN2 IN3 IN4
往前 1 0 1 0
往後 0 1 0 1
停止 0 0 0 0
右轉 1 0 0 0
左轉 0 0 1 0
馬達A
馬達B
前
後
4
自走車往前
5
物聯網技術重點之一
無線傳輸
6
藍牙-server
7
Serial Bluetooth Terminal
8
無線網路-server
9
TCP UDP Terminal
輸入樹莓派的IP
輸入訊息
10
作業四、基本題:模擬垃圾車
• 目的:練習物聯網的無線傳輸技術
• 無線傳輸方式:無線網路
*左邊一顆LED燈,右邊一顆LED燈,顏色不限。
*無源蜂鳴器只有自走車停止時不發出音樂,其餘自走車狀態需播
放小星星音樂。
• 敘述:智慧型手機透過wifi與樹莓派連線,然後從手機發送五個
指令如下,來控制自走車:
• Z代表自走車往前走,左右LED燈不發亮。
• X代表自走車往後走,左右LED燈同時每1秒閃一次。
• C代表自走車往左轉,左邊的LED燈每1秒閃一次。
• V代表自走車往右轉,右邊的LED燈每1秒閃一次。
• S代表自走車停止,無源蜂鳴器停止,左右LED燈都恆亮。
11
作業四、進階題:同步控制自走車
• 目的:練習物聯網的無線傳輸技術
• 無線傳輸方式:無線網路或藍牙
*無線網路或藍牙選其中一種傳輸方式
• 敘述:用智慧型手機透過wifi或藍牙,同時傳送指令給兩台自走
車,兩台自走車接收指令後會同時執行相同的動作,指令
如下:
• Z代表自走車往前走。
• X代表自走車往後走。
• C代表自走車往左轉。
• V代表自走車往右轉。
• S代表自走車停止。 12
附註
13
查看MAC位址
14
監聽藍牙連線
15
執行sudo apt-get update
1 2 執行sudo apt-get upgrade
16
執行sudo apt-get install bluetooth bluez blueman
3
執行sudo nano /etc/systemd/system/dbus-org.bluez.service
4
17
5
6
修改ExecStart=/usr/lib/bluetooth/bluetoothd 為 ExecStart=/usr/lib/bluetooth/bluetoothd –C
新增ExecStartPost=/usr/bin/sdptool add SP
完成後按Ctrl + X 離開,選Y儲存更新
執行sudo rfcomm watch hci0
開始監聽藍牙連線
18
安裝python藍牙函式庫
19
1
2
執行sudo apt-get install bluetooth libbluetooth-dev
執行sudo python3 -m pip install pybluez
20
Bluetooth server and client
21
rfcomm-client.py
import bluetooth
bd_addr = "01:23:45:67:89:AB" # here need to modify. use hciconfig to get address
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
sock.send("hello!!")
sock.close()
22
l2cap-server.py
import bluetooth
server_sock=bluetooth.BluetoothSocket( bluetooth.L2CAP )
port = 0x1001
server_sock.bind(("",port))
server_sock.listen(1)
client_sock,address = server_sock.accept()
print "Accepted connection from ",address
data = client_sock.recv(1024)
print "received [%s]" % data
client_sock.close()
server_sock.close()
23
l2cap-client.py
import bluetooth
sock=bluetooth.BluetoothSocket(bluetooth.L2CAP)
bd_addr = "01:23:45:67:89:AB"
port = 0x1001
sock.connect((bd_addr, port))
sock.send("hello!!")
sock.close()
24
無線網路-Client
import socket
host = '127.0.0.1'
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
addr = (host,5555)
mysock.connect(addr)
try:
msg =b"nhi, This is connection from python network client n"
mysock.sendall(msg)
except socket.errno as e:
print ("This is Socket Error!", e)
finally:
mysock.close()
25
App下載
• Android系統
• TCP/UDP Terminal
• Serial Bluetooth Terminal
• iOS系統
• Telnet Client Terminal
26

More Related Content

Similar to 2017 Week 6 Automatic Mobile Vehicle

Iot tech with education 物聯網技術在教育上的應用
Iot tech with education 物聯網技術在教育上的應用Iot tech with education 物聯網技術在教育上的應用
Iot tech with education 物聯網技術在教育上的應用
kuoyichen
 
認識 RoBoard 硬體
認識 RoBoard 硬體認識 RoBoard 硬體
認識 RoBoard 硬體
roboard
 

Similar to 2017 Week 6 Automatic Mobile Vehicle (9)

Ch12Micro:bit RF 遙控車
Ch12Micro:bit RF 遙控車Ch12Micro:bit RF 遙控車
Ch12Micro:bit RF 遙控車
 
第三章Ti msp430平台介紹 v3
第三章Ti msp430平台介紹 v3第三章Ti msp430平台介紹 v3
第三章Ti msp430平台介紹 v3
 
Iot tech with education 物聯網技術在教育上的應用
Iot tech with education 物聯網技術在教育上的應用Iot tech with education 物聯網技術在教育上的應用
Iot tech with education 物聯網技術在教育上的應用
 
160603 T客邦7688物聯網實作坊
160603  T客邦7688物聯網實作坊160603  T客邦7688物聯網實作坊
160603 T客邦7688物聯網實作坊
 
LinkIt Smart 7688 Duo and MCS basics
LinkIt Smart 7688 Duo and MCS basicsLinkIt Smart 7688 Duo and MCS basics
LinkIt Smart 7688 Duo and MCS basics
 
IoT 與 WoT 物聯網裝置實作:使用 Arch Pro 與 mbed
IoT 與 WoT 物聯網裝置實作:使用 Arch Pro 與 mbedIoT 與 WoT 物聯網裝置實作:使用 Arch Pro 與 mbed
IoT 與 WoT 物聯網裝置實作:使用 Arch Pro 與 mbed
 
WF8266R IoT DEV Board 物聯網開發版
WF8266R IoT DEV Board 物聯網開發版WF8266R IoT DEV Board 物聯網開發版
WF8266R IoT DEV Board 物聯網開發版
 
認識 RoBoard 硬體
認識 RoBoard 硬體認識 RoBoard 硬體
認識 RoBoard 硬體
 
#1247 Sensor and Controller Student book Chinese version-Part 1
#1247 Sensor and Controller Student book Chinese version-Part 1#1247 Sensor and Controller Student book Chinese version-Part 1
#1247 Sensor and Controller Student book Chinese version-Part 1
 

More from AkashaC1

More from AkashaC1 (20)

How to Prevent DNS Attacks on MikroTik.pdf
How to Prevent DNS Attacks on MikroTik.pdfHow to Prevent DNS Attacks on MikroTik.pdf
How to Prevent DNS Attacks on MikroTik.pdf
 
Config RouterOS openVPN.pdf
Config RouterOS openVPN.pdfConfig RouterOS openVPN.pdf
Config RouterOS openVPN.pdf
 
AR Implementation 1 2016.10.20
AR Implementation 1 2016.10.20AR Implementation 1 2016.10.20
AR Implementation 1 2016.10.20
 
AR Implementation 2
AR Implementation 2AR Implementation 2
AR Implementation 2
 
Post article to KM with Python
Post article to KM with PythonPost article to KM with Python
Post article to KM with Python
 
2018 Week 7 Data Analysis
2018 Week 7 Data Analysis2018 Week 7 Data Analysis
2018 Week 7 Data Analysis
 
2018 Week 5 DHT11
2018 Week 5 DHT112018 Week 5 DHT11
2018 Week 5 DHT11
 
2018 Week 4 PIR
2018 Week 4 PIR2018 Week 4 PIR
2018 Week 4 PIR
 
2018 Week 15 Speech Recognition
2018 Week 15 Speech Recognition2018 Week 15 Speech Recognition
2018 Week 15 Speech Recognition
 
2018 Week 15 Speaker
2018 Week 15 Speaker2018 Week 15 Speaker
2018 Week 15 Speaker
 
2018 Week 14 HC-SR04
2018 Week 14 HC-SR042018 Week 14 HC-SR04
2018 Week 14 HC-SR04
 
2018 Week 13 Servo Motor
2018 Week 13 Servo Motor2018 Week 13 Servo Motor
2018 Week 13 Servo Motor
 
2018 Week 12 Data Storage and Visualization
2018 Week 12 Data Storage and Visualization2018 Week 12 Data Storage and Visualization
2018 Week 12 Data Storage and Visualization
 
2018 Week 11 Bluetooth and Wi-Fi
2018 Week 11 Bluetooth and Wi-Fi2018 Week 11 Bluetooth and Wi-Fi
2018 Week 11 Bluetooth and Wi-Fi
 
2018 Week 10 Read Time Data Sending
2018 Week 10 Read Time Data Sending2018 Week 10 Read Time Data Sending
2018 Week 10 Read Time Data Sending
 
2018 Week 10 IoT and Robot
2018 Week 10 IoT and Robot2018 Week 10 IoT and Robot
2018 Week 10 IoT and Robot
 
2018 Week 8 Relay
2018 Week 8 Relay2018 Week 8 Relay
2018 Week 8 Relay
 
2018 Week 8 IoT and Wearable Devices
2018 Week 8 IoT and Wearable Devices2018 Week 8 IoT and Wearable Devices
2018 Week 8 IoT and Wearable Devices
 
2018 Week 7 Photoresistor
2018 Week 7 Photoresistor2018 Week 7 Photoresistor
2018 Week 7 Photoresistor
 
2018 Week 16 Computer Vision
2018 Week 16 Computer Vision2018 Week 16 Computer Vision
2018 Week 16 Computer Vision
 

2017 Week 6 Automatic Mobile Vehicle