Help with my I2C gyro

Hello,

I'm trying to run this code which simply reads values from a gyro. The problem seems to be in the libraries I added, here's the code I'm using.

#include <Wire.h>
#include <L3G4200D.h>

L3G4200D gyro;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  gyro.enableDefault();
}

void loop() {
  gyro.read();

  Serial.print("G ");
  Serial.print("X: ");
  Serial.print((int)gyro.g.x);
  Serial.print(" Y: ");
  Serial.print((int)gyro.g.y);
  Serial.print(" Z: ");
  Serial.println((int)gyro.g.z);

  delay(100);
}

And here's the error I'm getting

In file included from Serial.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:4:43: error: Arduino.h: No such file or directory
In file included from Serial.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:52: error: 'byte' does not name a type

I'm stuck :frowning: I don't have experience using libraries with Arduino so I guess it's something to do with it. Any comments and suggestions will be much appreciated, thanks.

C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:4:43: error: Arduino.h: No such file or directory

What version of the IDE are you using? If you are not using 1.0, why are you using a library for 1.0?

Thanks Paul,

You're right! I'm using the 0022 version, I also have the new version though (1.0) and I get this error

In file included from sketch_feb10a.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:4:43: error: Arduino.h: No such file or directory
In file included from sketch_feb10a.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:52: error: 'byte' does not name a type
sketch_feb10a.cpp: In function 'void setup()':
sketch_feb10a:6: error: 'Serial' was not declared in this scope
sketch_feb10a.cpp: In function 'void loop()':
sketch_feb10a:14: error: 'Serial' was not declared in this scope
sketch_feb10a:22: error: 'delay' was not declared in this scope

Any idea what's wrong?

Any idea what's wrong?

"I have both versions. I ran one of them, but I won't tell you which, and I got this..."

No, sorry. My crystal ball is out for cleaning.

However, the fact that the compiler can't find Arduino.h implies that you are using 0022 to compile a 1.0 library. Isn't that enough of a clue?

Paul, I think you misunderstood what I wrote, or maybe I wasn't clear :slight_smile:

I've been using 0022 version for like a year (maybe less), but now I have a gyro and I can't get it to work with the 0022 version, the code I'm trying to run is this

#include <Wire.h>
#include <L3G4200D.h>

L3G4200D gyro;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  gyro.enableDefault();
}

void loop() {
  gyro.read();

  Serial.print("G ");
  Serial.print("X: ");
  Serial.print((int)gyro.g.x);
  Serial.print(" Y: ");
  Serial.print((int)gyro.g.y);
  Serial.print(" Z: ");
  Serial.println((int)gyro.g.z);

  delay(100);
}

And the error I get

In file included from Serial.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:4:43: error: Arduino.h: No such file or directory
In file included from Serial.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:52: error: 'byte' does not name a type

I learned there was a new version, 1.0, so I installed it but when I run the same code I get the same error + some extra lines,

In file included from sketch_feb10a.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:4:43: error: Arduino.h: No such file or directory
In file included from sketch_feb10a.cpp:2:
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:51: error: 'byte' has not been declared
C:\Users\User\Documents\Arduino\libraries\L3G4200D/L3G4200D.h:52: error: 'byte' does not name a type
sketch_feb10a.cpp: In function 'void setup()':
sketch_feb10a:6: error: 'Serial' was not declared in this scope
sketch_feb10a.cpp: In function 'void loop()':
sketch_feb10a:14: error: 'Serial' was not declared in this scope
sketch_feb10a:22: error: 'delay' was not declared in this scope

There's a library I'm using to run the gyro (L3G4200D). In the Arduino "libraries" directory I copied and pasted the corresponding folder with its files. However, I'm stuck, with both IDEs I get the same.

I obviously don't know much about Arduino libraries, only the basics. That's basically why I'm asking for help :slight_smile:

In the Arduino "libraries" directory I copied and pasted the corresponding folder with its files.

In which Arduino libraries directory? If you have two versions of the IDE, you have 3 possible libraries folders. Only one of them is the right place for downloaded libraries.

Where DID you download the library from?

The Arduino.h file IS part of Arduino 1.0. If you are running the 1.0 version of the IDE, save the sketch. Look at the folder you saved the sketch in. The file should have the .ino extension. If it doesn't, you aren't running the 1.0 version, which explains the error messages.

In which Arduino libraries directory? If you have two versions of the IDE, you have 3 possible libraries folders. Only one of them is the right place for downloaded libraries.

First I copied and pasted it in the 0022 libraries directory, as it didn't work I installed the 1.0 and did the same, I copied and pasted it in the libraries directory of the new IDE, same problem.

Why do you say there are 3 possible libraries folders? and not two?

Where DID you download the library from?

The Arduino.h file IS part of Arduino 1.0. If you are running the 1.0 version of the IDE, save the sketch. Look at the folder you saved the sketch in. The file should have the .ino extension. If it doesn't, you aren't running the 1.0 version, which explains the error messages.

I saved the file and the extension is ".ino"

:frowning:

Why do you say there are 3 possible libraries folders? and not two?

Official libraries go in the libraries folder under installPath\Arduino-0022 or installPath\Arduino-1.0.

User downloaded libraries go in the libraries folder (created, if needed) in the user's sketchbook location.

I downloaded the library, and unzipped it. I opened the sketch example, named serial.pde, using 0022 and tried to compile it. I got the same errors you got.

Then, I opened the same sketch in 1.0, and got this error when compiling:

Binary sketch size: 5264 bytes (of a 30720 byte maximum)

So, it looks like you are running 0022, only.

 I opened the same sketch in 1.0, and got this error when compiling

I loved the ironic comment, I actually managed to get the same error you're getting, thanks.

I guess the problem was that I can't have two Arduino IDEs on the computer ? I was running the code in the 1.0 but I would always get that (extended) error. The problem got solved when I deleted the 0022 and restarted the computer. Never thought that'd be the problem.

I guess the problem was that I can't have two Arduino IDEs on the computer ?

I do. That's how I was able to reproduce your problem, and get a clean build.