Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Note that this code requires the "MPU9250" library
- import smbus
- import time
- from MPU9250 import MPU9250
- # Define the I2C bus and MPU9250 address
- bus = smbus.SMBus(1)
- address = 0x68
- # Create a new MPU9250 object
- mpu9250 = MPU9250(bus, address)
- # Initialize the MPU9250
- mpu9250.begin()
- # Print the sensor configuration
- print("Accelerometer scale: {} g".format(mpu9250.get_accel_scale()))
- print("Gyroscope scale: {} dps".format(mpu9250.get_gyro_scale()))
- print("Magnetometer scale: {} uT".format(mpu9250.get_mag_scale()))
- print("Sample rate divider: {}".format(mpu9250.get_sample_rate_div()))
- # Read and print sensor data
- while True:
- accel_data = mpu9250.read_accel_data()
- gyro_data = mpu9250.read_gyro_data()
- mag_data = mpu9250.read_mag_data()
- print("Accelerometer: ({:6.2f}, {:6.2f}, {:6.2f}) g".format(*accel_data))
- print("Gyroscope: ({:6.2f}, {:6.2f}, {:6.2f}) dps".format(*gyro_data))
- print("Magnetometer: ({:6.2f}, {:6.2f}, {:6.2f}) uT".format(*mag_data))
- time.sleep(0.1) # Wait for 100ms before reading data again
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement