Pages: [1]   Go Down
Author Topic: MPU-6050 + Servo + arduino Uno - fail when uploading  (Read 3967 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So far I have the gy-521 connected to my arduino and can see it is working great through the serial monitor.

Now I want to get the gy-521 to control a parallel motion through a servo-motor, just like this:



So I took the code from Luka's webpage:
http://lukagabric.com/arduino-mpu6050/

I've installed all libraries... as far as I know..(I can see the codes in arduino 1.05 in the library)  but when I try to upload the code to my arduino board I get this message:

sketch_jun08c.ino:2:20: error: I2Cdev.h: No such file or directory
sketch_jun08c.ino:3:21: error: MPU6050.h: No such file or directory
sketch_jun08c.ino:4:11: error: #include expects "FILENAME" or <FILENAME>
sketch_jun08c:6: error: 'MPU6050' does not name a type
sketch_jun08c:11: error: 'Servo' does not name a type
sketch_jun08c.ino: In function 'void setup()':
sketch_jun08c:22: error: 'mpu' was not declared in this scope
sketch_jun08c:24: error: 'myservo' was not declared in this scope
sketch_jun08c.ino: In function 'void loop()':
sketch_jun08c:29: error: 'mpu' was not declared in this scope
sketch_jun08c:29: error: 'amp' was not declared in this scope
sketch_jun08c:29: error: expected `;' before ')' token
sketch_jun08c:34: error: 'myservo' was not declared in this scope

I've being sitting with this for so long that I have lost the big picture of all this.. so I hope someone can see where the problem might could be. What I've read through google is that the problem is the files in my library. but I've also followed this guide to make sure no problem would come.. http://arduino.cc/de/Guide/Libraries

Sorry for my bad english! im from Denmark.



Best regards.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Anyone?

Best regards.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have a problem with wrong folder/libraries/versions/include files.

Since Luka is using the I2Cdevlib library, you should install the library for i2cdevlib and the library for the MPU-6050 from this site: http://www.i2cdevlib.com/

Your compiler is telling you, that you have neither of those libraries.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your reply! (:

As you can see I've installed the library from http://www.i2cdevlib.com/

and I've also installed the freeimu library, and both gives that error output when trying to uploading it when using Jeff rowbergs code. I don't get it..??

see attached picture..


* Arduino picture.jpg (87.44 KB, 609x640 - viewed 185 times.)
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Luka code has an empty include at line 4.
Could you remove that line?
Could you also change the other includes to use '<' and '>'
Code:
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
And try to compile again.


If that doesn't work, I suggest to make a fresh start.
Download the newest Arduino 1.0.5.
Unzip it in a new folder and select a new project folder.
Download the I2Cdevlib and the MPU-6050 library in put it in the library folder.
Try both example sketches for the MPU-6050.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks alot, now the errors got minimize a bit smiley

and ended up with:
luca_sketch_MPU6050:6: error: 'MPU6050' does not name a type
luca_sketch_MPU6050:11: error: 'Servo' does not name a type
luca_sketch_MPU6050.ino: In function 'void setup()':
luca_sketch_MPU6050:22: error: 'mpu' was not declared in this scope
luca_sketch_MPU6050:24: error: 'myservo' was not declared in this scope
luca_sketch_MPU6050.ino: In function 'void loop()':
luca_sketch_MPU6050:29: error: 'mpu' was not declared in this scope
luca_sketch_MPU6050:29: error: 'amp' was not declared in this scope
luca_sketch_MPU6050:29: error: expected `;' before ')' token
luca_sketch_MPU6050:34: error: 'myservo' was not declared in this scope

Code:
#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>

 
MPU6050 mpu; // SO IT SEEMS THAT THIS STATEMENT IS ONE OF THE PROBLEMS RIGHT?
 
int16_t ax, ay, az;
int16_t gx, gy, gz;
 
Servo myservo;
 
int val;
int prevVal;
 
void setup()
{
    Wire.begin();
    Serial.begin(38400);
 
    Serial.println("Initialize MPU");
    mpu.initialize();
    Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");
    myservo.attach(9);
}
 
void loop()
{
    mpu.getMotion6(&amp;ax, &amp;ay, &amp;az, &amp;gx, &amp;gy, &amp;gz);
 
    val = map(ay, -17000, 17000, 0, 179);
    if (val != prevVal)
    {
        myservo.write(val);
        prevVal = val;
    }
 
    delay(50);
}

Best regards, and thanks alot again for your time, I really appreciate it. if there aint any problem you can see then Im going to reinstall it all, but I hope we can figure it out so that wont be the solution.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is one of the two examples for the MPU-6050 library, https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_raw/MPU6050_raw.ino

The "MPU6050 something;" declares the class for the MPU6050.
That is only possible if you have installed the MPU6050 library. So I guess you still have to install it.

Did you install the i2cdev library with a zip file ?
I only can find the sources, https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/I2Cdev
You can install the MPU6050 library the same way, https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050

If you post your sketch, please copy-paste it between [code] ... [/code] tags.
Logged

Kuwait
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Erdin and Dynamitetalks
i am a beginner in Arduino world. and am working on the same thing facing the same issues Dynamitetalks has.

Erdin your question about a zip file library, should it be zipped?
yes the errors narrowed down to the same as follow.

GYRO_Servo:6: error: 'MPU6050' does not name a type
GYRO_Servo:11: error: 'Servo' does not name a type
GYRO_Servo.ino: In function 'void setup()':
GYRO_Servo:22: error: 'mpu' was not declared in this scope
GYRO_Servo:24: error: 'myservo' was not declared in this scope
GYRO_Servo.ino: In function 'void loop()':
GYRO_Servo:29: error: 'mpu' was not declared in this scope
GYRO_Servo:29: error: 'amp' was not declared in this scope
GYRO_Servo:29: error: expected `;' before ')' token
GYRO_Servo:34: error: 'myservo' was not declared in this scope

any suggestions?
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are a beginner, start at the begin.
Run the i2c scanner:
http://playground.arduino.cc/Main/I2cScanner

Is your sensor detected ?

There is a test sketch that doesn't need libraries:
http://playground.arduino.cc/Main/MPU-6050

Do the values change if you move and tilt and rotate the sensor ?

You have servo motors connected ?
Can you run a simple test sketch to test the servo motors ?
How are they powered ?

Next step will be the i2cdevlib library.
Did you install that library ? how ? from what website ? do you use the newest arduino ? which arduino board ?
Logged

Kuwait
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Erdin,
Thank you so so much for taking the time for me, appreciate it much.

Yes my sensor is detected 0x68.
Yes the test was a success and values change with every movement.
I did a test and the servo motor is working properly. A sweep motion

The I2Cdevlib as I named the folder in the library folder of the program and pasted the files I downloaded from the site provided here.

My arduino is the latese UNO board

Different errors now they are as follow

In file included from GYRO_Servo.ino:3:
E:\ARDUINO\libraries\MPU6050/MPU6050.h:9: error: stray '\302' in program
E:\ARDUINO\libraries\MPU6050/MPU6050.h:9: error: stray '\267' in program
E:\ARDUINO\libraries\MPU6050/MPU6050.h:9: error: stray '\302' in program
E:\ARDUINO\libraries\MPU6050/MPU6050.h:9: error: stray '\267' in program
In file included from GYRO_Servo.ino:3:
E:\ARDUINO\libraries\MPU6050/MPU6050.h:315:46: error: invalid suffix "a8ae95ca13abf004028130f61cdbc88" on integer constant
E:\ARDUINO\libraries\MPU6050/MPU6050.h:316:62: error: invalid suffix "a8ae95ca13abf004028130f61cdbc88" on integer constant
E:\ARDUINO\libraries\MPU6050/MPU6050.h:4: error: expected unqualified-id before '<' token
E:\ARDUINO\libraries\MPU6050/MPU6050.h:1480: error: expected unqualified-id before numeric constant

Once again thank you Erdin
Mishal
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have seen this problem a week earlier. I don't know if it was solved.
It might have to do with a conflict between: character coding / UTF-8 / Windows / Linux.

Either the source code has wrong characters (Jeff Rowberg should fix that) or perhaps you did a copy-paste with the html code, or opened it in an editor that chanched the character coding.

I downloaded the "Raw" if this file: https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/MPU6050.h
And I could not find any weird characters.
Logged

Kuwait
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Erdin,
i re did all the steps with the libraries, and now i am getting different errors.

GYRO_Servo:13: error: 'Servo' does not name a type
GYRO_Servo.ino: In function 'void setup()':
GYRO_Servo:26: error: 'myservo' was not declared in this scope
GYRO_Servo.ino: In function 'void loop()':
GYRO_Servo:31: error: 'amp' was not declared in this scope
GYRO_Servo:31: error: expected `;' before ')' token
GYRO_Servo:36: error: 'myservo' was not declared in this scope

i hope i am not bothering you or any one els with my bigenners quaries  smiley

Thanks, Mishal
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Something with the class "Servo" is missing.
Look at the examples (on the right side, click on a few examples):
http://arduino.cc/en/reference/servo
Do you have: #include <Servo.h>

Please read this:
http://forum.arduino.cc/index.php?topic=97455.0
After reading that, you can ask as many questions as you like. We like to see the whole sketch (between code tags), and you have to tell what you are talking about and how you solved it, so others can see the solution.

How did you solve the problem with the weird characters ?

Where did the file GYRO_servo.ino come from ? I have no idea what it is.

Logged

Kuwait
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear Erdin
Thank you for the heads up, and mostly thank you for pointing me to the solution, its working now.

As you suggested i had to add the [#include <Servo.h>] in my sketch, and changed the getMotion6 argument. the sketch is as follow,

[#include <Wire.h>
#include <I2Cdev.h>
#include <Servo.h>
#include <MPU6050.h>

 
MPU6050 mpu; // SO IT SEEMS THAT THIS STATEMENT IS ONE OF THE PROBLEMS RIGHT?
 
int16_t ax, ay, az;
int16_t gx, gy, gz;

Servo myservo;

int val;
int prevVal;

void setup()
{
    Wire.begin();
    Serial.begin(38400);
 
    Serial.println("Initialize MPU");
    mpu.initialize();
    Serial.println(mpu.testConnection() ? "Connected" : "Connection failed");
    myservo.attach(9);
}

void loop()
{
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); // this was mpu.getMotion6(&amp;ax, &amp;ay, &amp;az, &amp;gx, &amp;gy, &amp;gz);
 
    val = map(ay, -17000, 17000, 0, 179);
    if (val != prevVal)
    {
        myservo.write(val);
        prevVal = val;
    }
 
    delay(50);
}]



Once again thank you Erdin.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very cool indeed. Well done.
This is a good guide for balancing and filtering: http://forum.arduino.cc/index.php?topic=58048.0
Logged

Pages: [1]   Go Up
Jump to: