LoginSignup
0
4

More than 1 year has passed since last update.

Raspberry Pi Pico Wの温度センサー【MicroPython】

Last updated at Posted at 2022-08-30
main.py
import machine
import utime

# 温度センサが接続されている、
# 4つ目の ADC(アナログデジタルコンバータ) を取得します
sensor_temp = machine.ADC(4)
# ADCの最大電圧3.3Vを16bit(65535)で割って、
# 16bitの 1 目盛りのあたりの電圧(変換係数)を計算します( 約 0.00005V)
conversion_factor = 3.3 / (65535)

while True:
    # センサから取得した値(0~65535) を電圧に変換します。
    reading = sensor_temp.read_u16() * conversion_factor
    # 温度を計算します。センサは27度を基準にしているため、
    # 温度センサの数値を27度から引いて計算します。
    temperature = 27 - (reading - 0.706)/0.001721
    print(temperature)
    utime.sleep(2)

image.png

ezgif-1-61e2f0cdfd.gif

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4