EasyManuals Logo

Adafruit Feather M4 Express User Manual

Adafruit Feather M4 Express
178 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 #104 background imageLoading...
Page #104 background image
CircuitPython Analog In
This example shows you how you can read the analog voltage on the A1 pin on your board.
Copy and paste the code into code.py using your favorite editor, and save the file to run the demo.
Creating the analog input
analog1in = AnalogIn(board.A1)
Creates an object and connects the object to A1 as an analog input.
get_voltage Helper
getVoltage(pin) is our little helper program. By default, analog readings will range from 0 (minimum) to 65535
(maximum). This helper will convert the 0-65535 reading from pin.value and convert it a 0-3.3V voltage reading.
Main Loop
The main loop is simple. It prints out the voltage as floating point values by calling get_voltage on our analog object.
Connect to the serial console to see the results.
# CircuitPython AnalogIn Demo
import time
import board
from analogio import AnalogIn
analog_in = AnalogIn(board.A1)
def get_voltage(pin):
return (pin.value * 3.3) / 65536
while True:
print((get_voltage(analog_in),))
time.sleep(0.1)
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 109 of 183

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit Feather M4 Express and is the answer not in the manual?

Adafruit Feather M4 Express Specifications

General IconGeneral
BrandAdafruit
ModelFeather M4 Express
CategoryMicrocontrollers
LanguageEnglish

Related product manuals