2016-06-07 17:46:27 -04:00
|
|
|
.. currentmodule:: machine
|
2019-09-04 01:05:03 -04:00
|
|
|
.. _machine.ADCWiPy:
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2019-09-04 01:05:03 -04:00
|
|
|
class ADCWiPy -- analog to digital conversion
|
|
|
|
=============================================
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
This class is a non-standard ADC implementation for the WiPy.
|
|
|
|
It is available simply as ``machine.ADC`` on the WiPy but is named in the
|
|
|
|
documentation below as ``machine.ADCWiPy`` to distinguish it from the
|
|
|
|
more general :ref:`machine.ADC <machine.ADC>` class.
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
Usage::
|
|
|
|
|
|
|
|
import machine
|
|
|
|
|
|
|
|
adc = machine.ADC() # create an ADC object
|
|
|
|
apin = adc.channel(pin='GP3') # create an analog pin on GP3
|
|
|
|
val = apin() # read an analog value
|
|
|
|
|
|
|
|
Constructors
|
|
|
|
------------
|
|
|
|
|
2020-07-11 02:53:26 -04:00
|
|
|
.. class:: ADCWiPy(id=0, *, bits=12)
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
Create an ADC object associated with the given pin.
|
|
|
|
This allows you to then read analog values on that pin.
|
|
|
|
For more info check the `pinout and alternate functions
|
2021-12-14 19:49:22 -05:00
|
|
|
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2021-12-14 19:49:22 -05:00
|
|
|
.. warning::
|
2015-10-14 06:32:01 -04:00
|
|
|
|
2021-12-14 19:49:22 -05:00
|
|
|
ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
|
|
|
|
can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
|
|
|
|
ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
|
2015-10-14 06:32:01 -04:00
|
|
|
then the maximum allowed input is 3.6V.
|
|
|
|
|
|
|
|
Methods
|
|
|
|
-------
|
|
|
|
|
2020-07-11 02:53:26 -04:00
|
|
|
.. method:: ADCWiPy.channel(id, *, pin)
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
Create an analog pin. If only channel ID is given, the correct pin will
|
|
|
|
be selected. Alternatively, only the pin can be passed and the correct
|
|
|
|
channel will be selected. Examples::
|
|
|
|
|
|
|
|
# all of these are equivalent and enable ADC channel 1 on GP3
|
|
|
|
apin = adc.channel(1)
|
|
|
|
apin = adc.channel(pin='GP3')
|
|
|
|
apin = adc.channel(id=1, pin='GP3')
|
|
|
|
|
2019-09-04 01:05:03 -04:00
|
|
|
.. method:: ADCWiPy.init()
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
Enable the ADC block.
|
|
|
|
|
2019-09-04 01:05:03 -04:00
|
|
|
.. method:: ADCWiPy.deinit()
|
2015-10-14 06:32:01 -04:00
|
|
|
|
|
|
|
Disable the ADC block.
|
|
|
|
|
|
|
|
class ADCChannel --- read analog values from internal or external sources
|
|
|
|
=========================================================================
|
|
|
|
|
|
|
|
ADC channels can be connected to internal points of the MCU or to GPIO pins.
|
|
|
|
ADC channels are created using the ADC.channel method.
|
|
|
|
|
|
|
|
.. method:: adcchannel()
|
|
|
|
|
|
|
|
Fast method to read the channel value.
|
|
|
|
|
|
|
|
.. method:: adcchannel.value()
|
|
|
|
|
|
|
|
Read the channel value.
|
|
|
|
|
|
|
|
.. method:: adcchannel.init()
|
|
|
|
|
|
|
|
Re-init (and effectively enable) the ADC channel.
|
|
|
|
|
|
|
|
.. method:: adcchannel.deinit()
|
|
|
|
|
|
|
|
Disable the ADC channel.
|