import machine import time # Hardware Setup i2c = machine.SoftI2C(scl=machine.Pin(7), sda=machine.Pin(6), freq=100000) led = machine.Pin(0, machine.Pin.OUT) # LED on D6 (GPIO0) button = machine.Pin(1, machine.Pin.IN, machine.Pin.PULL_UP) # Button on D7 (GPIO1) with pull-up BNO08X_I2C_ADDR = 0x4A last_button_state = 0 # Start with button not pressed (pull-up = HIGH) data_received = False print("Ready - Press button to check sensor data") while True: button_state = button.value() # Button pressed (LOW because of pull-up) if button_state == 1: led.value(1) if last_button_state == 0: print("Checking sensor...", end=" ") try: # Try to read data from sensor data = i2c.readfrom(BNO08X_I2C_ADDR, 4) # If we get data, sensor is responding if data and len(data) > 0: data_received = True print("✅ DATA RECEIVED!") else: data_received = False print("❌ NO DATA") except Exception as e: data_received = False print(f"❌ ERROR: No response") # Debounce delay time.sleep_ms(200) # Button released else: led.value(0) last_button_state = button_state time.sleep_ms(10)