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.

For example:

import analogbufio
import array
from board import *

length = 5000000
mybuffer = array.array("H", 0x0000 for i in range(length))
adc_in = analogbufio.BufferedIn(GP26, mybuffer, length)

This example will initialize the the device, read and fill BufferedIn to mybuffer

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
  • Adafruit Feather RP2040
  • 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 SubGHz
  • Challenger RP2040 WiFi
  • Challenger RP2040 WiFi/BLE
  • Cytron Maker Nano RP2040
  • Cytron Maker Pi RP2040
  • 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
  • W5100S-EVB-Pico
  • W5500-EVB-Pico
  • Waveshare RP2040-Zero
  • WeAct Studio Pico
  • takayoshiotake Octave RP2040

class analogbufio.BufferedIn(pin: microcontroller.Pin, buffer: circuitpython_typing.WriteableBuffer, *, sample_rate: int = 500000)

Capture multiple analog voltage levels to the supplied buffer


import board
import analogbufio
import array

length = 1000
mybuffer = array.array("H", 0x0000 for i in range(length))
rate = 500000
adcbuf = analogbufio.BufferedIn(board.GP26, mybuffer, 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. ADC values will be read

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

  • pin (Pin) – the pin to read from

  • buffer (WriteableBuffer) – buffer: A buffer for samples

  • 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.

read() None

Fills the provided buffer with ADC voltage values.