Pymate-Analog: Difference between revisions
| Line 26: | Line 26: | ||
Keep in mind that code cannot create better resolution that hardware does!}} | Keep in mind that code cannot create better resolution that hardware does!}} | ||
Pymate ADCs have 12 bits resolution meaning that maximum accuracy is 2.44 mV (10 Volts / 4095). | |||
=== Wiring === | === Wiring === | ||
Revision as of 17:40, 30 April 2026
Important note
Charts and graphics are made to be easy to follow.
The Pymate boards are drawed without connectors to avoids parallax shift. The real board are fitted with the connectors.
Analog Input
Any of the output pin can be switched from digital input to Analog Input.
Analog Input can read the value of the DC voltage applied to the analog Input pin.
As the voltage is read through and Analog-to-Digital converter, the resulting value will be an unsigned integer.
As MicroPython defines the ADC.read_u16() method returning an unsigned 16 bits value (0 .. 65535).
Getting an uniform result encoded over 16bits makes the user script independent of the effective hardware resolution of the analog converter.
This means that read_u16() may returns an upscaled value when ADC converter offers lower resolution (below 16bits).
Keep in mind that code cannot create better resolution that hardware does!Pymate ADCs have 12 bits resolution meaning that maximum accuracy is 2.44 mV (10 Volts / 4095).
Wiring
Coding
The following example query the state if imput 3 and displays the results on the REPL session.
from pymate.pymateio import PymateIO
from machine import ADC
import time
a4 = PymateIO( "IN4", ADC )
while True:
print( "Adc 4 RAW = %s" % a4.read_u16() )
time.sleep( 0.2 )Which would display values between 0 and 65535 in the REPL.
PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO