aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorM005A <[email protected]>2025-04-17 13:04:57 -0700
committerGitHub <[email protected]>2025-04-17 13:04:57 -0700
commitb54e5adecb6f339da2b914425bea1e448b4b8dd1 (patch)
tree189e803ac66fb2dc5cf667a8b55021ebb56d3893
parentCreate joystick_to_cursor.py (diff)
downloadsplitscreen-duo-b54e5adecb6f339da2b914425bea1e448b4b8dd1.tar.xz
splitscreen-duo-b54e5adecb6f339da2b914425bea1e448b4b8dd1.zip
New updated code to stop I2C errors
-rw-r--r--src/pico/test.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/pico/test.py b/src/pico/test.py
new file mode 100644
index 0000000..b267b09
--- /dev/null
+++ b/src/pico/test.py
@@ -0,0 +1,38 @@
+import time
+import board
+import busio
+import adafruit_mpu6050 # Import Adafruit's MPU6050 library
+
+# Initialize the I2C bus ONCE
+i2c = busio.I2C(board.GP1, board.GP0) # Use GP1 (SCL) and GP0 (SDA)
+
+# Initialize the MPU6050 sensor using the Adafruit library
+mpu = adafruit_mpu6050.MPU6050(i2c)
+
+# Optional: Adjust settings (Uncomment if needed)
+# mpu.gyro_range = adafruit_mpu6050.GyroRange.RANGE_500_DPS
+# mpu.accelerometer_range = adafruit_mpu6050.Range.RANGE_4_G
+# mpu.filter_bandwidth = adafruit_mpu6050.Bandwidth.BAND_94_HZ
+
+print("MPU6050 Initialized! Starting sensor read loop...")
+
+try:
+ while True:
+ # Read acceleration (m/s^2)
+ accel_x, accel_y, accel_z = mpu.acceleration
+
+ # Read gyro data (degrees/s)
+ gyro_x, gyro_y, gyro_z = mpu.gyro
+
+ # Read temperature (°C)
+ temp = mpu.temperature
+
+ # Print sensor data
+ print(f"Accel: X={accel_x:.2f}, Y={accel_y:.2f}, Z={accel_z:.2f} m/s²")
+ print(f"Gyro: X={gyro_x:.2f}, Y={gyro_y:.2f}, Z={gyro_z:.2f} °/s")
+ print(f"Temp: {temp:.2f}°C")
+ print("-" * 40)
+
+ time.sleep(0.1) # Adjust delay as needed
+except KeyboardInterrupt:
+ print("Exiting...")