Postby orkboy59 » 02 Sep 2013 16:03
Hi all,
I am messing around with the LSM303 compass and accelerometer and am having issues with the sketch compiling. I am using the example sketch, which is below, and am running into several errors, which are below as well.
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303.h>
/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Mag mag = Adafruit_LSM303_Mag(12345);
void displaySensorDetails(void)
{
sensor_t sensor;
mag.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" uT");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" uT");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" uT");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}
void setup(void)
{
Serial.begin(9600);
Serial.println("Magnetometer Test"); Serial.println("");
/* Initialise the sensor */
if(!mag.begin())
{
/* There was a problem detecting the LSM303 ... check your connections */
Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
while(1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
}
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
mag.getEvent(&event);
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print(" ");Serial.println("uT");
delay(500);
}
Code: Select all
In file included from magsensor.ino:3:
/Users/conanmills/Documents/Arduino/libraries/Adafruit_LSM303DLHC/Adafruit_LSM303.h:137: error: expected class-name before '{' token
/Users/conanmills/Documents/Arduino/libraries/Adafruit_LSM303DLHC/Adafruit_LSM303.h:142: error: 'sensors_event_t' has not been declared
/Users/conanmills/Documents/Arduino/libraries/Adafruit_LSM303DLHC/Adafruit_LSM303.h:143: error: 'sensor_t' has not been declared
/Users/conanmills/Documents/Arduino/libraries/Adafruit_LSM303DLHC/Adafruit_LSM303.h:156: error: expected class-name before '{' token
/Users/conanmills/Documents/Arduino/libraries/Adafruit_LSM303DLHC/Adafruit_LSM303.h:162: error: 'sensors_event_t' has not been declared
/Users/conanmills/Documents/Arduino/libraries/Adafruit_LSM303DLHC/Adafruit_LSM303.h:163: error: 'sensor_t' has not been declared
magsensor.ino: In function 'void displaySensorDetails()':
magsensor:10: error: 'sensor_t' was not declared in this scope
magsensor:10: error: expected `;' before 'sensor'
magsensor:11: error: 'sensor' was not declared in this scope
magsensor.ino: In function 'void loop()':
magsensor:44: error: 'sensors_event_t' was not declared in this scope
magsensor:44: error: expected `;' before 'event'
magsensor:45: error: 'event' was not declared in this scope
I am new to Arduino, but I know I have the files in the right place on this one. Any help would be greatly appreciated.
Conan