4.ADC采样测试
该教程演示如何通过开发板实现ADC采样测试,此处以读取开发板芯片内部的温度为例。
一、准备工作
- 准备1块BearPi-Pico RP2040开发板
二、编写代码
点击加号新建文件。
编写ADC采样测试的程序,将以下代码复制到新建的文件中。
import machine import utime sensor_temp = machine.ADC(4) conversion_factor = 3.3 / (65535) while True: reading = sensor_temp.read_u16() * conversion_factor # The temperature sensor measures the Vbe voltage of a biased bipolar diode, connected to the fifth ADC channel # Typically, Vbe = 0.706V at 27 degrees C, with a slope of -1.721mV (0.001721) per degree. temperature = 27 - (reading - 0.706)/0.001721 print(temperature) utime.sleep(2)
"ctrl+s"将文件保存到电脑中。
三、测试
点击运行,观察开发板的日志打印 。
35.93917 35.93917 39.21618 36.87546 36.87546 38.27989 37.34361 37.81175