Basic usage
Import Pyb
ADC = Pyb. ADC (Pin (' Y11 ')) # Create an analog object from a PIN
ADC = Pyb. ADC (Pyb. PIN.BOARD.Y11)
val = Adc.read () # read an analog value
ADC = Pyb. Adcall (resolution) # Creale an Adcall object
val = Adc.read_channel (channel) # Read the given channel
val = adc.read_core_temp () # Read MCU temperature
val = Adc.read_core_vbat () # Read MCU Vbat
val = Adc.read_core_vref () # Read MCU Vref
Pyb. ADC (PIN)
Defining an ADC with a Gpio
Pyb. Adcall (resolution)
Defines the resolution of the ADC and can be set to 8/10/12
Adc.read ()
Reads the ADC value, the return value is related to the ADC resolution, 8-bit maximum 255, 10-bit maximum 1023, 12-bit maximum 4095
Adc.read_channel (channel)
Reads the value of the specified ADC channel
Adc.read_core_temp ()
Reading the internal temperature sensor
Adc.read_core_vbat ()
Read Vbat voltage
Vback = Adc.read_core_vbat () * 1.21/ADC.READ_CORE_VREF ()
Adc.read_core_vref ()
Read Vref voltage (1.21V Reference)
3V3 = 3.3 * 1.21/ADC.READ_CORE_VREF ()
Adc.read_timed (buf, timer)
Read the ADC parameters to BUF at a specified frequency
BUF, Buffer
Timer, frequency (Hz)
Using this function limits the ADC's results to 8 bits
ADC = Pyb. ADC (Pyb. PIN.BOARD.X19) # Create an ADC on pin X19
BUF = ByteArray (+) # Create a buffer of up to bytes
Adc.read_timed (BUF, ten) # Read analog values into BUF at 10Hz
#this'll take ten seconds to finish
For Val in buf: # Loop through all values
Print (val) # Print the value out
How to use the Micropython Tpyboard ADC