Raspberry Pico上有四个 ADC 可用
- ADC0 引脚 31 (GP26)
- ADC1 引脚 32 (GP27)
- ADC2 引脚 34 (GP28)
ADC 引脚的输入电压范围为 0V ..3.3V
此外,还有另一个板载 ADC 输入(ADC4),它连接到芯片上的温度传感器。
在lazarus建个控制台应用
此示例说明如何读取模拟引脚(ADC0)和内部传感器(ADC4)。
program adc; {$MODE OBJFPC} {$H+} {$MEMORY 10000,10000} uses pico_gpio_c, pico_adc_c, pico_timer_c, pico_c; var milliVolts,milliCelsius : longWord; begin adc_init; // Make sure GPIO is high-impedance, no pullups etc adc_gpio_init(TPicoPin.ADC0); // Turn on the Temperature sensor adc_set_temp_sensor_enabled(true); repeat // Select ADC input 0 (GPIO26) adc_select_input(0); // For now we avoid floating point, there have been fixes done on FPC trunk which are yet to be verified milliVolts := (adc_read * 3300) div 4096; // Select internal temperature sensor adc_select_input(4); milliVolts := (adc_read * 3300) div 4096; //Temperature formula is : T = 27 - (ADC_voltage - 0.706)/0.001721 milliCelsius := 27000-(milliVolts-706)*581; busy_wait_us_32(500000); until 1=0; end.
对 ADC 进行编程时,或多或少只有一件事需要注意,引脚配置了它们的 GPIO 值(26、27、28),但在选择 ADC 输入时,我们需要按名称引用 ADC 输入
- ADC0 --> 0
- ADC1 --> 1
- ADC2 --> 2
- ADC4 --> 4

浙公网安备 33010602011771号