Hi
I'm new to Arduino and programming in general and I had this code running but now I seem to have messed up and I get error messages when "Linking everything together"... which basically says:-
In function 'setup':
Undefined reference to 'Adafruit_LSM303::begin()'
In function 'setup':
Undefined reference to 'Adafruit_LSM303::begin()'
If anybody is able to spot my error that would be much appreciated !
The code is intended to operate a magnetic sensor with an encoder so that magnetic readings can be plotted against distance. The code is: -
// add adafruit sketch
#include <Wire.h>
#include <Adafruit_LSM303.h>
Adafruit_LSM303 lsm;
int val;
int totmag;
// Digital pin definitions
enum enDigitalPins
{
// Rotary encoder input lines
dpInEncoderA=2,
dpInEncoderB=4,
dpInEncoderPress=6,
};
static void _ResetPins()
{
// Rotary encoder input lines
// Configure as input, turn on pullup resistors
pinMode(dpInEncoderA, INPUT);
digitalWrite(dpInEncoderA, HIGH);
pinMode(dpInEncoderB, INPUT);
digitalWrite(dpInEncoderB, HIGH);
pinMode(dpInEncoderPress, INPUT);
digitalWrite(dpInEncoderPress, HIGH);
}
void setup()
{
//configure the pins
_ResetPins();
// init serial communication
Serial.begin(9600);
config_MP();
Serial.println("Ready to begin");
// start adafruit
if (!lsm.begin()) // Try to initialise and warn if we couldn't detect
{
Serial.println("Oops...unable to initialise the LSM303. Check wiring");
while (1);
}
//end adafruit
}
void _lowlevel_ReadEncoder(int &rotate,int& press)
{
rotate = (digitalRead(dpInEncoderB) * 2) +digitalRead(dpInEncoderA);
press =digitalRead(dpInEncoderPress);
}
void loop()
{
ReadEncoder();
}
void ReadEncoder()
{
int Position, Press;
int isFwd = 0;
int depth = 0;
_ResetPins();
Serial.println("Reading the encoder... rotate the knob by one click");
_lowlevel_ReadEncoder(Position, Press);
while (!Serial.available())
{
int Position2, Press2;
do
{
_lowlevel_ReadEncoder(Position2, Press2);
}while ((Position2 == Position) && (Press2 == Press));
if (Position2 != Position)
{
// "Forward" is shown by the position going from (0 to 1) or (1 to 3)
// or (3 to 2) or (2 to 0). Anything else indicates that the user is
// turning the device the other way.
int isFwd = ((Position == 0) && (Position2 == 1)) ||
((Position == 1) && (Position2 == 3)) ||
((Position == 3) && (Position2 == 2)) ||
((Position == 2) && (Position2 == 0));
depth = depth + (isFwd ? 10 : -10); //this yields four depth measurements
lsm.read(); // reads the magnetometer
val =sq(lsm.magData.x);
val = val +sq(lsm.magData.y);
val = val +sq(lsm.magData.z);
val =sqrt(val); // calculate total magnetic field
float Pi = 3.14159;
// Calculate the angle of the vector y,x
float heading = (atan2(lsm.magData.z,lsm.magData.x) * 180) / Pi;
// Normalise to 0-360
if (heading < 0)
{
heading = 360 + heading;
}
Serial.print(depth/4);
Serial.print(",");
//Serial.print((int)lsm.magData.x);
//Serial.print(".");
Serial.print((int)lsm.magData.y);
Serial.print(".");
//Serial.print((int)lsm.magData.z);
//Serial.print(".");
Serial.print(depth/4);
Serial.print(".");
Serial.print(val);
Serial.print(".");
Serial.print(depth/4);
Serial.print(".");
Serial.println((int)lsm.accelData.z);
Serial.print("Compass Heading: ");
Serial.println(heading);
}
if (Press2 != Press)
{
Serial.println(Press ? "Press" :"Release");
}
Position = Position2;
Press = Press2;
}
}