## [樹梅派OS部屬影片](https://www.youtube.com/watch?v=CYhpoO5VbqU) ## 參考資料 [Raspberry Pi Introduction (樹莓派介紹)](https://hackmd.io/@combo-tw/S1EfJwQbB) [Day4 Raspberry Pi介紹](https://ithelp.ithome.com.tw/articles/10217981) [Day8 - 樹莓派的GPIO簡介](https://ithelp.ithome.com.tw/articles/10237152) ## 樹莓派介紹 ### 命名由來 - 樹梅派 Raspberry Pi 的 Pi 就是指 python,一開始只打算使用 python 當 Raspberry Pi 的專屬語言,但之後各種的語言都可以在 Raspberry Pi 上面運行了。 - 而以樹莓為命名 Raspberry 則是為了致敬 Apple、Tangerine Computer Systems、Apricot Computers、Acorn等以水果為命字的公司。 ### 機型 - 而 Raspberry Pi 從推出到現在,釋出了許多機型,一開始型號分為 A、B 兩種,A 為沒有網路孔的型號價格較低。之後則推出了型號 Pi Zero,是 model A、B 閹割版,性能稍差,但體積更小;Pi Zero W 則是 Pi Zero 的無線網路版本。 - 註:我們課程所使用的是 Pi 4 ![upgit_20240827_1724749877.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724749877.png) ## GPIO 腳位 - GPIO (General Purpose Input Output) 就是可以輸入輸出指令的地方,各接腳有編號與各自負責的工作,可以透過程式去控制他們,下圖是屬於 Raspberry Pi 的40個 pin ,各具備不同功能。 - 可分為以下四種類別: - I2C - UART - SPI - GPIO ![upgit_20240827_1724749935.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724749935.png) ![upgit_20240827_1724749953.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724749953.png) ## 使用示意圖 ![pi-plug-in](https://hackmd.io/_uploads/S1hAOMso0.gif) ## 環境建置 ### 0.需要材料 - SD卡(建議用小卡) - 讀卡機 ### 1.安裝MicroSD卡 - 請小心&注意方向!! 請小心&注意方向!! 請小心&注意方向!! - 請把卡的位置與洞洞插對 ![upgit_20240827_1724751039.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724751039.png =100%x) ![upgit_20240827_1724751078.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724751078.png =100%x) ![upgit_20240827_1724751579.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724751579.png =100%x) ### 2. 將電腦開啟行動熱點 - 在後續的動作是要讓Raspberry Pi吃你目前正在使用的電腦(這樣你才可以看到樹梅派所聯的IP) - 在撰寫這份教材時,助教是採用實驗室路由的熱點去做,那這邊你要決定好提供給樹梅派的網路是誰 - 可以採用電腦開熱點去做 - 可以採用路由熱點去做 ### 3. 到Raspberry Pi Imager下載Raspberry Pi OS - 下載連結:[Raspberry Pi OS](https://www.raspberrypi.com/software/) ![upgit_20240827_1724750477.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724750477.png) - 將SD卡插入讀卡機,然後將讀卡機插入電腦 - 安裝好後開啟exe ![upgit_20240827_1724750552.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724750552.png =100%x) - 選擇【CHOOSE DEVICE】,然後選擇型號 ![upgit_20240827_1724751751.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724751751.png =100%x) - 作業系統選擇【Raspberry Pi OS (64-bit)】 - 記憶卡就須選你的記憶卡 ![upgit_20240827_1724752528.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724752528.png =100%x) ![upgit_20240827_1724752614.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724752614.png =100%x) - 按下【NEXT】,會詢問你是否要進行設置,選擇【編輯設置】 ![upgit_20240827_1724752686.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724752686.png =100%x) - 在【GENERAL】 - 主機名稱:不用動 - 使用者密碼名稱(要牢記) - 開啟熱點 ![image](https://hackmd.io/_uploads/r1QNW5Zm1e.png) - 記住熱點名稱、密碼 ![image](https://hackmd.io/_uploads/rJGv-9WQyl.png) - 網路設定大致上的流程圖 ![image](https://hackmd.io/_uploads/rJzmEpZ71x.png) - 所以在樹梅派配置WiFi的部分要設定電腦熱點的名稱、密碼,不是手機的 - 配置WIFI(打上剛剛的熱點名稱、密碼) ![upgit_20240827_1724753254.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724753254.png =100%x) - 在【SERVICES】開啟SSH服務(這樣你才可以遠端) - 按下【保存】 ![upgit_20240827_1724753374.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724753374.png =100%x) - 按下【是】 ![upgit_20240827_1724753445.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724753445.png =100%x) - 讓記憶卡格式化,並安裝OS ![upgit_20240827_1724753464.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240827_1724753464.png =100%x) ### 4.插卡卡 ![upgit_20240828_1724823028.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240828_1724823028.png =100%x) ![upgit_20240828_1724823011.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240828_1724823011.png =100%x) ## 遠端連線 - 先去熱點查看樹梅派連線的IP,記得她要跟你是同一個局網 ![image](https://hackmd.io/_uploads/HkwmVq-Q1x.png) ## 透過ssh與樹梅派進行遠端操作 ### 方法1: 使用terminal(不用安裝額外套件) - 開一個terminal - 下指令`ssh kcwc1029@192.168.137.168`,然後就進來了 ![upgit_20240828_1724823420.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240828_1724823420.png) - 使用`ls`可以查看當前目錄的內容物 ![image](https://hackmd.io/_uploads/S1KVjnW7kl.png) - 使用`touch`指令可以創建檔案(touch後面要跟著檔案名稱) ![image](https://hackmd.io/_uploads/SkthohWXyl.png) - 我們在使用`ls`指令來查詢就能發現`hello.py`被我們創建在此目錄中了 ![image](https://hackmd.io/_uploads/Hyx4hhZmJe.png) - 使用`nano`指令來開啟對我們的`hello.py`才能做程式碼的撰寫 ![image](https://hackmd.io/_uploads/rklC22ZXye.png) - 然後按下Enter執行`nano hello.py`指令,就可以開始做撰寫 ![image](https://hackmd.io/_uploads/Byb763Z7ye.png) - 程式碼撰寫完成後就按下`ctrl + s`儲存,然後`ctrl + x`離開 - 使用`python`指令來執行我們剛剛撰寫的`hello.py` ![image](https://hackmd.io/_uploads/rke9Y0nbmkx.png) - 完成 2. 方法2: VS Code ssh(要額外裝套件,但寫程式比較方便) * 開啟VS Code * 選取左側"延伸模組",輸入"SSH",按"安裝" ![](https://i.imgur.com/n4V7xQP.jpg) * 選取左側"遠端總管",選取"SSH Target",按"+" ![](https://i.imgur.com/z8Axqya.jpg) * 輸入SSH指令:`ssh 使用者名稱@樹梅派ip` e.g. `ssh N96114239@192.168.137.10` ![](https://i.imgur.com/UK3vJoo.jpg) * 選擇SSH設定檔要存在哪裡,這邊直接按"Enter"即可 ![](https://i.imgur.com/7zxtskQ.jpg) * 對著剛加入的連線按右鍵,看你要用現在的視窗還是新開一個視窗皆可 ![](https://i.imgur.com/JimGjO0.jpg) * <font color="#f00">注意中上方,選擇"Linux",並輸入密碼</font> * 確認左下綠色部分有顯示SSH連線的ip,選取左側"檔案總管",按"開啟資料夾",直接按"確定"即可 ![](https://i.imgur.com/9qwtGfx.jpg) * 按右上"切換面板"以顯示終端機 ![](https://i.imgur.com/ex0d9P6.jpg) * 大功告成 ![](https://i.imgur.com/7YNtAOL.jpg) * 新增檔案,然後打上`hello.py` ![image](https://hackmd.io/_uploads/rkK4epW7kl.png) ![image](https://hackmd.io/_uploads/HkZ_gaZm1e.png) * 然後點`hello.py`就可以開始撰寫程式碼,然後`ctrl + s`儲存,然後在下方terminal中用`python` 指令來執行hello.py ![image](https://hackmd.io/_uploads/Bk87W6Zmyl.png) ## Raspberry Pi 中文環境安裝(補充) - sudo apt update - sudo apt install vim - sudo locale-gen zh_TW.UTF-8 - sudo vim /etc/locale.gen - 如果需要更改vim主題色 ```shell= :colorscheme default :colorscheme desert :colorscheme elflord :colorscheme ron ``` - 將zh_TW.UTF-8取消註解,離開 ![upgit_20240828_1724833272.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240828_1724833272.png) - sudo locale-gen (產生中文套件) - sudo vim /etc/default/locale (更改語系) - ![upgit_20240828_1724833543.png](https://raw.githubusercontent.com/kcwc1029/obsidian-upgit-image/main/2024/08/upgit_20240828_1724833543.png) - sudo apt-get -y install scim scim-tables-zh scim-chewing (安裝中文輸入字形) - sudo reboot ## Raspberry Pi 多使用者設定(補充) - 架設要多一名使用者s000 - sudo adduser s000 - 要刪除就sudo deluser s000 ## Lab09/作業題目 新增一個資料夾,資料夾名稱: 學號_Lab09 截取ssh連線成功畫面,儲在剛剛建立的資料夾中,圖片檔案名稱: Lab09.png 上傳樹梅派照片:照片內容為樹梅派本體,電源供應器,如果有多拿到其他東西也要拍進來。 圖片名稱為 : "RaspberryPi.png" 加分題: 在樹梅派中print出Hello world! 截取圖片,圖片檔案名稱: Lab09_plus.png 然後上傳至GitHub