Here is what I did. It reads Depth, Windspeed and Windangle (degrees to right from bow) and prints them as it reads them. Now that this works, I'm going to make this routine into a separate loop to run when called and output to global variables rather than the ones built in now. A lot of the rest of the code for reading the GPS module and the compass module is already up and running as well as the button readers and LCD output.
it all has to be combined. On my setup, the datagrams are read in sequence starting with Depth whose Command byte is 0x00. Nick's SerialHardware library reads the 9th bit which then shows up as a 1 appended to the head of each command byte, hence 0x00 is 0x100 with the 9th bit.
i was able to use the calculations shown in Thomas Knauth's reference to derive each of the datatypes.
I'll make a sketch of what i built for the hardware converter when I get a chance.
UPDATE 2/29/12: changed code example to note requirement for Nick Glammon's HardwareSerial core and clean up. Criticisms welcomed. Added sample of datastream.
UPDATE 3/1/12 changed "pointer" to "index" and moved varable type declaration to Global in effort to improve C-worthiness
This is what the SeaTalk input looks like on my system. I added the spaces for legibility. Byte 3 should always be 20, and is, once the stream settles down. I may add some filters to ignore lines where byte 3 is not 20.
100 2 20 6D 0 110 1 0 21 111 1 C 2;
100 2 30 70 0 110 1 0 1A 111 1 B 1;
100 2 30 73 0 110 1 0 20 111 1 B 4;
100 2 20 71 0 110 1 0 3 111 1 B 4;
100 2 20 6E 0 110 1 0 3B 111 1 B 3;
100 2 28 6C 0 110 1 0 2A 111 1 B 0;
100 2 20 6D 0 110 1 0 1B 111 1 B 0;
100 2 20 6E 0 110 1 0 3B 111 1 B 2;
100 2 20 6F 0 110 1 0 31 111 1 B 6;
100 2 20 6F 0 110 1 0 29 111 1 A 1;
/* - SeaTalk reader: Depth, Windspeed, Windangle
- no error detection, no collision detection
- requires new SerialHardware core library with
- 9th bit processing by Nick Gammon available
- http://arduino.cc/forum/index.php/topic,91377
- which requires Arduino 1.0 IDE 2/29/12 jaf
*/
char SeaTalkData[256] , index ;
float printdepth, printwind ;
int printangle, inbyte ;
long interval = 2000 ;
unsigned long currentMillis ;
void setup()
{
Serial.begin(9600) ;
Serial1.begin(4800,true) ; //Nick G's SerialHardware core req'd.
Serial.println("SeaTalkReader2 Startup") ;
delay(2000) ;
}
void readSeaTalk()
{
if (Serial1.available ())
{
inbyte = (Serial1.read());
if (inbyte == 0x100)
index = 0 ;
/* Code above reads SeaTalk Stream and starts inbyte buffer when
9th bit and first byte of depth sentence (command byte)come in.
On my system with two talkers, ST40 depth and wind, the datagrams
follow each other in sequence so it's easy to pick out the
bytes needed to derive wanted data - always in same place */
SeaTalkData[index++] = inbyte ;
printwind = ((SeaTalkData[11] & 0x7f) + SeaTalkData[12]/10) ;
printangle = (makeWord(SeaTalkData[7] , SeaTalkData[8]))/2 ;
printdepth = (makeWord(SeaTalkData[4] , SeaTalkData[3])) / 10.0 ;
}
}
void serialprint ()
{
Serial.print("windspeed: ") ; Serial.print (printwind, 1) ;
Serial.print(" Wind Angle: "); Serial.println (printangle) ;
Serial.print("Depth: ") ; Serial.println (printdepth, 1) ;
}
void loop()
{
currentMillis = millis() ;
while (millis() - currentMillis <= interval) //not tested yet, but this is a timer to make sure uart is up and delivering data.
readSeaTalk () ;
serialprint () ;
}