Код: Выделить всё
https://github.com/sparkfun/Qwiic_I2C_PyКод: Выделить всё
https://github.com/sparkfun/Qwiic_KX13X_PyКод: Выделить всё
import qwiic_i2c
import qwiic_kx13x
import time
import sys
# Initialize I2C driver (assuming qwiic_i2c doesn't support custom SDA/SCL)
my_bus = qwiic_i2c.get_i2c_driver(sda=4, scl=5, freq=100000)
ping_result = my_bus.ping(0x1F) # Check for device presence at the correct address 0x1F
print("Device is connected:", ping_result)
def runExample():
print("\nSparkFun KX13X Accelerometer Example 1\n")
# Initialize the KX13X device at I2C address 0x1F
myKx = qwiic_kx13x.QwiicKX13XCore(address=0x1F) # Corrected address
if not myKx.connected:
print("The Qwiic KX13X Accelerometer device isn't connected to the system. Please check your connection", \
file=sys.stderr)
return
if myKx.begin():
print("Ready.")
else:
print("Make sure you're using the correct KX13X device")
# Set the accelerometer range if needed, uncomment if range is required
# myKx.set_range(myKx.KX132_RANGE8G)
# Initialize with basic settings
myKx.initialize(myKx.BASIC_SETTINGS)
while True:
# Get accelerometer data
myKx.get_accel_data()
print("X: {0}g Y: {1}g Z: {2}g".format(
myKx.kx134_accel.x,
myKx.kx134_accel.y,
myKx.kx134_accel.z))
time.sleep(0.02) # Delay for the Output Data Rate, default 50Hz (1/50 = 0.02)
if __name__ == '__main__':
try:
runExample()
except (KeyboardInterrupt, SystemExit):
print("\nEnding Example 1")
sys.exit(0)
Подробнее здесь: https://stackoverflow.com/questions/791 ... e-being-de
Мобильная версия