I have it connected to an uno - on a bread board with about 1.5' of wire on it. I can hold it in the air and get similar results as laying flat on the counter top.
3.5v - gnd - scl - sda connections
I set my phone on the counter with the x axis of the LSM right up against it, rotating them very slowly, and here are the readings I get. I get very similar reading with the phone removed so the phone next to it doesn't appear to be an issue.
LSM Phone
345 2
20 90
320 180
308 270
At this point I'm not concerned about true north, If I could get just get 360 reading as I rotate it would be a start!!
I'm using the code provided from the Adafruit site. (included below)
Code: Select all
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
/* Assign a unique ID to this sensor at the same time */
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345);
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);
}
}
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
mag.getEvent(&event);
float Pi = 3.14159;
// Calculate the angle of the vector y,x
float heading = (atan2(event.magnetic.y,event.magnetic.x) * 180) / Pi;
// Normalize to 0-360
if (heading < 0)
{
heading = 360 + heading;
}
Serial.print("Compass Heading: ");
Serial.println(heading);
delay(500);
}
I have another UNO and a mega that I could steal if need be.
Thanks
edit - pins 4 and 5 are scl - scd? can I try those? If so how does the code need to be modified?
Thanks