LSM303 Code Help

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
orkboy59
 
Posts: 3
Joined: Wed Jul 31, 2013 4:22 pm

LSM303 Code Help

Post by orkboy59 »

'sensors_event_t' was not declared in this scope
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);
}
Errors

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

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303 Code Help

Post by adafruit_support_bill »

It could be either a corrupted copy of the library, or possibly you have more than one instance installed. Make sure you have only one copy of the library. Remove (rename is not enough!) any duplicates from both the Arduino install libraries folder and your sketchbook libraries folder.
http://learn.adafruit.com/adafruit-all- ... nstall-use

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”