個人在20年前專科時代就有玩過 8051 的微處理機,那時候寫程式相對的麻煩。
接線路也很麻煩,需要剪線、測長度,現在都有杜邦線這種現成做好的。
電子電路元件的觀念都還有印像,但是年久失修需要一段時間回憶。
底下這兩篇很適合入門的第一課:
Raspberry Pi 教學
http://www.raspberrypi.com.tw/category/%E6%95%99%E5%AD%B8/
基本電路元件解說
http://www.codedata.com.tw/java/java-embedded-6-raspberry-pi-gpio/
線路接線:(請參考上面兩篇)
LED_PIN 的輸出電位用的針腳是 12 port ,記得接對線路。
再 pi 內用編輯寫下面的程式碼:(RPi,GPIO 也請參考上面兩篇的說明安裝 pyhton lib)
pi@raspberrypi ~/code $ cat led_blink.py
import RPi.GPIO as GPIO
import time
# define pin 12, RPi P1. 2011.12 version.
LED_PIN = 12
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED_PIN, GPIO.OUT)
try:
while True:
print("LED is on")
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)
print("LED is off")
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)
except KeyboardInterrupt:
print "Exception: KeyboardInterrupt"
finally:
GPIO.cleanup()
執行:
pi@raspberrypi ~/code $ sudo python led_blink.py
LED is on
LED is off
LED is on
LED is off
LED is on
LED is off
LED is on
LED is off
^CException: KeyboardInterrupt (Ctrl+C 中斷)
pi@raspberrypi ~/code $