• 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: ESP32‑S3 13.3-inch E6 Full-Color E-Ink e-Paper Display Integrated capacitive fingerprint module Cortex core UART serial port High-precision fingerprint recognition Raspberry Pi 5 27W Power ESP32-P4-WIFI6 3.5inch LCD Display AI Development Board 320×480 3.5 inch TouchScreen Deepseek Milk-V Duo RJ45 RDK X5 PoE Module For Power Over Ethernet/ IEEE 802.3af/at PoE For D-Robotics RDK X5 Raspberry Pi Pico 2 RP2350 With 0.96 inch LCD Display 0.96inch Screen 160×80 Onboard RP2350A Raspberry Pi Pico Raspberry Pi USB Camera 12MP IMX378 30fps onboard dual microphones Also For Jeston / RDK spotpear Sipeed Lichee Tang Nano1K FPGA MINI Development Board GW1NZ-1 Raspberry Pi 5 PCIe to M.2 Multi Function Adapter Board Supports Dual 4K HDMI Output AI Board ESP32 1.5inch LCD ESP32 1.9 inch LCD Capacitive TouchScreen 1.9inch Display ST7789 170x320 for Arduino /Raspberry Pi /Pico Raspberry Pi 5 RTC Battery ESP32-S3 Development Board 1.85 inch Round LCD N16R8 DeepSeek AI Voice Chat Robot BOX Magnetic-charging Finger Vein Scanner Module (B) Cortex M4F UART serial port EAL4+ security certification qualification SpotPear Raspberry Pi RP2040 LoRa-HF