EasyManuals Logo

Adafruit ESP32-S3 User Manual

Adafruit ESP32-S3
263 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #136 background imageLoading...
Page #136 background image
Then, you set up the analog pin by creating an analogio.AnalogIn() object,
providing it the desired pin using the board module, and saving it to the variable
analog_pin .
Finally, in the loop, you print out the analog value with analog_pin.value , including
a time.sleep() to slow down the values to a human-readable rate.
Reading Analog Voltage Values
These values don't necessarily equate to anything obvious. You can get an idea of the
rotation of the potentiometer based on where in the range the value falls, but not
without doing some math. Remember, you wired up the potentiometer as a voltage
divider. By adding a simple function to your code, you can get a more human-
readable value from the potentiometer.
You'll need to connect to the serial console() to see the values printed out.
In the example below, click the Download Project Bundle button below to download
the necessary libraries and the code.py file in a zip file. Extract the contents of the zip
file, open the directory Adafruit_ESP32-S3_TFT_Feather/analogin/ and then click on
the directory that matches the version of CircuitPython you're using and copy the
contents of that directory to your CIRCUITPY drive.
Your CIRCUITPY drive should now look similar to the following image:
# SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
CircuitPython analog voltage value example
"""
import time
import board
import analogio
analog_pin = analogio.AnalogIn(board.A0)
def get_voltage(pin):
return (pin.value * 3.1) / 61000
©Adafruit Industries Page 136 of 263

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit ESP32-S3 and is the answer not in the manual?

Adafruit ESP32-S3 Specifications

General IconGeneral
BrandAdafruit
ModelESP32-S3
CategoryMicrocontrollers
LanguageEnglish

Related product manuals