RaspberryPi
簡介
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
樹莓派(英語:Raspberry Pi)是基於Linux的單晶片電腦,由英國樹莓派基金會開發,目的是以低價硬體及自由軟體促進學校的基本電腦科學教育。
樹莓派是源自一個開放源程式碼的硬體專案平台,該平台包括一塊具備簡單I/O功能的電路板以及一大堆的Linux 軟體。
命名由來
樹梅派 Raspberry Pi 的 Pi 就是指
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
python,一開始只打算使用 python 當 Raspberry Pi 的專屬語言,但之後各種的語言都可以在 Raspberry Pi 上面運行了。
而以樹莓為命名 Raspberry 則是為了致敬 Apple、Tangerine Computer Systems、Apricot Computers、Acorn等以水果為命字的公司。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
應用
樹莓派可以用來開發交互產 品,比如它可以讀取大量的開關和感測器信號,並且可以控制電燈、電機和其他各 式各樣的物理設備;也可以開發出與PC一樣的周邊裝置,也可以運行在Linux PC 上的軟體進行通信。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
機器人、自走車
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
做成掌機
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
物聯網通訊的閘道器
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
四軸飛行器、無人機
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
做成平板
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
影音播放器
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Arduino uno 與 Raspberry Pi B 比較
|
Arduino uno |
Raspberry Pi Model B |
Price |
$30 |
$35 |
Size |
7.6x1.9x16.4 cm |
8.6x5.4x1.7 cm |
Memory |
0.002MB |
512MB |
Clock Speed |
16MHz |
700MHz |
On Board Network |
None |
10/100 wired Ethernet RJ45 |
Multitasking |
No |
Yes |
Iput voltage |
7~12V |
5V |
USB |
One,input only |
Two,peripherals OK |
Flash |
32KB |
SD Card(2~16G) |
Operating System |
None |
Linux distributions |
Integrate Development Environment |
Arduino |
Scratch、IDLE、anything with Linux support |
官網 : https://www.raspberrypi.org |
|
|
各式硬體種類 : https://www.raspberrypi.org/products/ |
|
|
Raspberry Pi 3 Model B+
與 Pi 3 最大的改變是網路效能增加了!
特色
- 新增四根 PoE 的 Pin 腳支援,並有對應的擴充板(HAT)。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
規格
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- Fusion 360 Raspberry Pi 3 Model B+ 若看不到,請點擊此連結
Raspberry Pi 4 Model B
和之前的版本最大的改變是多了 2GB/4GB/8GB 的記憶體版本可供選擇
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
紅色圈起來的地方是MicroSD卡插槽 (樹莓派背面)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
特色
- 使用 Broadcom 2711 四核心晶片(原本為 BCM2837B0)Quad-core Cortex-A72 64-bit SoC,單核心時脈可達 1.5GHz,有三倍速快。
- 三種記憶體(LPDDR4 SDRAM)大小可選擇,分別是 1GB, 2GB, 4GB 和 8GB。
- 乙太網路(Ethernet)達 True Gigabit Ethernet。
- 支援藍牙5.0(Bluetooth 5.0)。
- 兩個 USB 3.0 和 兩個 USB 2.0。
- 支援雙螢幕輸出,解析度可達 4K。
- 使用 VideoCore VI,可支援 OpenGL ES 3.x。
- 可硬體解 4Kp60 HEVC 影片。
規格
型號 |
樹莓派 4B |
晶片 |
Broadcom 2711,Quad-core Cortex-A72 |
處理器 |
四核ARM Cortex-A72(v8) 64位元 1.5GHz處理器 |
記憶體 |
1GB, 2GB or 4GB LPDDR4 SDRAM |
Wifi |
2.4GHz / 5.0GHz IEEE 802.11.b/g/n/ac wireless LAN |
藍芽 |
Bluetooth 5.0, BLE |
乙太網路 |
ports delivering true Gigabit Ethernet |
USB |
2 x USB 2.0 / 2 x USB 3.0 |
IO |
Extended 40-pin GPIO header |
影像音頻 |
2 x micro HDMI、4k video(支援雙螢幕輸出)、1 X MIPI DSI display port、1 X MIPI CSI camera port、4 pole stereo output and composite video port |
電源IC |
Microchip LAN7515 |
電源 |
DC 5V3A, 從USB Type-C接頭,或GPIO排針,或PoE輸入皆可 |
- Fusion 360 Raspberry Pi 4 Model B+ 若看不到,請點擊此連結
環境設置
安裝作業系統
將官方作業系統透過Raspberry Pi Imager 燒錄到MicroSD卡中,完成後將MicroSD插入樹莓派然後開機啟動,就完成安裝啦
安裝系統前須注意 :
1.確認您的電腦是否有Micro SD讀卡機,若沒有須自行準備並接至電腦
2.周邊設備是否備齊,如圖所示 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
3.將作業系統燒錄至Micro SD的動作只會用到電腦,固可先將設備先接至電腦(ex.鍵盤、滑鼠....),待燒錄完畢後再轉移到樹莓派即可。
安裝流程
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟二 : 至官網下載Raspberry Pi Imager 在這裡選擇windows版本
不須下載傳統燒錄軟體、映像檔,更簡便快速
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟三 : 開啟執行檔後 繼續在Windows中開啟Raspberry Pi Imager
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 選擇作業系統 >Operating System>Raspberry Pi OS(other)>Raspberry Pi OS Full(32-bit)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 選擇你的SD卡
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 開始燒錄 燒錄完成後會驗證(Verifying...⏳)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟四 : 取出Micro SD卡 插入樹莓派的SD卡插槽
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟五 : 將樹梅派接上螢幕、鍵盤、滑鼠、網路後開機進行設定區域、語言、密碼、網路等等的設定,就完成啦:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
網路設定
wifi連線
方法一 : raspi-config
尚未連接WiFi(Wlan0)時觀察網路介面的相關參數
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟四 : 輸入你的WiFi名稱(必須大小寫一致)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟五 : 輸入你的WiFi密碼,若沒設密碼直接按確定
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
再觀察一次網路參數,連線成功:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
方法二 : 修改 /network/interfaces
- 步驟一 : 所在的區域必須擁有網路(無線分享器WIFI或是有線分享器)。
- 步驟二 : 設定你的WIFI名稱與密碼(名稱必須完全一致)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
輸入完成後按下Ctrl+O(英文O) → Enter → Ctrl+X重新開機等候數分鐘約5~10分鐘,樹莓派就會自行連上WIFI
- 步驟三 : 重新開機後檢查連線是否成功,也可以隨便開個網頁來看看
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
遠端連線
ssh
就是secure shell,透過網路連線到其他台主機上。
- 步驟一 : 我們首先要獲得Raspberry pi的ip address
網路的話可以連wifi,也可以把網路線連接在電腦上或路由器上,在terminal輸入ifconfig可以得到目前的ip address。
此範例用的是wlan0(wifi)的網路
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
從2016年底開始,Raspberry pi預設ssh都是關閉的,所以我們要先前往設定啟用它。
-偏好設定>Raspberry Pi 設定
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-啟用SSH
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
也可以透過樹梅派的terminal打開它,輸入:
-選擇Interface Options
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-選擇ssh
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-選擇enable後它就會告訴你SSH server已經啟用了
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 回到我們的電腦,我們已經獲得ip address,也啟用ssh,開啟putty,輸入相對應的IP位置後便完成後就可以遠端控制Raspberry pi了。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
預設帳號是 pi
預設密碼是 raspberry (密碼是盲打喔 不是鍵盤壞掉)
完成 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
VNC
VNC是一個遠端桌面的軟體,分成我們的VNC Server(Raspberry pi),與VNC Viewer(筆電端)。
直接從樹莓派設定可以看到系統預設的VNC伺服器也不見了,也不是消失無蹤,而是預設不啟動了。此時想以VNC操控,就會失敗。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
不過只要自己在命令列下打指令,啟動TightVNC伺服器:
- 步驟一 : 透過putty連線下開啟vnc的指令(也可以直接在樹莓派的terminal下指令)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-在此下載的是windows版本
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-完成後開啟執行檔
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-建立連線設定 >File>New connection...
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
VNC Server : 樹莓派IP加上 :1
(簡單的說:0代表實體連接的螢幕,而剛剛的指令會開出另一個螢幕:1。)
Name : 隨意取名,方便辨識
-建立完成,點擊右鍵兩下、輸入密碼就能看到連線畫面
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
中文化
介面中文化
- 步驟一 : 在左上角按「Raspberry 圖案」 > Preferences > Raspberry Pi Configuration
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟二 : Set Locale…
Language : zh(Chinese)
Country : TW(Taiwan)
Character Set : UTF 8
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
完成啦
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
中文輸入法
下載輸入法
- 步驟一 : 點選開始功能表的 偏好設定/Add/Remove Software
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟二 : 在搜尋欄中輸入scim-chewing
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟三 : 勾選最下面兩個選項,按下Apply,系統會要求輸入設定時預設的管理者密碼
【Chewing IM engine module for SCIM】
【Chinese input method data tables for SCIM platform】
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟四 : 系統會將相關的應用程式工具一併勾選,按下OK鍵
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
設定輸入法介面的切換鍵
- 步驟一 : 點選 開始功能表/偏好設定/SCIM Input Method(SCIM輸入法框架)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟二 : 點選介面(前端)設定,設定輸入法的切換鍵與快速鍵,設定切換下一種輸入法的快速鍵(…)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟四 : 再按一下鍵盤上的左側【Shift】按鍵
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟五 : 在空白欄裡會出現「Shift_L」,點選+新增至選定的按鍵欄位中
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟六 : 這樣就完成切換至下一種輸入法快速鍵的設定,記得要點選 ✔
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
輸入法引擎設定
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟二 : 取消簡體中文項目的勾選(需要則保留),勾選自己常用繁體中文的輸入法、其他語文項目,點選✔
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 步驟四 : 右上角會出現小鍵盤,完成啦 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
程式範例
GPIO
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
GPIO(General Purpose I/O Ports)意思是通用型輸入/輸出介面,也就是一些針腳可以通過它們輸出高電位或者低電位,可以供使用者由程式控制自由使用,與裝置進行通訊,達到控制裝置的目的。
既然一個針腳可以用於輸入、輸出或其他特殊功能,那麼一定有暫存器用來選擇這些功能。
對於輸入,一定可以透過讀取某個暫存器來確定針腳電位的高低;對於輸出,一定可以透過寫入某個暫存器來讓這個針腳輸出高電位或者低電位;對於其他特殊功能,則有另外的暫存器來控制它們,所以掌握了 GPIO 就相當於掌握了硬體的控制。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
這裡可以看到有二種編號規則,分別是紅框內的 BOARD 編號規則,與紅框外的 BCM 編號規則。
LED發光二極體的控制實作
控制單科LED閃爍練習
程式範例 : led_single.py
開始撰寫程式碼:
- 匯入模組
import time : 匯入時間模組,要完成閃爍效果,需要用到時間暫停的技巧。
import RPi.GPIO as GPIO : 匯入RPi.GPIO模組物件,用於控制Raspberry Pi GPIO引腳。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 宣告設定
setwarnings(False) : 在執行過程中將所有警告提示關閉(False)。
setmode(GPIO.BCM) : 設定模式
– GPIO.BCM : 使用GPIO編號
– GPIO.BOARD : 使用電路板腳位(pin的)編號
setup(4, GPIO.OUT) : 設定GPIO.4(BOARD模式7)作為輸出(Output)腳位
- 主程式區
透過無窮迴圈讓LED燈反覆閃爍,若要停用則按Ctrl+C強制停止。
GPIO.output(4,1) : (對應腳位,電位),1代表輸出高電位(High)的3.3V信號使LED點亮,0代表輸出低電位(Low)的0V信號使LED熄滅。
time.sleep(1) : 利用第2行的時間模組,將時間暫停1秒,sleep()方法暫停執行給定秒數。
電路圖 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
LED按鍵控制練習: 按一下亮,按一下滅
程式範例 : led_switch_on_off.py
電路圖 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
PWM範例 : LED漸亮
程式範例 : led_pwm1.py
Duty Cycle(工作週期,高電位佔用整個波形周期的比例),下圖分別呈現工作週期為 50% 與 25% 時的電位波形。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
在控制 LED 燈泡方面,只要記得工作週期越大燈泡就越亮,而工作週期越小時燈泡就越暗。
電路圖 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
PWM範例 : LED閃爍頻率慢到快
程式範例 : led_pwm2.py
電路圖 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
超音波感測器
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
超音波模組HC-SR04,算是常見的模組,特別是用在智慧車等專案中,用來測量前方障礙物的距離。
它的運作原理很簡單,模組會送出8個40khz的聲波,如果前方有障礙物,信號就會返回,模組收到信號後,再利用返回的時間,去計算該障礙的距離。
常見的HC-SR04都有4個腳,除了VCC和GND以外,Trig就是發送訊號,Echo就是接收返回的訊號。然後我們就能利用一發一收,去算出中間的距離了。
範例程式 : 測距儀
程式範例 : distance.py
實作結果 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
電路圖 :
使用杜邦線將工作電壓(Vcc)接5V、接地(GND)接GND、觸發(Tig)接GPIO.24、迴聲(Echo)接GPIO.25
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
範例程式 : 測量平均值距離
程式範例 : ultrasonic_distance_average.py
人體紅外線感測器
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
電路圖 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
伺服馬達(SERVO)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
伺服馬達(Servomotor)是對用於使用伺服機構的馬達(電動機)總稱。
伺服(Servo)一詞來自拉丁文"Servus",本為奴隸(Slave)之意,此指依照命令動作的意義。
所謂伺服系統,就是依照指示命令動作所構成的控制裝置,應用於馬達的伺服控制,將感測器裝在馬達與控制對象機器上,偵測結果會返回伺服放大器與指令值做比較。
硬體方式
程式範例 : servo_hardware.py
之前透過RPIGPIO的PWM指令,以便讓LED漸亮,PWM是屬於軟體模擬控制,所以不限制特殊腳位編號,缺點是無法精準控制。而本範例特別匯入使用pigpio函式庫模組,PWM是屬於硬體模擬控制,有支援硬體PWM的腳位,分別是BCM編號12、13、18、19的四隻腳位而已,如果PWM使用其他腳位,執行時會出現pigpio.error:GPIO has no hardware PWM 錯誤。
在執行程式碼前,請在樹莓派上下載pigpio套件:
並且執行:
若未下載套件、執行套件.執行程式碼時會有以下的錯誤訊息產生:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio at localhost(8888)
Did you start the pigpio daemon? E.g. sudo pigpiod
Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888
Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Traceback (most recent call last):
File "/home/pi/servo_hardware.py", line 14, in <module>
pi.hardware_PWM(PWMPIN, PWM_FREQ, update(90))
File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1964, in hardware_PWM
self.sl, _PI_CMD_HP, gpio, PWMfreq, 4, extents))
File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1006, in _pigpio_command_ext
sl.s.sendall(ext)
AttributeError: 'NoneType' object has no attribute 'sendall'
開始撰寫程式:
電路圖 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
實際操作 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
軟體方式
程式範例 : servo_software.py
使用軟體來模擬PWM功能有一些缺點,因為執行PWM軟體模擬功能時,需要CPU不斷地計算時間訂控制波形,造成CPU資源部只要提供PWM軟體使用,還必須同時提供各式各樣的程式使用,所以很容易造成無法即時處理PWM功能,進而影響PWM輸出的波形。
一旦波形不正確,PWM也失去了精確性,造成伺服馬達可能無法定位到正確的角度。使用硬體PWM才可以達到更精準地控制效果,對系統的負擔比較小。
在執行程式碼前,請在樹莓派上下載pigpio套件(載過的可以忽略):
並且執行(執行過的可以忽略):
電路圖 :
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
DHT11 數位溫溼度感測模組的控制
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
DHT11數位溫溼度感測模組屬於數位輸入,而非類比輸入。
溫度測量範圍為0-50度,測量誤差±2度,溼度測量範圍為20-95%,測量誤差±5,工作電壓5V。
DHT11可同時監測周圍環境的溫度與濕度的變化,價格低廉,經常使用於物聯網環境溫溼度監測。
顯示溫溼度
程式範例 : dht11.py、dht11_example.py
dht11.py (做為副程式,用來模擬1線通信介面程式)
dht11_example.py (主程式)
電路圖:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
執行主程式:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
火焰感測器模組
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
火焰感測器模組工作電壓 3V 或 5V 均可,利用紅外線對火焰非常敏感的特點,使用特製的紅外線接收管來檢測火焰,然後把火焰的亮度轉化為高低變化的電壓信號,使用打火機測試火焰距離為 80cm 以內,但火焰越大,測試距離越遠,探測角度約 60 度左右,越靠近火焰,AO 讀值越小,DO 則為高電位。一般常用做智慧居家的火焰警報等用途。
程式範例 : fire_sensor.py、AnaloginOutSerial.ino
UART
UART(Universal Asynchronous Receiver/Transmitter)是指通用非同步收發傳輸器,只允許兩個裝置直接對接,無法接更多裝置,除非使用 RS-422、RS-485 則可接多個裝置,基本傳送僅需利用 Tx 傳輸與 Rx 接收兩個接腳,跟 SPI 均屬於全雙工通訊,連接方式如下圖,由於速度不是很快,一般而言最高為 115.2Kbps,雖有更高速版本但不太普及,所以不適合用在高速、大量傳輸上。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
接著程式範例是利用樹莓派的 UART 傳輸方式,讀取 Arduino 開發板的類比腳位數值。
fire_sensor.py
AnaloginOutSerial.ino
- 找到A0腳位,根據感測器的腳位用杜邦線與arduino做連接
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 依序點選「軟體開發→ Arduino IDE」進入編輯環境
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 便會看到GUI畫面,顯示類比讀值 (測試時請小心喔!)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
從樹莓派控制 Arduino 輸出信號
利用樹莓派控制 Arduino 的 Pin13 腳位狀態,讓內建 LED 每隔 1 秒閃爍。
程式範例 : led_control.py、ledOnOff.ino
led_control.py
ledOnOff.ino
- 依序點選「軟體開發→ Arduino IDE」進入編輯環境
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 觀察 Arduino 閃爍變化的速度是否也跟著改變,亮紅燈的LED以及下方左側LED即為對應D13的LED。
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →