Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: Please help on TX on: June 06, 2012, 08:28:12 am
oops, TTL smiley-wink

To give the output to my laptop, it needs to be an rs232 signal. I just read through the manual of the mulitplexer and that one can also read a rs232 signal. But, as far as I understand, the TX can not be fed to the rs232 port
2  Using Arduino / Networking, Protocols, and Devices / Re: Please help on TX on: June 06, 2012, 03:10:51 am
Ok, thanks so far. If I skip the rs232 and only want tty logic, can you please tell what is required in that case?

Thanks again!
3  Using Arduino / Networking, Protocols, and Devices / Re: Please help on TX on: June 06, 2012, 03:04:26 am
Thanks Nick. Do I understand you correct if you say that in my current comfiguration it is not possible to get an output that I can either use vor rs232 or to have tty-logic for my multiplexer?

Many thanks for your time.
4  Using Arduino / Networking, Protocols, and Devices / Please help on TX on: June 05, 2012, 05:59:23 pm
Hello,

I have a Arduino Uno. Wrote code to use with the LSM303 and using the USB cable, I get a nice number of NMEA sentences. However, the data needs to go into a serial port on my (old) computer, or go into the multiplexer. This needs to be tty logic.

I spent hours searching for a solution on how to get the TX pin working, and did not find a fix, only many people searching for a similar solution.

The code I'm using:
Code:
#include <Wire.h>
#include <LSM303.h>
#include <AverageList.h>
#include <SoftwareSerial.h>
LSM303 compass;
SoftwareSerial mySerial(2, 3); // RX, TX

const byte MAX_NUMBER_OF_READINGS = 10;
int storage[MAX_NUMBER_OF_READINGS] = {0};
AverageList<int> list = AverageList<int>( storage, MAX_NUMBER_OF_READINGS );

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  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}); //1,0,0 will allign North with SFE silkscreen
 
  //int rand = compass.heading((LSM303::vector){0,-1,0});
  //Serial.print("Heading list : ");
  //Serial.println(heading);
  list.addValue(heading);

  //list.debug("list",Serial); //print contents to serial console
  //Serial.print("Average: ");
  //Serial.println(list.getAverage());
 
  //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);
}

For the tty logic I built a board as found here: http://prosje.be/CO/Schemas/RS232-to-TTL3.png The mentioned rs232 in the schema is connected to the TX pin 1.

Any help is highly appraciated on how to solve this issue. Am I working in the right direction??

Many thanks in advance!
5  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: June 03, 2012, 03:46:48 am
Dear Thomas, Lauszus,

Thanks for the time you took to reply.

I read the article and searched for a calibration programm related to the LSM303. I found this program:
Code:
#include <Wire.h>
#include <LSM303.h>

LSM303 compass;
LSM303::vector running_min = {2047, 2047, 2047}, running_max = {-2048, -2048, -2048};

// temp
float x_min; float x_max; float x_cur;
float y_min; float y_max; float y_cur;
float z_min; float z_max; float z_cur;

void setup() {
 
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();
 
}

void loop() { 
  compass.read();
 
  running_min.x = min(running_min.x, compass.m.x);
  running_min.y = min(running_min.y, compass.m.y);
  running_min.z = min(running_min.z, compass.m.z);

  running_max.x = max(running_max.x, compass.m.x);
  running_max.y = max(running_max.y, compass.m.y);
  running_max.z = max(running_max.z, compass.m.z);
 
  Serial.print("M min ");
  Serial.print("X: ");
  Serial.print((int)running_min.x);
  Serial.print(" Y: ");
  Serial.print((int)running_min.y);
  Serial.print(" Z: ");
  Serial.print((int)running_min.z);

  Serial.print(" M max "); 
  Serial.print("X: ");
  Serial.print((int)running_max.x);
  Serial.print(" Y: ");
  Serial.print((int)running_max.y);
  Serial.print(" Z: ");
  Serial.println((int)running_max.z);
 
  delay(100);
}

After running the programm and looking at the serial output, I started moving the board in all sorts of direction, and after some time I got a stable output:
Quote
/* Output of Calibrate.ino
  M min X: -548 Y: -378 Z: -547 M max X: 248 Y: 413 Z: 314
  M min X: -548 Y: -378 Z: -547 M max X: 248 Y: 413 Z: 314
  M min X: -548 Y: -378 Z: -547 M max X: 248 Y: 413 Z: 314
  */

These values I entered in the programm "Heading.ino"
Code:
#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();
 
  // Calibration values. Use the Calibrate example program to get the values for
  // your compass.
  compass.m_min.x = -548; compass.m_min.y = -378; compass.m_min.z = -547;
  compass.m_max.x = 248; compass.m_max.y = 413; compass.m_max.z = 314;
 
  /* Output van Calibrate
  M min X: -548 Y: -378 Z: -547 M max X: 248 Y: 413 Z: 314
  M min X: -548 Y: -378 Z: -547 M max X: 248 Y: 413 Z: 314
  M min X: -548 Y: -378 Z: -547 M max X: 248 Y: 413 Z: 314
  */
}

/* Oorspronkelijke code
void loop() {
  compass.read();
  int heading = compass.heading((LSM303::vector){0,-1,0});
  Serial.println(heading);
  delay(500);
}
*/

/*----------------------------------------------------------------------------
        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();
  dtostrf(compass.heading((LSM303::vector){0,-1,0}), 5, 0, 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.println();
 
  /* 5hz == 200 */
  delay(500);
}

While running this programm, serial output showed the heading as NMEA-string. Having it away from all sorts of electroncs and put a normal (old fashion smiley-wink ) compass pointing in the same directoin, and laying flat on the floor,, the output showed:
Quote
$HCHDG,    0,,,,*5C
$HCHDG,    2,,,,*5E
$HCHDG,    5,,,,*59
$HCHDG,    1,,,,*5D
$HCHDG,    3,,,,*5F
$HCHDG,    1,,,,*5D
$HCHDG,    2,,,,*5E
$HCHDG,    4,,,,*58
$HCHDG,    1,,,,*5D
$HCHDG,    2,,,,*5E
$HCHDG,    2,,,,*5E
$HCHDG,    0,,,,*5C
$HCHDG,    3,,,,*5F
$HCHDG,    1,,,,*5D
$HCHDG,    2,,,,*5E
$HCHDG,    3,,,,*5F
$HCHDG,    3,,,,*5F
$HCHDG,    3,,,,*5F
$HCHDG,    3,,,,*5F
$HCHDG,    2,,,,*5E
$HCHDG,    4,,,,*58
$HCHDG,    4,,,,*58
$HCHDG,    5,,,,*59

Allthough not very accurated, it points north with some variance. Not too bad, but room for improvement, I think.

As soon as I start turning the lsm303 up and down , still pointing in the same direction, I would expect to see the same heading however the output shows:
Quote
$HCHDG,   14,,,,*49
$HCHDG,   14,,,,*49
$HCHDG,   16,,,,*4B
$HCHDG,   12,,,,*4F
$HCHDG,   10,,,,*4D
$HCHDG,    6,,,,*5A
$HCHDG,    5,,,,*59
$HCHDG,    6,,,,*5A
$HCHDG,   10,,,,*4D
$HCHDG,    7,,,,*5B
$HCHDG,    9,,,,*55
$HCHDG,    8,,,,*54
$HCHDG,    9,,,,*55
$HCHDG,   12,,,,*4F
$HCHDG,   13,,,,*4E
$HCHDG,   11,,,,*4C
$HCHDG,   10,,,,*4D
$HCHDG,   11,,,,*4C

IMHO, this heading info is too inaccurate to use as a compass. The autopilot will move the boat from left to right, like a drunken sailor smiley-wink

I'm not sure wether this is part of the lsm303 (in that case it is not a sufficiënt solution for a compass for an auto pilot) or filtering or something else is required to get a more stable output.

Many thanks, George
6  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: June 01, 2012, 12:24:01 am
Thanks Lauszus, that woud be great!

Been searching using the keywords you suggest, however I did not find a solution that would fit my needs. Sites I found suggest to use some sort of Kalman filter. Will also do more digging.

Cheers, George
7  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: May 31, 2012, 11:31:42 am
Thanks for your explaination Lauszus.

The code from https://github.com/pololu/LSM303 is the code I use for the compass function. The output shown is the result of a minor addition I did to create nmea output.

I'll google "ahrs magnetometer" to see if it can help. Part of the learning curve smiley-wink

George
8  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: May 31, 2012, 05:09:36 am
Hello,

Pretty new to the forum and to using the Arduino Uno with the SLM303.

I'm trying to build a tilt compensated compass with an nmea string as out. This string is going to be input for my boat network so my tiller pilot will be able to better steer a course. Quite a project....

The code I have so far:
Code:
#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();
 
  // Calibration values. Use the Calibrate example program to get the values for
  // your compass.
  compass.m_min.x = -397; compass.m_min.y = -284; compass.m_min.z = -464;
  compass.m_max.x = 150; compass.m_max.y = 287; compass.m_max.z = 227;
 
  /* Output van Calibrate
  M min X: -397 Y: -284 Z: -464
  M max X: 150 Y: 287 Z: 227
  */
}

/* Oorspronkelijke code
void loop() {
  compass.read();
  int heading = compass.heading((LSM303::vector){0,-1,0});
  Serial.println(heading);
  delay(500);
}
*/

/*----------------------------------------------------------------------------
        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();
  dtostrf(compass.heading(), 5, 0, 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.println();
 
  /* 5hz == 200 */
  delay(500);
}

When laying flat on the table, it produces:
Quote
$HCHDG,  207,,,,*59
$HCHDG,  211,,,,*5E
$HCHDG,  213,,,,*5C
$HCHDG,  209,,,,*57
$HCHDG,  213,,,,*5C
$HCHDG,  211,,,,*5E
$HCHDG,  210,,,,*5F
$HCHDG,  215,,,,*5A
$HCHDG,  212,,,,*5D
$HCHDG,  207,,,,*59
$HCHDG,  208,,,,*56
$HCHDG,  208,,,,*56
$HCHDG,  208,,,,*56
$HCHDG,  211,,,,*5E
$HCHDG,  210,,,,*5F
$HCHDG,  210,,,,*5F
$HCHDG,  207,,,,*59
$HCHDG,  217,,,,*58
$HCHDG,  215,,,,*5A
$HCHDG,  211,,,,*5E
$HCHDG,  211,,,,*5E
$HCHDG,  209,,,,*57
$HCHDG,  212,,,,*5D
$HCHDG,  210,,,,*5F
$HCHDG,  209,,,,*57
$HCHDG,  210,,,,*5F
$HCHDG,  211,,,,*5E
$HCHDG,  212,,,,*5D
$HCHDG,  211,,,,*5E
$HCHDG,  210,,,,*5F

As you can see, not a stable course to steer smiley-wink The video shows the issue I'm facing when it comes to stable ocurse
http://youtu.be/3XHxAKu6n7E

I know I should do some filtering, and this is where I got to this topic and also got stuck on how to get the kalman filter to this code. I'd like some help on how I can put the filter in place so the course gets more stable.

Many thanks in advance for your reply!
9  International / Nederlands / Re: Gyro kompas met nmea0183 on: May 10, 2012, 03:13:36 am
Dank je voor je reactie. Ik heb in die sectie al rondgekeken en ga daar verder in zoeken.

Mijn idee is dat je met een 2-axis (x en y coördinaten) voldoende hebt om de kompaskoers te bepalen van de boot. Nu las ik iets over de functie van een accelerator, dat die nodig zou zijn om te weten of de boot vaart en dat dan daarmee wederom de juiste kompaskoers (Heading) kan worden bepaald. Op zich vind ik het niet van belang te weten wat de heading is als de snelheid 0 is. Of is iemand een andere mening toegedaan?

Het wordt een ander verhaal als je vaart, stroom tegen hebt en de daardoor de snelheid richting 0 gaat. Overigens moet je je dan afvragen of je niet de motor moet aanzetten dan wel het anker moet uitgooien. Kortom, een scenario dat zich normaler wijze niet voordoet.

Onderdelenlijst:
- Arduino Uno
- Gyro kompas X / Y
- NMEA bridge (RS232 --> TX en gnd, dit kan volgens mij ook)
- Software om gyro aan te sturen en juiste nmea zinnen terug te krijgen die weer aan het boordnet worden afgegeven.
10  International / Nederlands / Gyro kompas met nmea0183 on: May 09, 2012, 11:05:41 am
Hallo,

Al een tijdje ben ik op zoek naar een zelfbouw project voor een gyrokompas dat een nmea0183 signaal kan afgeven dat ik vervolgens via mijn multiplexer aan het boordnet kan afgeven. Doel is om de boot nauwkeuriger met de stuurautomaat te laten sturen. Via een omweg stuitte ik op Arduino. Inmiddels gevonden welk board ik kan gebruiken en dat er ook een gyro compass module is.

Mijn vraag is, is het met Arduino mogelijk wat ik zou willen? En....is er iemand die zoiets al eens eerder heeft gedaan?

Grtz., George
Pages: [1]