Tag: programming
-
Python code for Grove I2C accelerometer module in Raspberry Pi OS
Written with ChatGPT: import smbus import time # Define the I2C address of the accelerometer ACCEL_ADDR = 0x4c # Initialize the I2C bus bus = smbus.SMBus(1) # Start measurement bus.write_byte_data(ACCEL_ADDR, 0x07, 0x01) while True: # Read the acceleration values for each axis try: accel_x = bus.read_byte_data(ACCEL_ADDR, 0x00) accel_y = bus.read_byte_data(ACCEL_ADDR, 0x01) accel_z = bus.read_byte_data(ACCEL_ADDR, 0x02)…