Skip to content

Power management methods #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ example usage:
>>>from machine import I2C, Pin
>>>import mpu6050
>>>i2c = I2C(scl=Pin(5), sda=Pin(4))
>>>accelerometer = mpu6050.accel(i2c)
>>>accelerometer.get_values()
{'GyZ': -235, 'GyY': 296, 'GyX': 16, 'Tmp': 26.64764, 'AcZ': -1552, 'AcY': -412, 'AcX': 16892}
>>>imu = mpu6050.accel(i2c)
>>> imu.get_values()
{'GyZ': -60, 'GyY': -68, 'GyX': 2, 'Tmp': 33.04765, 'AcZ': 16048, 'AcY': 44, 'AcX': -952}
>>> imu.sleep()
>>> imu.get_values()
{'GyZ': -38, 'GyY': 56, 'GyX': -38, 'Tmp': 33.00059, 'AcZ': 15824, 'AcY': -40, 'AcX': -708}
>>> imu.get_values()
{'GyZ': -38, 'GyY': 56, 'GyX': -38, 'Tmp': 33.00059, 'AcZ': 15824, 'AcY': -40, 'AcX': -708}
>>> imu.wakeup()
>>> imu.get_values()
{'GyZ': -28, 'GyY': 59, 'GyX': -44, 'Tmp': 32.85941, 'AcZ': 15948, 'AcY': -76, 'AcX': -852}
```
Accelerometer/Gyroscope values are in int16 range (-32768 to 32767)
If the mpu6050 loses power, you have to call __init__() again

Source: https://github.com/adamjezek98/MPU6050-ESP8266-MicroPython

23 changes: 23 additions & 0 deletions mpu6050.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ def get_values(self):
return vals # returned in range of Int16
# -32768 to 32767

def sleep(self):
self.iic.start()
self.iic.writeto_mem(self.addr, 0x6B, b'\x40')
self.iic.stop()

def wakeup(self):
from time import sleep
self.iic.start()
self.iic.writeto_mem(self.addr, 0x6B, b'\x80')
self.iic.stop()
sleep(0.05)
self.iic.start()
self.iic.writeto_mem(self.addr, 0x68, b'\x07')
self.iic.stop()
sleep(0.05)
self.iic.start()
self.iic.writeto_mem(self.addr, 0x68, b'\x00')
self.iic.stop()
sleep(0.05)
self.iic.start()
self.iic.writeto_mem(self.addr, 0x6B, b'\x00')
self.iic.stop()

def val_test(self): # ONLY FOR TESTING! Also, fast reading sometimes crashes IIC
from time import sleep
while 1:
Expand Down