diff options
Diffstat (limited to 'src/pico')
| -rw-r--r-- | src/pico/test.py | 38 |
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...")
|