natanaeljr / esp32-mpu-driver Goto Github PK
View Code? Open in Web Editor NEWESP32 full library for all MPU6000 MPU6050 MPU6500 MPU9150 MPU9250 with SPI and I2C support and more.
License: MIT License
ESP32 full library for all MPU6000 MPU6050 MPU6500 MPU9150 MPU9250 with SPI and I2C support and more.
License: MIT License
MPUDriver put to my ESP32-S2 project as one component, then a error reported after run "idf.py menuconfig"
Hi! first of all thank you for your work! I've having problems trying to run the examples with the i2c peripheral. It doesn't find the I2Cbus.hpp neither the MPU.hpp even though I clone those libraries in the include directory. Thank you for your time!
"MPUdriver/include/MPU.hpp:34:2: error: #error ''MPU component requires I2Cbus library. Make sure the I2Cbus library is included in your components directory. See MPUs README.md for more information.''
#error ''MPU component requires I2Cbus library"
First of all, thank you for the code example... I am trying to get mpu_real working with M5Stack board.
Here is the output which shows 0 for all the roll,pitch & yaw.
$ MPU Driver Example: Advanced
E (2) example: Through I2C
I (177) MPU9250: whoAmI [0x71]:0X71
I (181) example: MPU connection successful!
I (287) MPU9250: Reset!
I (303) MPU9250: Sample rate set to 100 Hz
I (306) MPU9250: Initialization complete
I (309) MPU9250: Sample rate set to 1000 Hz
W (311) MPU9250: Compass sample rate constrained to 100, magnetometer's maximum is 100 Hz
I (664) MPU9250: Sample rate set to 100 Hz
I (672) MPU9250: Sample rate set to 1000 Hz
W (674) MPU9250: Compass sample rate constrained to 100, magnetometer's maximum is 100 Hz
I (1024) MPU9250: Sample rate set to 100 Hz
I (1030) example: MPU Self-Test result: Gyro=OK Accel=OK
I (1032) MPU9250: Sample rate set to 1000 Hz
W (1034) MPU9250: Compass sample rate constrained to 100, magnetometer's maximum is 100 Hz
I (1388) MPU9250: Sample rate set to 100 Hz
I (1396) MPU9250: Sample rate set to 250 Hz
W (1398) MPU9250: Compass sample rate constrained to 83, magnetometer's maximum is 100 Hz
I (1401) gpio: GPIO[36]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:1
Pitch: +0.0 Roll: +0.0 Yaw: +0.0
Pitch: +0.0 Roll: +0.0 Yaw: +0.0
Pitch: +0.0 Roll: +0.0 Yaw: +0.0
Pitch: +0.0 Roll: +0.0 Yaw: +0.0
Do let me know if you have any suggestions to get this working...
Also does your library support DMP?
The library is not compatible with the CMake based build system. I being new to CMake am pretty unsure of what's happening. Could you please tweak the library to work with the new system?
I'm new to ESP-IDF and have a very basic understanding of CMake and ESP-IDF's build system. I am getting an error while adding the MPU9250 driver component in a Vanilla ESP-IDF hello_world
example, and not sure how to proceed. My best guess is that the compiler expects everything to be in C. Here's my error -
Toolchain path: /opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a5
Compiler version: 5.2.0
Python requirements from E:/Work/MovTrack/ESP32/esp/esp-idf/requirements.txt are satisfied.
Project is not inside a git repository, will not use 'git describe' to determine PROJECT_VER.
App "mpu9250" version: 1
CC build/main/hello_world_main.o
In file included from E:/Work/MovTrack/ESP32/esp/mpu9250/components/MPUdriver/include/MPU.hpp:47:0,
from E:/Work/MovTrack/ESP32/esp/mpu9250/main/hello_world_main.c:15:
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:37:1: error: unknown type name 'class'
class SPI;
^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:40:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'hspi'
extern SPI hspi;
^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:41:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'vspi'
extern SPI vspi;
^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:48:1: error: unknown type name 'class'
class SPI {
^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:48:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
class SPI {
^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:133:3: warning: data definition has no type or storage class
} SPI_t;
^
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:133:3: error: type defaults to 'int' in declaration of 'SPI_t' [-Werror=implicit-int]
E:/Work/MovTrack/ESP32/esp/mpu9250/components/SPIbus/include/SPIbus.hpp:137:1: error: unknown type name 'constexpr'
constexpr SPI_t& getSPI(spi_host_device_t host) {
^
.
.
.
.
E:/Work/MovTrack/ESP32/esp/mpu9250/main/hello_world_main.c: At top level:
cc1.exe: warning: unrecognized command line option '-Wno-frame-address'
cc1.exe: some warnings being treated as errors
make[1]: *** [/e/Work/MovTrack/ESP32/esp/esp-idf/make/component_wrapper.mk:290: hello_world_main.o] Error 1
make: *** [E:/Work/MovTrack/ESP32/esp/esp-idf/make/project.mk:579: component-main-build] Error 2
All errors are about C++ keywords like class
not being recognized by the compiler. How can I fix this?
Hello, I tried to import the i2c and MPU repository as component under my 'hello_world' example project given by ESP-IDF.
if I modify the main.c into main.cpp by modifying some lines in main.c
file and CMakeList.txt
, the components works.
However, My project with lvgl lib needs to be developed by C language. When I directly using this driver for my MPU6050 on I2C, the error occurs when compiling.
How to use the cpp-written components in C project?
below is the file structure of my project:
% tree -L 3
.
├── CMakeLists.txt
├── Makefile
├── README.md
├── components
│ ├── I2Cbus *No modification made in this dir
│ │ ├── CMakeLists.txt
│ │ ├── Kconfig
│ │ ├── Kconfig.projbuild
│ │ ├── LICENSE
│ │ ├── Makefile.projbuild
│ │ ├── README.md
│ │ ├── component.mk
│ │ ├── examples
│ │ ├── include
│ │ └── src
│ └── MPUdriver *No modification made in this dir
│ ├── CMakeLists.txt
│ ├── Kconfig
│ ├── Kconfig.projbuild
│ ├── LICENSE
│ ├── Makefile.projbuild
│ ├── README.md
│ ├── component.mk
│ ├── docs
│ ├── examples
│ ├── include
│ ├── src
│ ├── test
│ └── tools
├── example_test.py
├── main
│ ├── CMakeLists.txt
│ ├── component.mk
│ ├── hello_world_main.c.bak
│ ├── main.c
│ └── main.cpp.ok.bak
├── sdkconfig
└── sdkconfig.old
Some error about namespace, I guess I need to configure something for using C++ component in C proj. but How?
Thank you very much!!
I'm trying to use your lib with an mpu6050 and an esp32 using esp-idf to flash data to my board, but having problems with comunication. All pins are defined correctly, pinned correctly but when I check the output it shows me "Pitch: +0.0 Roll: +0.0 Yaw: +0.0 " and the following error:
$ MPU Driver Example: Advanced
E (2285) I2Cbus: [port:0, slave:0x68] Failed to read 1 bytes from register 0x75, error: 0x107
E (2285) MPU6050: func:uint8_t mpud::MPU::whoAmI() @ line:162, expr:"readByte(regs::WHO_AM_I, buffer)", error:0x107
E (2285) MPU6050: func:esp_err_t mpud::MPU::testConnection() @ line:143, expr:"lastError()", error:0x107
E (2295) example: Failed to connect to the MPU, error=0X107
Pitch: +0.0 Roll: +0.0 Yaw: +0.0
Pitch: +0.0 Roll: +0.0 Yaw: +0.0
and keeps showing this every 1sec. MPU6050 and ESP32 pin connections are
MPU6050 ---- ESP32
VCC ---- 5v
GND ---- gnd
SCL ---- 26
SDA ---- 14
INT ---- 17
I've googled a lot but no answer found! If ou could help me I'll be so gratefull, thx in advance...
Im totally new to all this but im trying to use this library in platformIO for visual studio code. Im trying to use the make menuconfig command but that does not work so i installed cmake and its giving me errors when i run it in the master folder using cmake ./
Error im getting:
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.17763.
CMake Error at CMakeLists.txt:7 (register_component):
Unknown CMake command "register_component".
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.16)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
Thank you for the great code, very helpful.
I’ve been trying to read magnetometer from MPU9255 but no luck, readings are 0 and would appreciate your support.
Gyroscope and Accelerometer working fine.
here is the
MPU.acceleration(&accelRaw); // fetch raw data from the
MPU.rotation(&gyroRaw); // fetch raw data from the
MPU.heading(&compassRaw);
MPU.motion(&accelRaw, &gyroRaw, &compassRaw);
float mx = compassRaw[0] * 1.499;
float my = compassRaw[1] * 1.499;
float mz = compassRaw[2] * 1.499;
printf("mx = %f \t my = %f \t mz = %f\n",mx,my,mz);
I havent found any libraries for the mpu9250 that work over spi on the esp32 and this looks really good. Does this work with PlatformIO or do i need to change some things to get it to work?
By running the example codes mpu_i2c and mpu_real with an ESP32 Dev Kit C V4 and a MPU6050 Module connected (SDA to GPIO21 and SCL to GPIO22) I'm just getting 0X105 errors (). I wrote the right GPIO Pins (not Hardware Pins) in the program and tried different Pins as well, but it still doesn't work. Maybe I did something wrong, I'm pretty new in the ESP-IDF framework...
magneto AK89 all zero
This isn't really an issue just a question - I love this library, I would love to use the DMP on the MPU6000 but from what I can tell, it looks like the DMP is not yet supported, is this correct?
How much work do we think it would take to add this support? Does it just involve setting different register values and such (MPU n00b here)
Hi, I'm using this library with MPU9255.
I cannot read data from the sensor when I call MPU.acceleration
in FreeRTOS task.
There are some errors at the console like this.
E (155274) I2Cbus: [port:0, slave:0x68] Failed to read 6 bytes from register 0x3B, error: 0x107
I can get a data without using FreeRTOS task.
How to avoid this issue?
I'm using esp-idf v3.1 and MPU9250.
Regards,
Akira
I obtained the following error message in the ESP-IDF ver 5.0.1 platform:
MPU.cpp:1879:13: error: either all initializer clauses should be designated or none of them should be
Currently only when operating the MPU through SPI, I2C AUX mode is enabled automatically during initialization. When operating through I2C, the application has to do it to enable readouts from the compass.
Line 1785 in 82a6092
I think the correct code in line 93 is
#if defined CONFIG_MPU6500 || defined CONFIG_MPU9250
Because I get an error in compiling when I define MPU9250 on menuconfig
fchoice_t does not a type.
There is no example of using magnetometer sensor. Also it will be good to see example of getting some data, like roll, pitch, yaw angles
Hi, relatively new to C++ and the esp-idf, got mpu_i2c working but prefer the output of the mpu_real example (connected the INT pin on my mpu to check this example out).
I have already made a custom 4 wire connector to the mpu from my ESP32 (VCC/GND/SCL/SDA) and so would prefer not to have the INT also connected as I would have to remake the wire.
Is there a portion of the example code that I can omit or an argument I can pass into one of the functions to remove this functionality and in doing so remove the need for a cable to the INT connector?
Thanks
When running mpu_real with ESP32 and MPU6050, the pitch drifts from 0 (correct - in upright position) to 6 degrees in about half a second after starting, then the value stabalizes. Similar problem with Roll. When I delete the fusion with the pitchAccel like this:
//pitch = gyroPitch * 0.95f + accelPitch * 0.05f;
pitch = gyroPitch;
The pitch value is correct. But i want the fusion to work...
I checked the acceleration offset values for x,y and z and changed them manually until
accelG.x = 0, accelG.y = 0 and accelG.z = 1. Now the pitch / roll values are correct when using the fusion with accelPitch and accelRoll. The gyro calibration seems to work fine.
Any idea why the acceleration calibration gives wrong offsets?
Hi!
I build and flash the mpu_real it outputs looks below
Pitch: -5.5 Roll: +12.0 Yaw: -163.8
Pitch: -13.6 Roll: +50.1 Yaw: -152.3
Pitch: -3.2 Roll: +9.2 Yaw: -149.0
Pitch: -14.6 Roll: +51.0 Yaw: -144.7
Pitch: -6.2 Roll: +29.5 Yaw: -143.7
Pitch: -7.8 Roll: +38.5 Yaw: -154.8
Pitch: -16.9 Roll: +68.5 Yaw: -157.9
Pitch: -7.7 Roll: +35.0 Yaw: -156.6
Pitch: -8.8 Roll: +30.8 Yaw: -173.8
in this case I am not use ulTaskNotifyTake();
I don't know why it happen's please give your suggestion.
Regards,
K dhanasekaran
I ran your example mpu_real, but it doesn't seem to be working;
particularly, it's getting stuck at the line
uint32_t notificationValue = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
I put some logs in and it looks like mpuISR isn't running.
I was wondering if there was a bug in the code or is it just something wrong on my end? I set GPIO 17 as the interrupt pin, if that helps and the interrupt pin on the MPU seems to output a square wave on an oscilloscope.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.