采集内部温度传感器数据的测试代码:
from machine import ADC
from time import sleep
# 初始化内部温度传感器 (ADC4)
sensor = ADC(4)
# 转换系数 (3.3V / 65535)
CONV_FACTOR = 3.3 / 65535
def get_temperature():
# 读取原始值并转换为电压
raw = sensor.read_u16()
voltage = raw * CONV_FACTOR
# 根据 RP2040 数据手册的公式转换: 27 - (电压 - 0.706) / 0.001721
# 其中 0.706 为 27度时的电压,0.001721 为温度系数
temperature = 27 - (voltage - 0.706) / 0.001721
return temperature
while True:
temp = get_temperature()
print(f"Raw: {sensor.read_u16()}, Temperature: {temp:.2f} C")
sleep(1)测试结果:

漂移比较明显。
我要赚赏金
