• sales

    +86-0755-88291180

【MicroPython】machine.ADC Function

  • machine.ADC(id):
    • ADC object constructor, and initialize the corresponding channel.
    • id: can be a GPIO object or an ADC channel;

The ADC object constructor is used to initialize the corresponding ADC channel. The parameter ID is the ADC channel used. You can use the Pin object or directly specify the ADC channel.

When using the Pin object, the specified GPIO needs to support the ADC function, namely GPIO26-29;

Use the specified ADC channel, channel 0-3 corresponds to GPIO26-29, channel number 4 corresponds to the internal temperature sensor.

  • ADC.read_u16():
    • Read the ADC value of the corresponding channel

The read_u16 function reads the corresponding channel ADC and returns the read value;

It should be noted here that the return value of this function does not directly return the value read by the ADC, but the processed value, and its value range is 0-65535;

Therefore, the ADC voltage calculation formula should be:

Vin =\frac{3.3*ReadData}{65535}Vin=655353.3∗ReadData​
The ADC read voltage is 3.3 times the return value divided by 65535 in V
This article is only for RP2040 MicroPython firmware, and the source code shall prevail. This article is written according to the official source code at the time of writing, which is used to provide convenience for beginners and is for reference only. Those who are capable are recommended to refer to MicroPython.

TAG: Xiaozhi-AI-video-tutorial-2 Program Raspberry Pi 5 PD Activation Module RISC-V Mobile Robot Finger Vein Scanner Module (B) Cortex M4F UART serial port EAL4+ security certification qualification SpotPear Raspberry Pi 21.5inch FHD LCD 1080x1920 Capacitive TouchScreen Display For Raspberry Pi/Jetson Nano/ Changeable Photo Frames Raspberry Pi 5 Audio DeepSeek AI Voice Chat ESP32 S3 Development Board 1.85 inch Round LCD 1.85inch Display QMI8658 /MIC /SD /MP3 Audio LVGL For Arduino Raspberry Pi 13.3 inch FHD Monitor LCD 1080P Capacitive TouchScreen Display Type-C/HDMI For Computer PC HDMI to LVDS 15.6 inch Dual LCD Computer PC Monitor Display Double Secondary Screen Type C Mini HDMI 1080P For Windows/MacOS TOF Time of Flight Laser Range Sensor Mini Radar module UART Serial / I2C Port For Arduino / Raspberry Pi / ESP32 ESP32 P4 Development Board 7-inch LCD Display 1024×600 7inch Touchscreen ESP32-C6 WiFi6 AI Deepseek Milk-V Duo RJ45 ESP32-S3 0.85inch LCD Milk-V Duo Tutorial DeepSeek AI Voice Chat ESP32 C6 Development Board 1.69 inch LCD Display 240x280 1.69inch TouchScreen Programmable Watch