需要的材料
1.溫度傳感器模塊:
我購買的是某寶上3塊錢的“DS18B20溫度傳感器模塊”

2.杜邦線:某寶幾塊錢一組40P,這里只需要三根,用於連接 樹莓派與溫度傳感器

樹莓派PICO GPIO 說明
GPIO是(General Purpose Input Output)的縮寫,也就是通用輸入輸出,是一種常見的硬件接口,用以表示開關量。

物理連接
1.連線圖:
Python 控制腳本
去樹莓派PICO中文站 現在載入載入MicroPython到樹莓派PICO中
去 Thonny, Python IDE for beginners 下載 Thonny Python IDE
代碼如下:
import machine, onewire, ds18x20, time ds_pin=machine.Pin(4) #我將傳感器連接到GO4 這里為:4 ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin)) #創建onewire總線 引腳4(GO4) roms = ds_sensor.scan() #掃描總線上的設備 print('Found DS devices: ', roms) while True: ds_sensor.convert_temp() #獲取采樣溫度 time.sleep_ms(750) for rom in roms: print(rom) print(ds_sensor.read_temp(rom)) #得到溫度 time.sleep(2)
運行結果如下

