Go Down

Topic: Clean, straight-forward MPU-6050 code (Read 9 times) previous topic - next topic

schmidtbag

I was wondering if there were any simple, straight-forward examples to access just the temperature, yaw/pitch/roll, and X/Y/Z acceleration.  Most of the demos are several hundred lines long (with or without comments) and for me, the i2cdev demo just halts at the "DMP ready! Waiting for first interrupt..." stage.

I never understood the point of people who create tutorials and examples that are so needlessly complicated.  It'd be easier for everyone (including the tutors) if there were separate files for each core feature rather than cram most (but not all) features into 1 file and leave the user to spend hours filtering out whats needed and what isn't. Also with such long codes, it's effortless to break the entire thing while attempting to clean up everything you don't need.  There have been many times I could take a 200 line example code and shrink it to about 1/4 the size with the exact same results and more descriptive details of what every single line is trying to accomplish.  But in this situation, the examples are so long and over-complicated that it drew me here.

Considering the MPU-6050 is a DMP on an I2C bus, I would think my request should be relatively simple.  The code could be as short as maybe 75 lines (minus comment lines) to get the results I want, where you initialize the libraries, prepare the device, request the DMP data, parse the DMP data, and send it over serial.  That being said, technically the mpu6050 library by i2cdev shouldn't be needed, but that library does help put human-readable names to all the addresses.

I managed to get the ADXL345 to work in less than 50 lines of code, no libraries, and convert the raw data into degrees.  I don't see why the same can't be done with this.  Does anyone have any suggestions?

Krodal


wwbrown

Schmidtbag,

The alternative is to write the code you believe is needed for one device and share with the great unwashed.  Your example would show the world what it has been missing in easy and simple code and everyone would join the movement.

wade

schmidtbag

@Krodal
I noticed that code but it too is ridiculously long.  I'm sure 90% of the code is unneeded but its hard to determine what MUST be there.

@wwbrown
The problem is I'm not really sure where to begin.  The MPU-6050 has so much stuff to it, most of which I could care less about.  I wouldn't mind submitting my own cleaned-up code but I need something reasonable to work with.  I don't have time to spend days upon days of research.

GaryWilkerson

Krodal,

Im trying to compile the code you provided and get the following errors:

sketch_jan31a.ino: In function 'int MPU6050_read(int, uint8_t*, int)':
sketch_jan31a:802: error: 'class TwoWire' has no member named 'write'
sketch_jan31a:806: error: no matching function for call to 'TwoWire::endTransmission(int)'
C:\Documents and Settings\Gary W\My Documents\Arduino\libraries\Z/Wire.h:51: note: candidates are: uint8_t TwoWire::endTransmission()
sketch_jan31a:811: error: no matching function for call to 'TwoWire::requestFrom(int, int&, int)'
C:\Documents and Settings\Gary W\My Documents\Arduino\libraries\Z/Wire.h:52: note: candidates are: uint8_t TwoWire::requestFrom(uint8_t, uint8_t)
C:\Documents and Settings\Gary W\My Documents\Arduino\libraries\Z/Wire.h:53: note:                 uint8_t TwoWire::requestFrom(int, int)
sketch_jan31a:815: error: 'class TwoWire' has no member named 'read'
sketch_jan31a.ino: In function 'int MPU6050_write(int, const uint8_t*, int)':
sketch_jan31a:848: error: 'class TwoWire' has no member named 'write'
sketch_jan31a:852: error: 'class TwoWire' has no member named 'write'
sketch_jan31a:856: error: no matching function for call to 'TwoWire::endTransmission(int)'
C:\Documents and Settings\Gary W\My Documents\Arduino\libraries\Z/Wire.h:51: note: candidates are: uint8_t TwoWire::endTransmission()


I thought most of the error were due to Wire Library not being available but its in the Library folder.
I'm using a DUO with 1.0.3 version of the IDE

Any assistance would be appreciated.


Gary

Go Up