How to use the Micropython Tpyboard ADC

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.