analogbufio – Analog Buffered IO Hardware Support¶
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
deinit() or use a context manager. See
Lifetime and ContextManagers for more info.
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) analogbufio.read() print(*mybuffer) adc_in.deinit()
This example will initialize the the device, read and fill
BufferedIn to mybuffer
Available on these boards
- 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) adcbuf.read() adcbuf.deinit() 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
BufferedInon 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 https://docs.circuitpython.org/en/latest/docs/library/array.html)
pin (Pin) – the pin to read from
buffer (WriteableBuffer) – buffer: A buffer for samples
sample_rate (~int) – rate: sampling frequency, in samples per second
- __exit__() None ¶
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
- Create a