LSM303DLHC
Moderators: adafruit_support_bill, adafruit

LSM303DLHC

by mamazzi on Fri Jan 10, 2014 6:48 am

Hello!

I recently purchased the LSM303DLHC accel + compass and ST7565 negative LCD screen.

I am trying to get the LSM303DLHC accel + compass to work. Unfortunately, I am not able to compile the code after going through the tutorial via this: http://learn.adafruit.com/lsm303-accele ... out/coding.

Initially I faced the error ( pic ref LSM3030error.jpg) but rectified it through your forum. Now I am facing this prob ( pic ref LSM3030error2.jpg)

'sensor_t' was not declared in the scope.

Really appreciate the help!

Thanks!
Attachments
LSM3030error2.jpg
LSM3030error2.jpg (266.13 KiB) Viewed 436 times
LSM3030error.jpg
LSM3030error.jpg (189.6 KiB) Viewed 436 times
mamazzi
 
Posts: 6
Joined: Tue Dec 31, 2013 7:42 am

Re: LSM303DLHC

by adafruit_support_bill on Fri Jan 10, 2014 7:32 am

Looks like you have not installed the sensor library. https://github.com/adafruit/Adafruit_Sensor
User avatar
adafruit_support_bill
 
Posts: 31676
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303DLHC

by mamazzi on Sun Jan 12, 2014 2:31 am

Hi Bill

I have installed the library, but it doesn't appear on my examples. I'm using Arduino 1.0.5
Attachments
pic1.jpg
pic1.jpg (207.87 KiB) Viewed 397 times
mamazzi
 
Posts: 6
Joined: Tue Dec 31, 2013 7:42 am

Re: LSM303DLHC

by adafruit_support_bill on Sun Jan 12, 2014 8:28 am

Did you completely exit from all open instances of the Arduino IDE after installing the library? The IDE will not recognize libraries installed after it is opened. http://learn.adafruit.com/adafruit-all- ... nstall-use
User avatar
adafruit_support_bill
 
Posts: 31676
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303DLHC

by mamazzi on Sun Jan 12, 2014 11:02 pm

Yes I completely emptied out my libraries and re-installed each folder one by one. Unfortunately, the adafruit unified sensor library is still not installed. The rest of the folders are working fine
mamazzi
 
Posts: 6
Joined: Tue Dec 31, 2013 7:42 am

Re: LSM303DLHC

by adafruit_support_bill on Mon Jan 13, 2014 7:24 am

The sensor library won't show up in the examples menu because there are no examples for it. The Sensor library is just a common base-class library for all Adafruit Sensors that are part of the Unified Sensor system.
User avatar
adafruit_support_bill
 
Posts: 31676
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303DLHC

by mamazzi on Mon Jan 13, 2014 7:45 am

Thank you Bill, maybe I will just change my payload that does not use the unified sensor system.
mamazzi
 
Posts: 6
Joined: Tue Dec 31, 2013 7:42 am

Re: LSM303DLHC

by mamazzi on Fri Jan 31, 2014 8:01 am

Hi Bill

I finally managed to got it up and running. Can I know how do I display both the accelerometer and magnetometer readings in the same serial monitor. I tried combining both the codes but to avail.

Thanks!
mamazzi
 
Posts: 6
Joined: Tue Dec 31, 2013 7:42 am

Re: LSM303DLHC

by adafruit_support_bill on Fri Jan 31, 2014 9:07 am

You have to make sure you get both the setup and the loop code for both. Something like this should work:

Code: Select all | TOGGLE FULL SIZE
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Accel accel = Adafruit_LSM303_Accel(54321);
Adafruit_LSM303_Mag mag = Adafruit_LSM303_Mag(12345);

void displaySensorDetails(void)
{
  sensor_t sensor;
  accel.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(" m/s^2");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" m/s^2");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" m/s^2"); 
  Serial.println("------------------------------------");
  Serial.println("");
  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("Accelerometer/Magnetometer Test"); Serial.println("");
 
  /* Initialise the sensor */
  if(!accel.begin())
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
    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;
  accel.getEvent(&event);
 
  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");Serial.println("m/s^2 ");
 
  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);
}
User avatar
adafruit_support_bill
 
Posts: 31676
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303DLHC

by mamazzi on Sat Feb 01, 2014 12:45 am

Thanks alot Bill.

I keep getting the "XXXX does not name a type" error. After countless restarts of the Arduino IDE, it finally works. Any way that I can reduce this time?
mamazzi
 
Posts: 6
Joined: Tue Dec 31, 2013 7:42 am

Re: LSM303DLHC

by adafruit_support_bill on Sat Feb 01, 2014 8:23 am

I keep getting the "XXXX does not name a type" error.

That error means that the compiler was not able to find the library. Usually that means that the library was either not installed, or it was installed in the wrong location. Not sure why re-starting the IDE would fix anything. But make sure that you do have it installed in the correct location: http://learn.adafruit.com/adafruit-all- ... nstall-use
User avatar
adafruit_support_bill
 
Posts: 31676
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303DLHC

by inof8or on Tue Feb 18, 2014 2:49 pm

For some reason I'm running into the same issue

I checked out the link and relocated my libraries to the proper library folder in my sketch folder
and renamed the folder so it matched the .h minus the .h of course. /home/***/***/Arduino/sketchbook/libraries/Adafruit_Sensor

Restarting has done little to rectify the issue in my case

Maybe I need to fulfill the library dependencies?

Code: Select all | TOGGLE FULL SIZE

#if ARDUINO >= 100
 #include "Arduino.h"
 #include "Print.h"
#else
 #include "WProgram.h"
#endif

inof8or
 
Posts: 25
Joined: Fri Jan 10, 2014 3:43 pm

Re: LSM303DLHC

by inof8or on Tue Feb 18, 2014 3:32 pm

Image

the 9dof library depends on Adafruit_Sensors, If the library is failing to load it should catch 9dof first, right?

I am just trying to get the lsm303 working but I figured I would look at how similar libraries would react

inof8or
 
Posts: 25
Joined: Fri Jan 10, 2014 3:43 pm

Re: LSM303DLHC

by adafruit_support_bill on Tue Feb 18, 2014 4:02 pm

Scroll to the top of the output window and post the first few lines of the error output. Those are usually the most relevant error messages.
User avatar
adafruit_support_bill
 
Posts: 31676
Joined: Sat Feb 07, 2009 10:11 am

Re: LSM303DLHC

by inof8or on Thu Feb 20, 2014 10:23 pm

Sorry, late, I thought I have subscribed to this post.

Image

inof8or
 
Posts: 25
Joined: Fri Jan 10, 2014 3:43 pm