I have been using a slightly modified version of code sent to me from CTi (Tilt-33A). It is found below. I'm having problems getting the data in the serial buffer, it just shows up as "f". There is a picture of the serial buffer displaying what I'm getting now. It could be something with "unsigned char checkCRC(unsigned char * msg)", since I changed it so the code would compile.
/*
Modifying C program from CTi to Arduino Compatible
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
unsigned char checkCRC(char * msg)
{
unsigned int i;
char crc = 0;
/* Calculate the CRC */
for (i = 0; i < strlen((char *)msg); i++)
crc ^= msg[i];
/*return crc;*/
}
int parse_tilt_30(char *data, char rv[][64])
{
int i = 0;
char *token, *crc;
token = strtok(data, "*");
crc = strtok(NULL, "*");
/* Check if CRC equal to the CRC in message */
if (strtol(crc, NULL, 16) != checkCRC(token+1))
/*return -1;*/
token = strtok(token, ",");
/* Parsing the msg */
while (token != NULL)
{
token = strtok(NULL, ",");
if (token != NULL)
strcpy(rv[i++], token);
}
/*return 1;*/
}
void setup() {
Serial.begin(115200);
}
void loop(){
int ret = 0;
char data[64] = "$CSTLT,+0997.6,-0009.2,+0003.0,+087.09,+002.58,+000,22.40*42\n\r";
char rv[7][64] = {{0}};
float Ax, Ay, Az;
float Pitch, Roll, Rotation;
float Temperature;
if (parse_tilt_30(data, rv) < 0)
{
printf("Checksum Error!\n");
}
Ax = strtof(rv[0], NULL);
printf("Ax: %+5.1f, ", Ax);
Ay = strtof(rv[1], NULL);
printf("Ay: %+5.1f, ", Ay);
Az = strtof(rv[2], NULL);
printf("Az: %+5.1f\n", Az);
Pitch = strtof(rv[3], NULL);
printf("Pitch: %+5.2f, ", Pitch);
Roll = strtof(rv[4], NULL);
printf("Roll: %+5.2f, ", Roll);
Rotation = strtof(rv[5], NULL);
printf("Rotation: %+5.2f\n", Rotation);
Temperature = strtof(rv[6], NULL);
printf("Temperature: %+4.1f\n", Temperature);
delay(5000);
}