Raspberry Pico

  1. 使用 Thonny 將 blink (內建LED燈閃爍) 程式燒錄到 Pico
  2. 使用 Pico + 1602 LCD 顯示內建溫度感測器讀取到的溫度資料
  3. 使用 Raspberry Pi 燒錄/除錯 Pico 程式(All)
  • getTemp.py
  • 取溫度程式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import utime
from machine import I2C, Pin, ADC
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd
I2C_ADDR = 63
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
def read_temp():
sensor_temp = ADC(4)
conversion_factor = 3.3 / (65535)
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
formatted_temperature = "{:.2f}".format(temperature)
string_temperature = str("Temp:" + formatted_temperature)
print(string_temperature)
utime.sleep(2)
return string_temperature
while True:
temperature = read_temp()
lcd.move_to(0,0)
lcd.putstr(temperature)
  1. 使用 VSCode 搭配 Pico 開發 MicroPython 程式