Hello..
This is my first post after buying materials to build a simple COMPASS + PITCH/ROLL indicator on a sailboat.
As I said, I bought the following parts:
*Arduino MEGA 2560 Arduino Mega 2560 R3 (Atmega2560 - assembled) : ID 191 : $39.95 : Adafruit Industries, Unique & fun DIY electronics and kits
*LSM303 FLORA Accelerometer/Compass Sensor - LSM303 [v1.0] : ID 1247 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits
*LDC 16x2 Standard LCD 16x2 + extras [white on blue] : ID 181 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits
Aditional parts (Protoboard, USB cable and jumpers) from local dealer
I have to say that my sofware knowledge is almost null and all results mentioned below are based on GitHub downloads.
Following indications here Arduino | LSM303 Accelerometer + Compass Breakout | Adafruit Learning System , and instructions on the sensor DESCRIPTION here FLORA Accelerometer/Compass Sensor - LSM303 [v1.0] : ID 1247 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits about libraries needed, is kind of confusing thing to me.
My question focused on how the COMPASS and PITCH/ROLL (tilt) coluld be directed to the LCD.
¿Can anyone give to me some guidance to accomplish the project?
Sorry for some mismatches writing english... (I am from Spain)...
Thanks in advance.
There are a lot of examples of code for how to output numbers to LCD's.
There are a lot of examples of how to get numbers from your sensor using I2C.
Then thirdly, there is the issue of how you adjust the reading from your geomagnetic field sensor, which is a 3-d coordinate, into the conventional 2-d compass heading in the horizontal plane.
You need to tackle these issues separately, one at a time. Trying to do it all at once, if you are inexperienced, is just going to confuse you.
Thanks michinyon for your reply..
Since the LSM303 board will be moving fixed to a saliboat, I consider both (sensor & boat) the same "thing".
I used library and "Test" example on GitHub - adafruit/Adafruit_LSM303: Driver for Adafruit's LSM303DLHC breakout .
Then, I found the next code:
#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 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);
}
It says "Calculate the angle of the vector y,x" which rejects "Z" micro-Tesla values.
But something is wrong with the above code. I´m using libraries at GitHub - adafruit/Adafruit_LSM303: Driver for Adafruit's LSM303DLHC breakout
and seems that some values are not "declared" when trying to load the above "bearing" sketch.
It seems that I need to add some other libraries since the sketch above I read:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303.h>
And the one on the "Test" sketch I read:
#include <Wire.h>
#include <Adafruit_LSM303.h>
It doesn´t "include" the <Adafruit_Sensor.h> ![]()
I know that I have to read more and more about how the software-side works.
I´m a retired Navy sailor who use to work on the hardware-side of computers for decades... I think I can find a way.. (long way).. to study some basics about all these "tricky" loops ![]()
Thanks again