/ examples / mpu6050_sleep_example.py
mpu6050_sleep_example.py
 1  import time
 2  import board
 3  import busio
 4  import adafruit_mpu6050
 5  
 6  i2c = busio.I2C(board.SCL, board.SDA)
 7  mpu = adafruit_mpu6050.MPU6050(i2c)
 8  
 9  # This example is meant to be used with the serial plotter which makes
10  # it easier to see how the readings change with different settings.
11  # Make sure to poke and prod the sensor while the demo is running to
12  # generate some intersting data!
13  
14  while True:
15      # first show some 'normal' readings
16  
17      mpu.sleep = False
18      mpu.cycle = False
19  
20      for count in range(0, 100):
21          print(mpu.acceleration)
22          time.sleep(0.010)
23  
24      # Next, set a slow cycle rate so the effect can be seen clearly.
25      mpu.cycle_Rate = adafruit_mpu6050.Rate.CYCLE_5_HZ
26      # ensure that we're not sleeping or cycle won't work
27      mpu.sleep = False
28      # Finally, enable cycle mode
29      mpu.cycle = True
30  
31      for count in range(0, 100):
32          print(mpu.acceleration)
33          time.sleep(0.010)
34  
35      # Finally enable sleep mode. Note that while we can still fetch
36      #  data from the measurement registers, the measurements are not
37      #  updated. In sleep mode the accelerometer and gyroscope are
38      #  deactivated to save power, so measurements are halted.
39  
40      mpu.cycle = False
41      mpu.sleep = True
42  
43      for count in range(0, 100):
44          print(mpu.acceleration)
45          time.sleep(0.010)