Pimoroni Pico Explorer Base
前言
好吧,我要剁手手了,因為我這個月為了電子 DIY 噴了一堆。
今天的主角就是 Pimoroni 出品的 Pico Explorer Base, 是一款 Raspberry Pi Pico 的學習用底座,上面有各式各樣的模組可以玩。
根據官網所說的,這個底座有包含以下模組:
- Piezo 蜂鳴器
- 1.54吋 240x240 LCD 螢幕
- 4 個按壓按鈕
- 兩個馬達驅動器
- GPIO & ADC 插座
- 兩個 Breakout Garden I2C 底座
- 迷你麵包板
這麼多模組,還蠻適合初學者,也適合懶著接一堆麵包板的人使用(喂)
安裝 Firmware
由於 Pimoroni Pico Explorer Base 有很多內建模組, 故需要給 Pico 安裝特製版本的 MicroPython 或 import 他們的 C++ Library。
在這裡,我使用 MicroPython,故需要從 Pimoroni 的 Github 頁面 下載 firmware image,
在這裡我下載 pimoroni-pico-v0.2.0-micropython-v1.15.uf2
並且安裝到 Pico 上。
由於之前有裝過 Raspberry Pi 官方的 firmware,故需要按下 bootloader selection 按鈕同時插到電腦上, 在電腦上會變成一個檔案儲存裝置,把新的 firmware 拖上去就好了。
開始使用 LED
借一下官方的 Blink 範例,並且把 Pin 改成用 GPIO0
from machine import Pin, Timer
led = Pin(0, Pin.OUT)
tim = Timer()
def tick(timer):
global led
led.toggle()
tim.init(freq=2.5, mode=Timer.PERIODIC, callback=tick)
然後把 LED + 1K Ohm 電阻 接到 Explorer Base 上 GP0 的插座, 執行程式就可以得到一個閃爍的 LED:
在內建 LCD 螢幕上顯示 Hello World
既然有 LCD 螢幕,何不乾脆在螢幕上顯示真正的 Hello World 呢? 參考了 Pimoroni 給的 micropython/examples/pico_explorer/buttons.py, 改成這樣
import utime
from machine import Pin
import picoexplorer as display
led = Pin(0, Pin.OUT)
# Set up and initialise Pico Explorer
buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
col = [[255,255,255], [255,0,0], [0,255,0], [0,0,255], [255,255,0], [255,0,255], [0,255,255]]
i = 0
display.clear()
while True:
if display.is_pressed(display.BUTTON_A):
i = (i + 1) % len(col)
if display.is_pressed(display.BUTTON_B):
led.toggle()
if display.is_pressed(display.BUTTON_X):
display.clear()
i = (i + 1) % len(col)
r, g, b = col[i]
display.set_pen(r, g, b)
display.text("Hello World", 10, 10, 240, 4)
display.update()
utime.sleep(0.1)
然後透過 Thonny 把程式丟到 Pico 上跑:
這算是完成了儀式(喂)