limon Posted January 29, 2014 Report Share Posted January 29, 2014 Hello, dear pro MPU users! :-) I have no problem to compile the example for Arduino. This is good :-) But I can't move all the initializations and all the serial output into new class, I called Sensor. I'v created Sensor.h, Sensor.cpp In the sensor.h: #ifndef SENSOR_H #define SENSOR_H #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" //#include "MPU6050.h" // not necessary if using MotionApps include file // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif class Sensor{ public: static Sensor & getInstance(){ static Sensor instance; return instance; } bool init(); bool getYpr(float & y, float & p, float r); protected: MPU6050 _mpu; .................................. ...................... ........... In the main project: #include "Wire.h" #include "sensor.h" void setup() { Sensor::getInstance().init(); } void loop() { float y,p,r; Sensor::getInstance().getYpr(y,p,r); } And I have a lot of errors like this: testMPU.cpp.o: In function `MPU6050::dmpGetAccel(long*, unsigned char const*)': /MPU6050_6Axis_MotionApps20.h:533: multiple definition of `MPU6050::dmpGetAccel(long*, unsigned char const*)' sensor.cpp.o:/MPU6050_6Axis_MotionApps20.h:533: first defined here ............. I'v found some information, that this may be caused by including "MPU6050.h", but I don't do it! I can't attach archives here. So, here is a link to a dropbox with my test project: https://dl.dropboxusercontent.com/u/51786067/testMPU.rar Hope, my question is not very stupid :-)Thanks! Quote Link to comment Share on other sites More sharing options...
luisrodenas Posted January 30, 2014 Report Share Posted January 30, 2014 I believe your problem doesn't have anything to do with the sensor itself, but is more related to programming. Programming is not one of my strengths, so I think I cannot help much. Anyway, it looks like it has something to do with duplicated includes... looking at the error you posted. You can try two things: - Put all the includes in the arduino project, not in sensor.h. Its only 2 or 3 lines... - In sensor.cpp, you are including sensor.h, is it necessary? I mean, you are including it from the arduino project and from that file, maybe that's the cause? Sorry I can't be of more help. Quote Link to comment Share on other sites More sharing options...
luisrodenas Posted January 30, 2014 Report Share Posted January 30, 2014 Maybe, instead of putting the includes in sensor.h, try to put them all in sensor.cpp Quote Link to comment Share on other sites More sharing options...
limon Posted January 30, 2014 Author Report Share Posted January 30, 2014 Maybe, instead of putting the includes in sensor.h, try to put them all in sensor.cpp Thank you for your help! Put all the includes in the arduino project, not in sensor.h. Its only 2 or 3 lines... I tried to do this, and had another error in Sensor.h: sensor.h:18: error: 'MPU6050' does not name a type Because sensor.h don't know about MPU libraries... In sensor.cpp, you are including sensor.h, is it necessary? I mean, you are including it from the arduino project and from that file, maybe that's the cause? As I understand, if I write a class A, i should create two files: A.h & A.cpp. A.cpp must include A.h... Anyway, if I comment the string #include "sensor.h" in sensor.cpp, i get this errors: sensor.cpp:4: error: 'Sensor' has not been declared Btw you can download my test project and compile it with different includes... Thank you for your help and suggestions!!! Quote Link to comment Share on other sites More sharing options...
liamlau Posted May 24, 2014 Report Share Posted May 24, 2014 hi,buddy, have you solved the problem , i am facing the same problem, and i can fix it right now , would you like to help me ? here is my email , xllau@126.com. call me liam. thanks very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.