machine.ADC.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. .. currentmodule:: machine
  2. .. _machine.ADC:
  3. class ADC -- analog to digital conversion
  4. =========================================
  5. Usage::
  6. import machine
  7. adc = machine.ADC() # create an ADC object
  8. apin = adc.channel(pin='GP3') # create an analog pin on GP3
  9. val = apin() # read an analog value
  10. Constructors
  11. ------------
  12. .. class:: ADC(id=0, \*, bits=12)
  13. Create an ADC object associated with the given pin.
  14. This allows you to then read analog values on that pin.
  15. For more info check the `pinout and alternate functions
  16. table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
  17. .. warning::
  18. ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
  19. can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
  20. ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
  21. then the maximum allowed input is 3.6V.
  22. Methods
  23. -------
  24. .. method:: ADC.channel(id, \*, pin)
  25. Create an analog pin. If only channel ID is given, the correct pin will
  26. be selected. Alternatively, only the pin can be passed and the correct
  27. channel will be selected. Examples::
  28. # all of these are equivalent and enable ADC channel 1 on GP3
  29. apin = adc.channel(1)
  30. apin = adc.channel(pin='GP3')
  31. apin = adc.channel(id=1, pin='GP3')
  32. .. method:: ADC.init()
  33. Enable the ADC block.
  34. .. method:: ADC.deinit()
  35. Disable the ADC block.
  36. class ADCChannel --- read analog values from internal or external sources
  37. =========================================================================
  38. ADC channels can be connected to internal points of the MCU or to GPIO pins.
  39. ADC channels are created using the ADC.channel method.
  40. .. method:: adcchannel()
  41. Fast method to read the channel value.
  42. .. method:: adcchannel.value()
  43. Read the channel value.
  44. .. method:: adcchannel.init()
  45. Re-init (and effectively enable) the ADC channel.
  46. .. method:: adcchannel.deinit()
  47. Disable the ADC channel.