analogbufio – Analog Buffered IO Hardware Support

The analogbufio module contains classes to provide access to analog-to-digital conversion and digital-to-analog (DAC) for multiple value transfer.

All classes change hardware state and should be deinitialized when they are no longer needed if the program continues after use. To do so, either call deinit() or use a context manager. See Lifetime and ContextManagers for more info.

TODO: For the essentials of analogbufio, see the CircuitPython Essentials Learn guide

TODO: For more information on using analogbufio, see this additional Learn guide

Available on these boards
  • 0xCB Helios
  • 42. Keebs Frood
  • Adafruit Feather RP2040
  • Adafruit Feather RP2040 Scorpio
  • Adafruit ItsyBitsy RP2040
  • Adafruit KB2040
  • Adafruit Macropad RP2040
  • Adafruit QT Py RP2040
  • Adafruit QT2040 Trinkey
  • Arduino Nano RP2040 Connect
  • BBQ20KBD
  • Challenger NB RP2040 WiFi
  • Challenger RP2040 LTE
  • Challenger RP2040 LoRa
  • Challenger RP2040 SD/RTC
  • Challenger RP2040 SubGHz
  • Challenger RP2040 WiFi
  • Challenger RP2040 WiFi/BLE
  • Cytron Maker Nano RP2040
  • Cytron Maker Pi RP2040
  • E-Fidget
  • Electrolama minik
  • EncoderPad RP2040
  • Fig Pi
  • Melopero Shake RP2040
  • Oak Dev Tech BREAD2040
  • Oak Dev Tech Cast-Away RP2040
  • Pimoroni Badger 2040
  • Pimoroni Interstate 75
  • Pimoroni Keybow 2040
  • Pimoroni Motor 2040
  • Pimoroni PGA2040
  • Pimoroni Pico LiPo (16MB)
  • Pimoroni Pico LiPo (4MB)
  • Pimoroni PicoSystem
  • Pimoroni Plasma 2040
  • Pimoroni Servo 2040
  • Pimoroni Tiny 2040 (2MB)
  • Pimoroni Tiny 2040 (8MB)
  • PyKey 18 Numpad
  • PyKey 44 Ergo
  • PyKey 60
  • PyKey 87 TKL
  • RP2.65-F
  • RP2040 Stamp
  • Raspberry Pi Pico
  • Raspberry Pi Pico W
  • Seeeduino XIAO RP2040
  • Silicognition LLC RP2040-Shim
  • SparkFun MicroMod RP2040 Processor
  • SparkFun Pro Micro RP2040
  • SparkFun Thing Plus - RP2040
  • VCC-GND Studio YD RP2040
  • W5100S-EVB-Pico
  • W5500-EVB-Pico
  • Waveshare RP2040-LCD-1.28
  • Waveshare RP2040-Zero
  • WeAct Studio Pico
  • WeAct Studio Pico 16MB
  • nullbits Bit-C PRO
  • takayoshiotake Octave RP2040

class analogbufio.BufferedIn(pin: microcontroller.Pin, *, sample_rate: int)

Capture multiple analog voltage levels to the supplied buffer


import board
import analogbufio
import array

length = 1000
mybuffer = array.array("H", [0x0000] * length)
rate = 500000
adcbuf = analogbufio.BufferedIn(board.GP26, sample_rate=rate)
for i in range(length):
    print(i, mybuffer[i])

(TODO) The reference voltage varies by platform so use
``reference_voltage`` to read the configured setting.
(TODO) Provide mechanism to read CPU Temperature.

Create a BufferedIn on the given pin and given sample rate.

  • pin (Pin) – the pin to read from

  • sample_rate (~int) – rate: sampling frequency, in samples per second

deinit() None

Shut down the BufferedIn and release the pin for other use.

__enter__() BufferedIn

No-op used by Context Managers.

__exit__() None

Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

readinto(buffer: circuitpython_typing.WriteableBuffer) int

Fills the provided buffer with ADC voltage values.

ADC values will be read into the given buffer at the supplied sample_rate. Depending on the buffer typecode, ‘B’, ‘H’, samples are 8-bit byte-arrays or 16-bit half-words and are always unsigned. The ADC most significant bits of the ADC are kept. (See


buffer (WriteableBuffer) – buffer: A buffer for samples