Comments (3)
Ok, I did some debugging and rewrote the readRegisters function like so:
int MPU9250::readRegisters(uint8_t subAddress, uint8_t count, uint8_t* dest){
if( _useSPI ){
// SPI code left out for conciseness
} else {
_i2c->beginTransmission(_address); // open the device
_i2c->write(subAddress); // specify the starting register address
int resultEndTransmission = _i2c->endTransmission(false);
if(resultEndTransmission > 0) {
return -200 - resultEndTransmission;
}
_numBytes = _i2c->requestFrom(_address, count); // specify the number of bytes to receive
if (_numBytes == count) {
for(uint8_t i = 0; i < count; i++){
dest[i] = _i2c->read();
}
return 1;
} else {
return -100 - _numBytes;
}
}
}
and the readSensor function like so:
int MPU9250::readSensor() {
_useSPIHS = true; // use the high speed SPI for data readout
// grab the data from the MPU9250
int resultReadReg = readRegisters(ACCEL_OUT,21, _buffer);
if (resultReadReg < 0) {
return resultReadReg;
}
// rest of the function left out for conciseness
}
After the modifications I monitored the readSensor's return value and I got a couple -100 but it always continued flawlessly. However after a couple of minutes I started getting -205 return values which according to the arduino docs shouldn't even be possible because the endTransmission function's return values should range from 0 to 4 (and not 5).
A tried to just disconnect the sensor while running and I got the same error code but after reconnecting it the readings didn't continue.
I can imagine that some of my freezings happen because the cables disconnect for a very short time but there are times when everything is completely still and the freezing still occurs.
I also wanted to connect is via SPI but I couldn't get it working at all.
from invensense-imu.
Is this the core that you're using? Are you on the newest version or something older?
https://github.com/espressif/arduino-esp32
I'll need to dig into it in detail to try to figure out what's going on. Seems like maybe something with the endTransmission(false) isn't working 100% reliably. Unfortunately, my schedule is a bit tied up until after March 9th to dig around in detail.
from invensense-imu.
Yes I'm using the latest arduino-esp32 core. Reading through this thread it seems like that the problem is in the core itself and we can't do anything with your library to avoid it so I think my (and anyone with this problem) only options are:
- using SPI instead of I2C
- using ESP8266 instead of ESP32
I tried my luck again with the SPI version and I was able the initialize the sensor (you have to use the VSPI labeled pins instead of the SPI ones) but the reading was all over the place, like I was generating just random numbers. Do you have any idea why I didn't got usable readings? I'll try to debug it later today. And another question: if the sensor is working correctly through an SPI connection and I temporarily disconnect one of the cables for a short period, will it work flawlessly after that? Or will I have to initialize the sensor again? Thanks for the help!
from invensense-imu.
Related Issues (20)
- Eigen.h file is missing HOT 4
- I am unable to begin communicating with my mpu9250 HOT 8
- Does setSrd() only work with interrupt? HOT 3
- No such file or directory #include <cstddef> + a few more imports HOT 1
- Latest version of the library is not available in PlatformIO library registry. HOT 1
- Glitches on Gyro data HOT 8
- Unable to reach magnetometer module in mpu9250 while using Teensy4.0 HOT 1
- SPI communication with teensy 4.1 is not working HOT 18
- cstddef: No such file or directory HOT 1
- cstddef & cstdint? HOT 1
- Set SPI clock speed HOT 1
- Why inverted axis for gyro and accelerometer HOT 5
- Esp32, Arduino how do I know the correct angle of the device? HOT 1
- Incompatible with AVR architecture ? HOT 3
- Compiling IDE 2.0 and arduino nano 33 iot HOT 2
- how can i get the cstddef HOT 2
- calibration HOT 1
- Reading erros HOT 8
- Is wake on motion still supported? HOT 1
- Missing Libraries in units.h and eigen.h HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from invensense-imu.