Git Product home page Git Product logo

adafruit_circuitpython_mpu6050's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

CircuitPython helper library for the MPU6050 6-DoF Accelerometer and Gyroscope

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-mpu6050

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-mpu6050

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-mpu6050

Usage Example

import time
import board
import adafruit_mpu6050

i2c = board.I2C()  # uses board.SCL and board.SDA
mpu = adafruit_mpu6050.MPU6050(i2c)

while True:
    print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2"%(mpu.acceleration))
    print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s"%(mpu.gyro))
    print("Temperature: %.2f C"%mpu.temperature)
    print("")
    time.sleep(1)

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_mpu6050's People

Contributors

dhalbert avatar evaherrada avatar foamyguy avatar jepler avatar jposada202020 avatar kattni avatar keiththeee avatar ladyada avatar siddacious avatar sommersoft avatar squirtlesquadleader avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_mpu6050's Issues

MpyError: Incompatible .mpy file in CircuitPython 6.0.0

I'm trying to run your handy library with an Adafruit Feather M0 Microcontroller running CircuitPython 6.0.0.

I've downloaded the Adafruit Bundle with the mentioned dependencies and the MPU6050 library as the .mpy file you provided.
See my lib folder here:
image

When importing via:
import adafruit_mpu6050

I get this error:
Traceback (most recent call last): File "code.py", line 8, in <module> File "adafruit_mpu6050.py", line 56, in <module> MpyError: Incompatible .mpy file. Please update all .mpy files. See http://adafru.it/mpy-update for more info.

Is your library not yet compatible with CP 6.0.0 or am I doing something wrong here?
Thank you for your help.

import error

import time
import adafruit_mpu6050
import board

i2c = board.I2C()# uses board.SCL and board.SDA
mpu = adafruit_mpu6050.MPU6050()

while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2"%(mpu.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f degrees/s"%(mpu.gyro))
print("Temperature: %.2f C"%mpu.temperature)
print("")
time.sleep(1)

i m using this code for raspberry pi pico but its showing " File "", line 3, in
ImportError: no module named 'board'"

Failed to find MPU6050 but it's detected by i2cdetect

So I'm using GY-521 MPU-6050 for my Jetson Nano, So I tried to run this code example https://github.com/adafruit/Adafruit_CircuitPython_MPU6050/blob/main/examples/mpu6050_simpletest.py then there is an error Failed to find MPU6050 - check your wiring .

My wirings:

scl -> (28 pin)
sda -> (27 pin)
gnd -> (gnd)
vcc -> (vcc)

The i2cdetect still able to detect the i2c though.

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- 69 -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

I also change line 10 from the example to be set the address to 105 (i2cdetect detects 0x69)
mpu = adafruit_mpu6050.MPU6050(i2c, 105) .

My MPU-6050 led is still on, but why it fails to find MPU6050?

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_mpu6050.py:175
  • adafruit_mpu6050.py:293
  • adafruit_mpu6050.py:303
  • adafruit_mpu6050.py:315
  • adafruit_mpu6050.py:327
  • adafruit_mpu6050.py:339

Feature request => Add Tap, Motion, and Freefall

@siddacious Bryan, thank you for posting your code and helping us.
Adafruit_CircuitPython_ADXL34x Tap, Motion and Freefall are solid examples within this other github.

Could this be possibly considered for the MPU6050 also, to be added within the examples?

MemoryError when loading module

Using an Adafruit Metro Express M0, CircuitPython 8.2.8, and MPU boards from Amazon, with or without having an MPU board connected, I get an. immediate memory error upon loading the module:

paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import time
=== import board
=== import digitalio
=== import adafruit_mpu6050
=== 
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "adafruit_mpu6050.py", line 45, in <module>
  File "adafruit_register/i2c_bits.py", line 25, in <module>
MemoryError: memory allocation failed, allocating 60 bytes
>>>

The boards in question do work if I use C - is the M0 just not beefy enough, maybe?

Temperature

I believe the temperature formula should be:

Option for MPU6050

temp = (raw_temperature / 340.0) + 36.53

or Option for MPU6500

temp = (raw_temperature / 333.87) + 21.0

Rather than exiting formula:

temp = (raw_temperature + 12412.0) / 340.0

This is based on the code available here.

I still question if the MPU6050 values are correct. I get approximately 48 degrees C with the IMU sitting on my desk (I am using an MPU6500 which should have the same registers). The ambient temperature is about 20 degrees C.

DisplayIO Example Wanted

Add a Basic DisplayIO Based Example

We would like to have a basic displayio example for this library. The example should be written for microcontrollers with a built-in display. At a minimum it should show a Label on the display and update it with live readings from the sensor.

The example should not be overly complex, it's intended to be a good starting point for displayio based projects that utilize this sensor library. Try to keep all visual content as near to the top left corner as possible in order to best fascilitate devices with small built-in display resolutions.

The new example should follow the naming convention examples/libraryname_displayio_simpletest.py with "libraryname" being replaced by the actual name of this library.

You can find an example of a Pull Request that adds this kind of example here: adafruit/Adafruit_CircuitPython_BME680#72

We have a guide that covers the process of contributing with git and github: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

If you're interested in contributing but need additional help, or just want to say hi, feel free to join the Discord server to ask questions: https://adafru.it/discord

RuntimeError - issues with device id

Hello and sorry in advance if this question ist quite foolish.

I am continously running into this error-message:
Traceback (most recent call last): File "code.py", line 27, in <module> File "adafruit_mpu6050.py", line 164, in __init__ RuntimeError: Failed to find MPU6050 - check your wiring!

From what I can gather from the source code this is an issue with the "device-id" ("WHO_AM_I" - register in the datasheet). Now I don't know what's causing this, presumably this register is somehow different on my device?

I'm using Feather M0 and the MPU6050. I've resoldered the pins, tried adding pullups, attached an external battery, replaced the wiring but this all didn't change anything.

This is the relevant section of my code:

import board
import microcontroller
import busio
import adafruit_mpu6050

i2c = busio.I2C(board.SCL, board.SDA)

mpu = adafruit_mpu6050.MPU6050(i2c)

My Circuit:
photo5204311937167503650

Have you any idea what could be causing this? Thanks in advance.

How to qualify the bus, board.i2c() does not see bus 0 on Pi Model B (original board)?

How to qualify the bus, board.i2c() does not see bus 0 on Pi Model B (original board)? My MPU6050 is on bus 0...

i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

No gyro data coming only show 0

I test my raspberry pi 3b+ with the mpu6050 and having great accl data but the gyro only showing 0 in all x y z when using different library the gyro showing normal values.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.