- Wed Jun 06, 2012 7:41 am
#145520
Hello,
I'm in the process of building a digital compass with the Arduino Uno and the LSM303. The purpose of this compass is to enter the nmea-data to the boat's network and therefor get a more stable course when the auto pilot is steering the boat. To get a serial data stream I build a small logic board that converts the TX signal into a TTL signal. I can read the data stream using a serial cable (not the usb cable that can be connected to the Arduino too). The code I'm using:
Someone who can be of any help in solving this issue? Been searching for hours and hours but did not find a similar subjects on this question.
Any help is highly appreciated!
I'm in the process of building a digital compass with the Arduino Uno and the LSM303. The purpose of this compass is to enter the nmea-data to the boat's network and therefor get a more stable course when the auto pilot is steering the boat. To get a serial data stream I build a small logic board that converts the TX signal into a TTL signal. I can read the data stream using a serial cable (not the usb cable that can be connected to the Arduino too). The code I'm using:
Code: Select all
The problem I have with the output, it is fluctuating heavily. I think some filtering might help. I had already had a look at the Kalman filter, however since I don't speak the programming language, I got stuck in that process. #include <Wire.h>
#include <LSM303.h>
LSM303 compass;
void setup() {
Serial.begin(4800);
Wire.begin();
compass.init();
compass.enableDefault();
// Calibration values. Use the Calibrate example program to get the values for
// your compass.
compass.m_min.x = -550; compass.m_min.y = -357; compass.m_min.z = -460;
compass.m_max.x = 223; compass.m_max.y = 378; compass.m_max.z = 300;
}
/*----------------------------------------------------------------------------
1 2 3 4 5 6
| | | | | |
$--HDG,x.x,x.x,a,x.x,a*hh<CR><LF>
------------------------------------------------------------------------------
Field Number:
1. Magnetic Sensor heading in degrees
2. Magnetic Deviation, degrees
3. Magnetic Deviation direction, E = Easterly, W = Westerly
4. Magnetic Variation degrees
5. Magnetic Variation direction, E = Easterly, W = Westerly
6. Checksum */
char nmeastr[17]; // HCHDG,000.00,,,,*
int checksum;
char hs[6]; // 000.00
void loop() {
strcpy(nmeastr,"HCHDG,");
//dtostrf(FLOAT,WIDTH,PRECSISION,BUFFER);
compass.read();
int heading = compass.heading((LSM303::vector){0,-1,0});
Serial.print("Heading list : ");
Serial.print(heading);
Serial.print("\t\t");
if (heading > 180)
{
heading = heading - 360;
}
// dtostrf(compass.heading((LSM303::vector){0,-1,0}), 5, 2, hs);
dtostrf(list.getAverage(), 5, 2, hs);
//dtostrf(heading, 5, 2, hs);
//Serial.print("hs ");
//Serial.print(hs);
//Serial.println();
strcat(nmeastr,hs);
strcat(nmeastr,",,,,");
//add a checksum
checksum=0;
for (int n=0; n < strlen(nmeastr); n++) {
checksum ^= nmeastr[n];
}
Serial.print("$");
Serial.print(nmeastr);
Serial.print("*");
Serial.print(checksum, HEX);
Serial.print("\t");
Serial.println();
/* 5hz == 200 */
delay(100);
}
Someone who can be of any help in solving this issue? Been searching for hours and hours but did not find a similar subjects on this question.
Any help is highly appreciated!