Error: Does not name a type

I keep getting this error message even though I have SFE_LSM9DS0 .cpp and .h files in the a folder labelled SFE_LSM9DS0 in the libraries folder in arduino. Any Help?
here is the code…

// The SFE_LSM9DS0 requires both the SPI and Wire libraries.
// Unfortunately, you’ll need to include both in the Arduino
// sketch, before including the SFE_LSM9DS0 library.
#include <SPI.h> // Included for SFE_LSM9DS0 library
#include <Wire.h> // Use the modified version to allow for the buffer not being full
#include <SFE_LSM9DS0.h>

// Example I2C Setup //
// Comment out this section if you’re using SPI
// SDO_XM and SDO_G are both grounded, so our addresses are:
#define LSM9DS0_XM 0x1D // Would be 0x1E if SDO_XM is LOW
#define LSM9DS0_G 0x6B // Would be 0x6A if SDO_G is LOW
// Create an instance of the LSM9DS0 library called dof the
// parameters for this constructor are:
// [SPI or I2C Mode declaration],[gyro I2C address],[xm I2C add.]

// Example SPI Setup //
/* // Uncomment this section if you’re using SPI
#define LSM9DS0_CSG 9 // CSG connected to Arduino pin 9
#define LSM9DS0_CSXM 10 // CSXM connected to Arduino pin 10

// Do you want to print calculated values or raw ADC ticks read
// from the sensor? Comment out ONE of the two #defines below
// to pick:
//#define PRINT_RAW

#define PRINT_SPEED 50 // 500 ms between prints

const int ledPin = 13;
const int buttonPin=11;

// Interrupt Pin Definitions //
const byte INT1XM =6; // INT1XM tells us when accel data is ready
const byte INT2XM = 7; // INT2XM tells us when mag data is ready
const byte DRDYG = 5; // DRDYG tells us when gyro data is ready

int lastButtonState=LOW;
int currentButtonState=LOW;
boolean outputOn=true;
unsigned long lastButtonClickTime=0;

int averageCount=0;
double averageX=0;
double averageY=0;
double averageZ=0;

void setup()
// wait a minute before starting to allow the LSM9DS0
// Serial.begin(115200); // Start serial at 115200 bps
// Use the begin() function to initialize the LSM9DS0 library.
// You can either call it with no parameters (the easy way):
uint16_t status = dof.begin();
// Or call it with declarations for sensor scales and data rates:
//uint16_t status = dof.begin(dof.G_SCALE_2000DPS,
// dof.A_SCALE_6G, dof.M_SCALE_2GS);

// begin() returns a 16-bit value which includes both the gyro
// and accelerometers WHO_AM_I response. You can check this to
// make sure communication was successful.
//Serial.print(“LSM9DS0 WHO_AM_I’s returned: 0x”);
//Serial.println(status, HEX);
//Serial.println(“Should be 0x49D4”);

pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
// Set up interrupt pins as inputs:
pinMode(INT1XM, INPUT);
pinMode(INT2XM, INPUT);
pinMode(DRDYG, INPUT);

digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)

//ignore the first 10 readings - they are normally not so good

for (int i=0;i<10;i++){

void loop()
// check if the button is toggled to turn the mouse function on and off. When turning off, the stable position will be reset
currentButtonState = digitalRead(buttonPin);
if ((currentButtonState!=lastButtonState && ((millis()-lastButtonClickTime)>100)) ){
if(currentButtonState==LOW ){
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
} else {
digitalWrite(ledPin, LOW); // turn the LED on (HIGH is the voltage level)


// calculate the average gyroscope reading of the stationary device - it’s probably not 0, so we need to factor that out.
} else if (averageCount==30){
//Serial.print(averageX, 2);
//Serial.print(", “);
//Serial.print(averageY, 2);
//Serial.print(”, ");
//Serial.println(averageZ, 2);
} else {

//printGyro(); // Print “G: gx, gy, gz”
// Serial.println();

// delay(PRINT_SPEED);


void printGyro()
// To read from the gyroscope, you must first call the
// readGyro() function. When this exits, it’ll update the
// gx, gy, and gz variables with the most current data.

// Now we can use the gx, gy, and gz variables as we please.
// Either print them as raw ADC values, or calculated in DPS.
Serial.print("G: “);
// If you want to print calculated values, you can use the
// calcGyro helper function to convert a raw ADC value to
// DPS. Give the function the value that you want to convert.
Serial.print((dof.calcGyro(dof.gx)-averageX), 2);
Serial.print(”, “);
Serial.print((dof.calcGyro(, 2);
Serial.print(”, ");
Serial.print(dof.calcGyro(dof.gz)-averageZ, 2);
Serial.print ("X= ");
Serial.println((dof.calcGyro(dof.gx)-averageX)*dof.calcAccel( +(dof.calcGyro( , 2);
#elif defined PRINT_RAW
// Serial.print(dof.gx);
// Serial.print(", “);
// Serial.print(;
//Serial.print(”, ");
// Serial.println(dof.gz);

void mouseMoveGyro()

// wait until there is both an accelerometer and gyroscope reading
if ( (digitalRead(INT1XM)) && (digitalRead(DRDYG)))

// read the values


// move the mouse left and right depending on gyroscope movement on the X and Y axis, scaled by the accelerometer reading to allow it to point in any direction.
// move the mouse up and down based on the z axis rotation. Designed for the chip facing right. Reveerse the Z calculation if facing left.
Mouse.move((averageX-dof.calcGyro(dof.gx))*dof.calcAccel( +(averageY-dof.calcGyro(*dof.calcAccel(dof.ay), averageZ-dof.calcGyro(dof.gz));


void recordAverageGyro(){
// add another gyroscope reading to build up an average.

Apparently you didn't read the stickies at the top of the forum that you were supposed to read before you blundered in here. That is NOT how to post code.

You would also have learned that you are supposed to tell us where you got the library that is causing you grief.

failed to name a type error, almost always means that your #include did not work.

You might have put the file in the wrong place - check.

The library files for code you have written yourself or downloaded from some random place, go in a different places to the standard arduino libraries.

You also need to close and restart the Arduino IDE so it can see the new library files when you restart it.

Are you using an Arduino Leonardo? If not, you can’t use Mouse, as it will not work on the Uno or Mega2650.

I went to github and grabbed a version of the SFE_LSM9DS0 library. I got it from GitHub - kriswiner/LSM9DS0: LSM9DS0 9DOF sensor AHRS sketch, extracted it, placed it in the libraries\SFE_LSM9DS0 folder, and started compiling.

I commented out several lines that were trying to use the Mouse class, but I ended up with one error. Turns out that the version of the library I downloaded had an error. Here’s the erroneous code in that library. It’s on line 641 or 643 (duplicate lines, comment one or both out).

void LSM9DS0::I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data)  //  **** this one
        // Wire.h read and write protocols
        void LSM9DS0::I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data)  // **** or this one
	Wire.beginTransmission(address);  // Initialize the Tx buffer
	Wire.write(subAddress);           // Put slave register address in Tx buffer
	Wire.write(data);                 // Put data in Tx buffer
	Wire.endTransmission();           // Send the Tx buffer

After these changes, it compiled just fine. I can’t test it though, because I don’t have the SFE_LSM9DS0 hardware.