Skip to content

sparkfun/Qwiic_I2C_Py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qwiic_I2C_Py

follow on Twitter

Python package to support multi platform I2C bus integrations for the SparkFun qwiic ecosystem

This package can be used in conjunction with the overall SparkFun qwiic Python Package

New to qwiic? Take a look at the entire SparkFun qwiic ecosystem.

Contents

Supported Platforms

The qwiic I2C Python package current supports the following platforms:

Dependencies

The Raspberry Pi/Single Board Computer Linux driver of this package is dependent on smbus

Documentation

The SparkFun qwiic I2C module documentation is hosted at ReadTheDocs

Installation

PyPi Installation

This repository is hosted on PyPi as the sparkfun-qwiic-i2c package. On systems that support PyPi installation via pip, this library is installed using the following commands

For all users (note: the user must have sudo privileges):

sudo pip install sparkfun-qwiic-i2c

For the current user:

pip install sparkfun-qwiic-i2c

Local Installation

To install, make sure the setuptools package is installed on the system.

Direct installation at the command line:

python setup.py install

To build a package for use with pip:

python setup.py sdist

A package file is built and placed in a subdirectory called dist. This package file can be installed using pip.

cd dist
pip install sparkfun_qwiic_i2c-<version>.tar.gz

Examples

This package is used extensively by the python modules for the SparkFun qwiic ecosystem. References to the modules can be found in the qwiic python package

General package use examples:

# Import the package
import qwiic_i2c

# Get the default I2C bus
my_bus = qwiic_i2c.get_i2c_driver()

# Linux (Raspberry Pi) - Specify I2C bus index
my_bus = qwiic_i2c.get_i2c_driver(iBus = 1)

# MicroPython and CircuitPython - Specify SDA and SCL pins, and frequency
my_bus = qwiic_i2c.get_i2c_driver(sda=0, scl=1, freq=100000)

# Perform scan of I2C bus
scan_list = my_bus.scan()
print("Bus scan:", scan_list)

# Check if a device with the specified address is connected
ping_result = my_bus.ping(device_address)
print("Device is connected:", ping_result)

# Read one byte from the specified address
read_data = my_bus.read_byte(device_address, register_address)
print("Read byte:", read_data)

# Read one word (2 bytes) from the specified address
read_data = my_bus.read_word(device_address, register_address)
print("Read word:", read_data)

# Read several bytes from the specified address
read_data = my_bus.read_block(device_address, register_address, num_bytes_to_read)
print("Read block:", read_data)

# Write one byte to the specified address
my_bus.write_byte(device_address, register_address, write_data)

# Write one word (2 bytes) to the specified address
my_bus.write_word(device_address, register_address, write_data)

# Write several bytes to the specified address
my_bus.write_block(device_address, register_address, write_data)

SparkFun - Start Something

About

Python package to support multi platform I2C bus integrations

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages