@@ -91,18 +91,46 @@ This package is used extensively by the python modules for the SparkFun qwiic ec
9191General package use examples:
9292
9393``` python
94+ # Import the package
9495import qwiic_i2c
95- connectedDevices = i2cDriver.scan()
96- if myDeviceAddress in connectedDevices:
97- with qwiic_i2c.getI2CDriver() as i2c:
98- i2c.writeByte(myDeviceAddress, register, 0x 3F )
99- ```
10096
101- ``` python
102- import qwiic_i2c
103- >> > if qwiic_i2c.isDeviceConnected(myDeviceAddress):
104- with qwiic_i2c.getI2CDriver() as i2c:
105- i2c.writeByte(myDeviceAddress, register, 0x 3F )
97+ # Get the default I2C bus
98+ my_bus = qwiic_i2c.get_i2c_driver()
99+
100+ # Linux (Raspberry Pi) - Specify I2C bus index
101+ my_bus = qwiic_i2c.get_i2c_driver(iBus = 1 )
102+
103+ # MicroPython and CircuitPython - Specify SDA and SCL pins, and frequency
104+ my_bus = qwiic_i2c.get_i2c_driver(sda = 0 , scl = 1 , freq = 100000 )
105+
106+ # Perform scan of I2C bus
107+ scan_list = my_bus.scan()
108+ print (" Bus scan:" , scan_list)
109+
110+ # Check if a device with the specified address is connected
111+ ping_result = my_bus.ping(device_address)
112+ print (" Device is connected:" , ping_result)
113+
114+ # Read one byte from the specified address
115+ read_data = my_bus.read_byte(device_address, register_address)
116+ print (" Read byte:" , read_data)
117+
118+ # Read one word (2 bytes) from the specified address
119+ read_data = my_bus.read_word(device_address, register_address)
120+ print (" Read word:" , read_data)
121+
122+ # Read several bytes from the specified address
123+ read_data = my_bus.read_block(device_address, register_address, num_bytes_to_read)
124+ print (" Read block:" , read_data)
125+
126+ # Write one byte to the specified address
127+ my_bus.write_byte(device_address, register_address, write_data)
128+
129+ # Write one word (2 bytes) to the specified address
130+ my_bus.write_word(device_address, register_address, write_data)
131+
132+ # Write several bytes to the specified address
133+ my_bus.write_block(device_address, register_address, write_data)
106134```
107135
108136<p align =" center " >
0 commit comments