Raspberry pi 3 B Raspberry Pi 3 B
Raspberry pi 3 B 規格 型號 Raspberry Pi 3 B So. C Broadcom BCM 2837 CPU 1. 2 GHz 64 -bit quad-core(四核心) ARM Cortex-A 53 GPU Broadcom Video. Core IV[42], Open. GL ES 2. 0, 1080 p 30 h. 264/MPEG-4 AVC高畫質解碼器 記憶體 USB介面個數 1024 MB (LPDDR 2) 4 板載儲存 Micro. SD 網路介面 10/100 乙太網介面(RJ 45介面) 電源輸入 5 V 電壓 (通過Micro. USB或經GPIO輸入) 總體尺寸 85. 60 × 53. 98 毫米 重量 4 g 4
Raspberry pi與Arduino 6
Raspberry pi 軟體準備 欲使用樹莓派需要下載幾個檔案: 1. 樹莓派系統映像檔(版本: Raspbian Stretch with desktop) https: //www. raspberrypi. org/downloads/raspbian/ 2. Win 32 Disk Imager --卸除式磁碟映像檔製作及寫入 具 https: //sourceforge. net/projects/win 32 diskimager/ 3. SD Formatter - SD卡專用格式化軟體 https: //www. sdcard. org/cht/downloads/formatter/ 8
下載系統映像黨 - Raspberry pi • 至前頁網址選擇" Raspbian Stretch with desktop"下載檔案 • 解壓縮後,得到"2019 -04 -08 -raspbian-stretch. img"映像黨 ,稍後將會用到。 12
Raspberry pi – 架設網頁伺服器 • 輸入"sudo apt-get install apache 2“ • 輸入"sudo apt-get install php 7. 3" • 輸入完成後, 按下鍵盤"ENTER"鍵 32
Raspberry pi – 架設網頁伺服器 • 修改網頁資料夾權限 • "sudo chown -R pi: www-data /var/www/html/ “ • "sudo chmod -R 770 /var/www/html/ " 35
Raspberry pi – 架設網頁伺服器 依照以上步驟安裝資料庫 • 輸入" sudo apt install mariadb-server-10. 0 php-mysql“ • 安裝完成後,開啟終端機輸入” sudo mysql --user=root ” • 進入後,輸入 " CREATE USER ‘admin@’localhost’ IDENTIFIED BY ‘admin' ; GRANT ALL PRIVILEGES ON *. * TO ‘admin'@'localhost‘; " • 來創建帳號密碼為: ”admin”的使用者 45
Raspberry pi – 架設網頁伺服器 • 輸入" sudo apt install phpmyadmin“ • 選擇" apache 2 “ • 選擇"是“ • 輸入" sudo apt-get install libmysql++-dev“ • 開啟終端機輸入 cd /var/www sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin • 打開 Apache 2 的設定檔" sudo vim /etc/apache 2. conf " 在裡面加上下面這一行。 • Include /etc/phpmyadmin/apache. conf 46
Raspberry pi – 架設網頁伺服器 • 開啟/etc/php 5/apach 2/php. ini • 將以下這行輸入到檔案文末 " extension=json. so " • 重啟apache " sudo service apache 2 restart “ • 即完成phpmyadmin的安裝 47
Raspberry pi – 寫第一個HTML網頁 • 開啟LX終端機 • 開啟後輸入" sudo nano /var/www/html/myhtml" • 按下"ENTER" 54
Python控制程式 #讓紅色LED閃10次,每次間隔 0. 5秒 import time import RPi. GPIO as GPIO. setmode(GPIO. BOARD) #設定LED pin變數 LED 0 = 7 counter = 0 #迴圈10次 while(counter < 10): GPIO. output(LED 0, GPIO. HIGH) Time. sleep(0. 5) GPIO. output(LED 0, GPIO. LOW) counter = counter + 1 GPIO. output(LED 0, GPIO. LOW) #設定為輸出 GPIO. setup(LED 0, GPIO. OUT) 63
小題目-Python控制程式 #讓紅色及綠色LED各閃10次,每次間隔 0. 5秒 import time import RPi. GPIO as GPIO. setmode(GPIO. BOARD) #設定LED pin變數 LED 0 = 7 LED 1 = 11 counter = 0 #迴圈10次 while(counter < 10): GPIO. output(LED 0, GPIO. HIGH) GPIO. output(LED 1, GPIO. LOW) time. sleep(0. 5) GPIO. output(LED 0, GPIO. LOW) GPIO. output(LED 1, GPIO. HIGH) time. sleep(0. 5) counter = counter + 1 GPIO. output(LED 0, GPIO. LOW) GPIO. output(LED 1, GPIO. LOW) #設定為輸出 GPIO. setup(LED 0, GPIO. OUT) GPIO. setup(LED 1, GPIO. OUT) 65
Python控制程式 import RPi. GPIO as GPIO import time #設置腳位 RED_LED_PIN = 3 GREEN_LED_PIN = 5 BLUE_LED_PIN = 7 PWM_FREQ = 70 red_pwm = GPIO. PWM(RED_LED_PIN, PWM_FREQ) blue_pwm = GPIO. PWM(BLUE_LED_PIN, PWM_FREQ) green_pwm = GPIO. PWM(GREEN_LED_PIN, PWM_FREQ) red_pwm. start(0) blue_pwm. start(0) green_pwm. start(0) GPIO. setmode(GPIO. BOARD) GPIO. setup(RED_LED_PIN, GPIO. OUT) GPIO. setup(BLUE_LED_PIN, GPIO. OUT) GPIO. setup(GREEN_LED_PIN, GPIO. OUT) 68
Python控制程式 #設置顏色的副程式 def set. Color(r=0, g=0, b=0): red_pwm. Change. Duty. Cycle(r) blue_pwm. Change. Duty. Cycle(b) green_pwm. Change. Duty. Cycle(g) #執行迴圈 try: while True: #紅色 red_pwm. Change. Duty. Cycle(100) blue_pwm. Change. Duty. Cycle(0) green_pwm. Change. Duty. Cycle(0) time. sleep(1) #綠色 set. Color(0, 100, 0) time. sleep(1) #藍色 set. Color(0, 0, 100) time. sleep(1) except Keyboard. Interrupt: pass red_pwm. stop() green_pwm. stop() blue_pwm. stop() GPIO. cleanup() 69
Raspberry 相機規格 71
Raspberry pi – 攝影指令 預覽指令: raspistill -f (全螢幕預覽) raspistill -t 10000 (預覽十秒 參數單位為毫秒) raspistill -p 0, 0, 100 (預覽視窗設定 x, y, w, h) raspistill -f -op 100 (設定預覽視窗透明度 參數範圍 0 -255) 拍照指令: raspistill -o test. jpg (輸出圖檔 儲存路徑/檔案名稱) raspistill -o test. jpg -hf(水平翻轉) raspistill -o test. jpg -vf(垂直翻轉) raspistill -o test. jpg -w 100 -h 100 (設定圖片大小 寬 高) raspistill -o test. jpg -q (設定影像品質 參數範圍 0 -100) 錄影指令: raspivid -o test. h 264 -t 10000 73
有趣指令 • Fortune • Figlet : figlet “text” • Sl • cmatrix 76
- Slides: 76