L3G4200D code fails to compile

Received my L3G400D board on Friday. The example code does not compile, failing at line L3G4200D gyro;

Hello,

Did you follow the instructions for installing the library as described in the readme on the GitHub page? (The “L3G4200D” folder should be in the “libraries” directory of your Arduino installation, for example C:\arduino-0022\libraries\L3G4200D. Inside that folder should be an “examples” folder and two files, L3G4200D.cpp and L3G4200D.h.)

If you still have trouble getting the code to compile, please paste the exact error message that the Arduino environment is giving you.

- Kevin

The L3G4200D folder is under libraries and contains the example folder . In the example folder are the Serial folder and the cpp and h files. Serial contains just the serial.pde. I can load the serial program. However a compile gives this error message at the line - L3G4200D gyro;

Serial:3: error: ‘L3G4200D’ does not name a type
Serial.cpp: In function ‘void setup()’:
Serial:8: error: ‘gyro’ was not declared in this scope
Serial.cpp: In function ‘void loop()’:
Serial:12: error: ‘gyro’ was not declared in this scope

On another note I’ve had the students running the spark fun SPI code on it and initial impression is that this gyro is much more stable than the analog one we were using. Hopefully our robot will be able to drive straight.

L3G4200D.cpp and L3G4200D.h should not be in the examples folder; they should be up a level, in the L3G4200D folder. Could you try moving them there to see if that allows the program to compile successfully? (You might have to restart the Arduino environment after you move the files.)

- Kevin

Moved the files and the exact same errors.

Hello,

Can you verify that this is the file structure you have?

arduino/libraries/
->L3G4200D
->->examples
->->->serial
->->->->Serial.pde
->->L3G4200D.h
->->L3G4200D.cpp

If that doesn’t work, please tell us what version of Arduino you are using and what operating system you are using it on.

- Ryan

I have moved the .cpp and h files to all directories and tried to compile all combos. Same error message. Windows vista, Arduino 0022, Arduino uno.

Putting the files in random directories is unlikely to work. You should try to make sure the files are in the exact structure I described in my last post. I think it is time to try the entire process over again.

  1. Download github.com/pololu/L3G4200D/zipball/1.0.0
  2. Decompress the zip archive
  3. Copy the folder called L3G4200D into C:\path\to\arduino-0022\libraries\
  4. Verify the directory and file structure matches my last post (you should not have to move any files to achieve this)
  5. Start the Arduino software
  6. Go to File->Examples->L3G4200D->Serial
  7. Click the Verify button
  8. The output should say “Done compiling…binary sketch size: 4294 bytes…”

If this procedure does not work for you, I think you should try reinstalling the Arduino software.

- Ryan

We have done everything that you mentioned before we posted. Your code does not compile. We posted in consideration of other customers. Have you tried a clean install? Does it work? We have working code based on SPI and have moved on.

Hello.

It works fine for me. I just installed arduino-0022 on my computer, put the unzipped L3G4200D directory (as downloaded from GitHub) into the libraries folder, started the IDE, selected the L3G4200D->serial example, and clicked verify. The compilation was successful. I think you are either doing something wrong or have a corrupted download.

- Ben

One thing to make sure of is that you are copying only the folder named “L3G4200D” into the libraries directory, not the folder named “pololu-L3G4200D-67296af” which is in the top level of the zip file. Again, the exact path to the .cpp and .h files should be:

arduino-0022\libraries\L3G4200D\L3G4200D.cpp
arduino-0022\libraries\L3G4200D\L3G4200D.h

If I copy the entire “pololu-L3G4200D-67296af” folder into the libraries directory instead, I can access the example but I get the same compile error that you reported, so maybe that is what you are doing. Several of us here have tried clean installs multiple times and been able to compile the example program successfully.

- Kevin

I had the students do exactly that last night and still the same error. Several different computers. Will look at this closer tonight.