### Install i2cdriver Source: https://i2cdriver.readthedocs.io/en/latest Install the package from PyPI using pip. ```bash $ pip install i2cdriver ``` -------------------------------- ### Write Bytes to I2C Device Source: https://i2cdriver.readthedocs.io/en/latest Start a transaction, write a sequence of bytes, and stop the transaction. ```python >>> i2c.start(0x75, 0) >>> i2c.write([0x12,034]) >>> i2c.stop() ``` -------------------------------- ### Connect and Scan I2C Bus Source: https://i2cdriver.readthedocs.io/en/latest Initialize the I2CDriver on a specific port and perform a bus scan to identify connected devices. ```python >>> import i2cdriver >>> i2c = i2cdriver.I2CDriver("/dev/ttyUSB0") >>> i2c.scan() -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1C -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [28, 72, 104] ``` -------------------------------- ### Perform I2C Bus Scan Source: https://i2cdriver.readthedocs.io/en/latest Execute a bus scan to print a device map and return a list of active addresses. ```python >>> i2c.scan() -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1C -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- [28, 72, 104] ``` -------------------------------- ### Write Device Registers Source: https://i2cdriver.readthedocs.io/en/latest Set device registers using either a single byte or a packed sequence. ```python >>> i2c.regwr(0x34, 7, 0xa1) ``` ```python >>> i2c.regwr(0x75, 102, struct.pack(">H", 4999)) ``` -------------------------------- ### i2cdriver.I2CDriver Source: https://i2cdriver.readthedocs.io/en/latest Constructor for the I2CDriver class to establish a connection to the hardware. ```APIDOC ## I2CDriver(port='/dev/ttyUSB0', reset=True) ### Description Initializes a connection to the I2CDriver hardware. ### Parameters - **port** (str) - Optional - The USB port to connect to. - **reset** (bool) - Optional - Issue an I2C bus reset on connection. ``` -------------------------------- ### Read Temperature from LM75 Sensor Source: https://i2cdriver.readthedocs.io/en/latest Use the EDS.Temp class to read temperature data from a connected LM75 sensor. ```python >>> d=i2cdriver.EDS.Temp(i2c) >>> d.read() 17.875 >>> d.read() 18.0 ``` -------------------------------- ### scan Source: https://i2cdriver.readthedocs.io/en/latest Performs an I2C bus scan to identify connected devices. ```APIDOC ## scan(silent=False) ### Description Performs an I2C bus scan. If silent is False, prints a map of devices. Returns a list of the device addresses. ### Parameters - **silent** (bool) - Optional - If True, suppresses printing the device map. ``` -------------------------------- ### regwr Source: https://i2cdriver.readthedocs.io/en/latest Writes a value to a device register. ```APIDOC ## regwr(dev, reg, vv) ### Description Writes a device's register. ### Parameters - **dev** (int) - Required - 7-bit I2C device address. - **reg** (int) - Required - Register address 0-255. - **vv** (int/sequence) - Required - Value to write. ``` -------------------------------- ### Read Device Register Source: https://i2cdriver.readthedocs.io/en/latest Read a 16-bit unsigned big-endian register from a device. ```python >>> i2c.regrd(0x75, 102, ">H") 4999 ``` -------------------------------- ### regrd Source: https://i2cdriver.readthedocs.io/en/latest Reads a register value from an I2C device. ```APIDOC ## regrd(dev, reg, fmt='B') ### Description Reads a register from a device. ### Parameters - **dev** (int) - Required - 7-bit I2C device address. - **reg** (int) - Required - Register address 0-255. - **fmt** (str/int) - Optional - struct.unpack() format string or byte count. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.