### busio.SPI.frequency Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Gets or sets the actual SPI bus frequency. The actual frequency may differ from the requested frequency due to hardware limitations. ```APIDOC ## busio.SPI.frequency ### Description The actual SPI bus frequency. This may not match the frequency requested due to internal limitations. ### Method GET/SET (property access) ### Parameters #### Request Body (for setting) - **frequency** (int) - The desired SPI bus frequency. ### Request Example (setting) ```json { "frequency": 1000000 } ``` ### Response #### Success Response - **frequency** (int) - The actual SPI bus frequency. ### Response Example ```json { "frequency": 800000 } ``` ``` -------------------------------- ### configure() Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Configures the SPI bus. The SPI object must be locked. ```APIDOC ## configure() ### Description Configures the SPI bus. The SPI object must be locked. ### Parameters * **baudrate** (_int_) – the desired clock rate in Hertz. The actual clock rate may be higher or lower due to the granularity of available clock settings. Check the `frequency` attribute for the actual clock rate. * **polarity** (_int_) – the base state of the clock line (0 or 1) * **phase** (_int_) – the edge of the clock that data is captured. First (0) or second (1). Rising or falling depends on clock polarity. * **bits** (_int_) – the number of bits per word ### Notes On the SAMD21, it is possible to set the baudrate to 24 MHz, but that speed is not guaranteed to work. 12 MHz is the next available lower speed, and is within spec for the SAMD21. On the nRF52840, these baudrates are available: 125kHz, 250kHz, 1MHz, 2MHz, 4MHz, and 8MHz. If you pick a a baudrate other than one of these, the nearest lower baudrate will be chosen, with a minimum of 125kHz. Two SPI objects may be created, except on the Circuit Playground Bluefruit, which allows only one (to allow for an additional I2C object). ``` -------------------------------- ### busio.SPI Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Initializes an SPI controller for 3-4 wire serial communication. ```APIDOC ## busio.SPI ### Description Initializes an SPI controller for 3-4 wire serial communication. ### Parameters * **clock** (_microcontroller.Pin_) – The SPI clock pin. * **MOSI** (_microcontroller.Pin | None_) – The SPI Master Out Slave In pin. Defaults to None. * **MISO** (_microcontroller.Pin | None_) – The SPI Master In Slave Out pin. Defaults to None. * **half_duplex** (_bool_) – Specifies if the SPI interface is half-duplex. Defaults to False. ``` -------------------------------- ### busio.I2C Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Initializes an I2C controller. This class provides methods for I2C communication with external devices, including probing, scanning, and data transfer. ```APIDOC ## busio.I2C ### Description Initializes an I2C controller. This class provides methods for I2C communication with external devices, including probing, scanning, and data transfer. ### Parameters * **scl** (_Pin_) – The clock pin * **sda** (_Pin_) – The data pin * **frequency** (_int_) – The clock frequency in Hertz * **timeout** (_int_) – The maximum clock stretching timeout - (used only for `bitbangio.I2C`; ignored for `busio.I2C`) ### Methods #### deinit() -> None Releases control of the underlying hardware so other classes can use it. #### __enter__() -> I2C No-op used in Context Managers. #### __exit__() -> None Automatically deinitializes the hardware on context exit. See Lifetime and ContextManagers for more info. #### probe(_address : int_) -> bool Check if a device at the specified address responds. Parameters: * **address** (_int_) – 7-bit device address Returns: `True` if a device at `address` responds; `False` otherwise Return type: bool #### scan() -> List[int] Scan all I2C addresses between 0x08 and 0x77 inclusive and return a list of those that respond. Returns: List of device ids on the I2C bus Return type: list #### try_lock() -> bool Attempts to grab the I2C lock. Returns True on success. Returns: True when lock has been grabbed Return type: bool #### unlock() -> None Releases the I2C lock. #### readfrom_into(_address : int_, _buffer : circuitpython_typing.WriteableBuffer_, _*_ , _start : int = 0_, _end : int = sys.maxsize_) -> None Read into `buffer` from the device selected by `address`. At least one byte must be read. If `start` or `end` is provided, then the buffer will be sliced as if `buffer[start:end]` were passed, but without copying the data. The number of bytes read will be the length of `buffer[start:end]`. Parameters: * **address** (_int_) – 7-bit device address * **buffer** (_WriteableBuffer_) – buffer to write into * **start** (_int_) – beginning of buffer slice * **end** (_int_) – end of buffer slice; if not specified, use `len(buffer)` #### writeto(_address : int_, _buffer : circuitpython_typing.ReadableBuffer_, _*_ , _start : int = 0_, _end : int = sys.maxsize_) -> None Write the bytes from `buffer` to the device selected by `address` and then transmit a stop bit. If `start` or `end` is provided, then the buffer will be sliced as if `buffer[start:end]` were passed, but without copying the data. The number of bytes written will be the length of `buffer[start:end]`. Writing a buffer or slice of length zero is permitted, as it can be used to poll for the existence of a device. Parameters: * **address** (_int_) – 7-bit device address * **buffer** (_ReadableBuffer_) – buffer containing the bytes to write * **start** (_int_) – beginning of buffer slice * **end** (_int_) – end of buffer slice; if not specified, use `len(buffer)` #### writeto_then_readfrom(_address : int_, _out_buffer : circuitpython_typing.ReadableBuffer_, _in_buffer : circuitpython_typing.WriteableBuffer_, _*_ , _out_start : int = 0_, _out_end : int = sys.maxsize_, _in_start : int = 0_, _in_end : int = sys.maxsize_) -> None Write the bytes from `out_buffer` to the device selected by `address`, generate no stop bit, generate a repeated start and read into `in_buffer`. `out_buffer` and `in_buffer` can be the same buffer because they are used sequentially. If `out_start` or `out_end` is provided, then the buffer will be sliced as if `out_buffer[out_start:out_end]` were passed, but without copying the data. The number of bytes written will be the length of `out_buffer[start:end]`. If `in_start` or `in_end` is provided, then the input buffer will be sliced as if `in_buffer[in_start:in_end]` were passed, The number of bytes read will be the length of `out_buffer[in_start:in_end]`. Parameters: * **address** (_int_) – 7-bit device address * **out_buffer** (_ReadableBuffer_) – buffer containing the bytes to write * **in_buffer** (_WriteableBuffer_) – buffer to write into * **out_start** (_int_) – beginning of `out_buffer` slice * **out_end** (_int_) – end of `out_buffer` slice; if not specified, use `len(out_buffer)` * **in_start** (_int_) – beginning of `in_buffer` slice * **in_end** (_int_) – end of `in_buffer slice`; if not specified, use `len(in_buffer)` ``` -------------------------------- ### Initialize and Scan I2C Bus Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio This snippet shows how to initialize an I2C bus, lock it for exclusive access, scan for connected devices, unlock the bus, and finally deinitialize the hardware. It's useful for setting up and verifying I2C communication. ```python import busio from board import * i2c = busio.I2C(SCL, SDA) i2c.try_lock() print(i2c.scan()) i2c.unlock() i2c.deinit() ``` -------------------------------- ### busio.UART Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Initializes and configures a UART (Universal Asynchronous Receiver/Transmitter) bus for serial communication. It supports various parameters for baud rate, data bits, parity, stop bits, and timeouts. ```APIDOC ## busio.UART ### Description Initializes and configures a UART (Universal Asynchronous Receiver/Transmitter) bus for serial communication. It supports various parameters for baud rate, data bits, parity, stop bits, and timeouts. ### Parameters #### Path Parameters * **tx** (Pin) - The pin to transmit with, or `None` if this `UART` is receive-only. * **rx** (Pin) - The pin to receive on, or `None` if this `UART` is transmit-only. * **rts** (Pin) - The pin for rts, or `None` if rts not in use. * **cts** (Pin) - The pin for cts, or `None` if cts not in use. * **rs485_dir** (Pin) - The output pin for rs485 direction setting, or `None` if rs485 not in use. * **rs485_invert** (bool) - `rs485_dir` pin active high when set. Active low otherwise. * **baudrate** (int) - The transmit and receive speed. * **bits** (int) - The number of bits per byte, 5 to 9. * **parity** (Parity) - The parity used for error checking. * **stop** (int) - The number of stop bits, 1 or 2. * **timeout** (float) - The timeout in seconds to wait for the first character and between subsequent characters when reading. Raises `ValueError` if timeout >100 seconds. * **receiver_buffer_size** (int) - The character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * `receiver_buffer_size` bytes.) `tx` and `rx` cannot both be `None`. _New in CircuitPython 4.0:_ `timeout` has incompatibly changed units from milliseconds to seconds. The new upper limit on `timeout` is meant to catch mistaken use of milliseconds. **Limitations:** RS485 is not supported on SAMD, Nordic, Broadcom, Spresense, or STM. On i.MX and Raspberry Pi RP2040, RS485 support is implemented in software: The timing for the `rs485_dir` pin signal is done on a best-effort basis, and may not meet RS485 specifications intermittently. ### Methods #### deinit() → None Deinitializes the UART and releases any hardware resources for reuse. #### __enter__() → UART No-op used by Context Managers. #### __exit__() → None Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info. #### read(_nbytes : int | None = None_) → bytes | None Read bytes. If `nbytes` is specified then read at most that many bytes. Otherwise, read everything that arrives until the connection times out. Providing the number of bytes expected is highly recommended because it will be faster. If no bytes are read, return `None`. Note When no bytes are read due to a timeout, this function returns `None`. This matches the behavior of `io.RawIOBase.read` in Python 3, but differs from pyserial which returns `b''` in that situation. Returns: Data read Return type: bytes or None #### readinto(_buf : circuitpython_typing.WriteableBuffer_) → int | None Read bytes into the `buf`. Read at most `len(buf)` bytes. Returns: number of bytes read and stored into `buf` Return type: int or None (on a non-blocking error) _New in CircuitPython 4.0:_ No length parameter is permitted. #### readline() → bytes Read a line, ending in a newline character, or return `None` if a timeout occurs sooner, or return everything readable if no newline is found and `timeout=0` Returns: the line read Return type: bytes or None #### write(_buf : circuitpython_typing.ReadableBuffer_) → int | None Write the buffer of bytes to the bus. _New in CircuitPython 4.0:_ `buf` must be bytes, not a string. return: the number of bytes written rtype: int or None ### Attributes #### baudrate _: int_ The current baudrate. #### in_waiting _: int_ The number of bytes in the input buffer, available to be read #### timeout _: float_ The current timeout, in seconds (float). ### Other Methods #### reset_input_buffer() → None Discard any unread characters in the input buffer. ``` -------------------------------- ### busio.SPI Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Constructs an SPI object on the given pins. This class acts as an SPI main (controller). For SPI secondary (target) functionality, use `spitarget.SPITarget`. ```APIDOC ## busio.SPI ### Description Constructs an SPI object on the given pins. This class acts as an SPI main (controller). For SPI secondary (target) functionality, use `spitarget.SPITarget`. ### Parameters * **clock** (_Pin_) – the pin to use for the clock. * **MOSI** (_Pin_) – the Main Out Selected In pin. * **MISO** (_Pin_) – the Main In Selected Out pin. * **half_duplex** (_bool_) – True when MOSI is used for bidirectional data. False when SPI is full-duplex or simplex. Available only on STM; other chips do not have the hardware support. ### Limitations `half_duplex` is available only on STM; other chips do not have the hardware support. ``` -------------------------------- ### busio.UART Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Initializes a UART (Universal Asynchronous Receiver/Transmitter) object for bidirectional serial communication. Supports various pins for TX, RX, RTS, CTS, and RS485 direction control, along with configurable baud rate, data bits, parity, stop bits, and timeout. ```APIDOC ## busio.UART ### Description A bidirectional serial protocol. ### Method Constructor ### Parameters - **tx** (microcontroller.Pin | None) - Optional - Transmit pin. - **rx** (microcontroller.Pin | None) - Optional - Receive pin. - **rts** (microcontroller.Pin | None) - Optional - Request To Send pin (for hardware flow control). - **cts** (microcontroller.Pin | None) - Optional - Clear To Send pin (for hardware flow control). - **rs485_dir** (microcontroller.Pin | None) - Optional - RS485 direction control pin. - **rs485_invert** (bool) - Optional - If True, invert the RS485 direction signal. - **baudrate** (int) - Optional - The baud rate for serial communication (default is 9600). - **bits** (int) - Optional - The number of data bits (default is 8). - **parity** (Parity | None) - Optional - The parity setting (None, Parity.ODD, Parity.EVEN). - **stop** (int) - Optional - The number of stop bits (default is 1). - **timeout** (float) - Optional - The read timeout in seconds (default is 1). - **receiver_buffer_size** (int) - Optional - The size of the receiver buffer (default is 64). ### Request Example ```json { "tx": "pin_object_tx", "rx": "pin_object_rx", "baudrate": 115200, "timeout": 0.5 } ``` ### Response #### Success Response - **uart_object** (busio.UART) - The initialized UART object. ### Response Example ```json { "uart_object": "" } ``` ``` -------------------------------- ### Busio Module Overview Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio The `busio` module in CircuitPython offers hardware-accelerated interfaces for external bus communication. It supports I2C, SPI, and UART protocols, allowing for efficient interaction with a wide range of peripherals. ```APIDOC ## busio Module ### Description Provides hardware-accelerated external bus access. ### Sub-modules - **I2C**: Interface for I2C communication. - **SPI**: Interface for SPI communication. - **UART**: Interface for UART communication. ``` -------------------------------- ### busio.I2C Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio The I2C class implements the two-wire serial protocol for communication between devices using SCL (clock) and SDA (data) lines. It is recommended to use I2CDevice for managing locks when using this class directly. ```APIDOC ## busio.I2C ### Description Implements the two-wire serial protocol for communication between devices. At the physical level it consists of 2 wires: SCL and SDA, the clock and data lines respectively. ### Method I2C ### Parameters - **_scl** (microcontroller.Pin) - The SCL pin. - **_sda** (microcontroller.Pin) - The SDA pin. - **frequency** (int) - Optional. The I2C clock frequency in Hz. Defaults to 100000. - **timeout** (int) - Optional. The I2C timeout in milliseconds. Defaults to 255. ### See Also Using this class directly requires careful lock management. Instead, use `I2CDevice` to manage locks. ``` -------------------------------- ### busio.SPI.write_readinto Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Performs a simultaneous write and read operation on the SPI bus. Data is written from `out_buffer` while data is read into `in_buffer`. The SPI object must be locked. Supports slicing for both buffers, and the lengths of the slices must be equal. ```APIDOC ## busio.SPI.write_readinto ### Description Write out the data in `out_buffer` while simultaneously reading data into `in_buffer`. The SPI object must be locked. If `out_start` or `out_end` is provided, then the buffer will be sliced as if `out_buffer[out_start:out_end]` were passed, but without copying the data. The number of bytes written will be the length of `out_buffer[out_start:out_end]`. If `in_start` or `in_end` is provided, then the input buffer will be sliced as if `in_buffer[in_start:in_end]` were passed, The number of bytes read will be the length of `out_buffer[in_start:in_end]`. The lengths of the slices defined by `out_buffer[out_start:out_end]` and `in_buffer[in_start:in_end]` must be equal. If buffer slice lengths are both 0, nothing happens. ### Method POST (or similar, as it's a method call) ### Parameters #### Request Body - **out_buffer** (ReadableBuffer) - write out bytes from this buffer - **in_buffer** (WriteableBuffer) - read bytes into this buffer - **out_start** (int) - Optional - beginning of `out_buffer` slice - **out_end** (int) - Optional - end of `out_buffer` slice; if not specified, use `len(out_buffer)` - **in_start** (int) - Optional - beginning of `in_buffer` slice - **in_end** (int) - Optional - end of `in_buffer slice`; if not specified, use `len(in_buffer)` ### Request Example ```json { "out_buffer": "data_to_write", "in_buffer": "destination_buffer", "out_start": 0, "out_end": 5, "in_start": 0, "in_end": 5 } ``` ### Response #### Success Response - **return_value** (None) - Indicates successful write-read operation. ### Response Example ```json { "return_value": null } ``` ``` -------------------------------- ### busio.Parity Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Enum-like class to define the parity used for error checking during data transfer. ```APIDOC ## busio.Parity ### Description Enum-like class to define the parity used for error checking during data transfer. ### Members #### ODD _: int_ Total number of ones should be odd. #### EVEN _: int_ Total number of ones should be even. ``` -------------------------------- ### deinit() Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Turns off the SPI bus. ```APIDOC ## deinit() ### Description Turn off the SPI bus. ``` -------------------------------- ### busio.SPI.write Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Writes data from a buffer to the SPI bus. The SPI object must be locked before calling this method. Supports slicing the buffer for partial writes. ```APIDOC ## busio.SPI.write ### Description Write the data contained in `buffer`. The SPI object must be locked. If the buffer is empty, nothing happens. If `start` or `end` is provided, then the buffer will be sliced as if `buffer[start:end]` were passed, but without copying the data. The number of bytes written will be the length of `buffer[start:end]`. ### Method POST (or similar, as it's a method call) ### Parameters #### Request Body - **buffer** (ReadableBuffer) - write out bytes from this buffer - **start** (int) - Optional - beginning of buffer slice - **end** (int) - Optional - end of buffer slice; if not specified, use `len(buffer)` ### Request Example ```json { "buffer": "data_to_write", "start": 0, "end": 5 } ``` ### Response #### Success Response - **return_value** (None) - Indicates successful write operation. ### Response Example ```json { "return_value": null } ``` ``` -------------------------------- ### busio.SPI.readinto Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Reads data from the SPI bus into a buffer while simultaneously writing a specified value for each byte read. The SPI object must be locked. Supports slicing the buffer for partial reads. ```APIDOC ## busio.SPI.readinto ### Description Read into `buffer` while writing `write_value` for each byte read. The SPI object must be locked. If the number of bytes to read is 0, nothing happens. If `start` or `end` is provided, then the buffer will be sliced as if `buffer[start:end]` were passed. The number of bytes read will be the length of `buffer[start:end]`. ### Method GET (or similar, as it's a method call) ### Parameters #### Request Body - **buffer** (WriteableBuffer) - read bytes into this buffer - **start** (int) - Optional - beginning of buffer slice - **end** (int) - Optional - end of buffer slice; if not specified, it will be the equivalent value of `len(buffer)` and for any value provided it will take the value of `min(end, len(buffer))` - **write_value** (int) - Optional - value to write while reading ### Request Example ```json { "buffer": "destination_buffer", "start": 0, "end": 10, "write_value": 0 } ``` ### Response #### Success Response - **return_value** (None) - Indicates successful read operation. ### Response Example ```json { "return_value": null } ``` ``` -------------------------------- ### busio.SPI.try_lock Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Attempts to acquire the SPI bus lock. This method is useful for ensuring exclusive access to the SPI bus before performing operations. ```APIDOC ## busio.SPI.try_lock ### Description Attempts to grab the SPI lock. Returns True on success. ### Method GET (or similar, as it's a method call) ### Parameters None ### Response #### Success Response - **return_value** (bool) - True when lock has been grabbed ### Response Example ```json { "return_value": true } ``` ``` -------------------------------- ### busio.SPI.unlock Source: https://docs.circuitpython.org/en/latest/shared-bindings/busio Releases the SPI bus lock, allowing other processes or devices to access the bus. ```APIDOC ## busio.SPI.unlock ### Description Releases the SPI lock. ### Method POST (or similar, as it's a method call) ### Parameters None ### Response #### Success Response - **return_value** (None) - Indicates successful release of the lock. ### Response Example ```json { "return_value": null } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.