Hi,
I was wondering if anyone could see a problem with my technique or with my code that explains why my output isn't printing to my SD card (no file is created), and why my compass output is not printing to my serial monitor. I've used these bits of code before and have not had any issues. I've also verified that all of the peripherals are working properly, and are properly connected
below is the code,
[code\]
#include <NewSoftSerial.h>
#include <Wire.h>
#include <SD.h>
const int CS=8;
int HMC6352slave =0x42;
int HMC6352read = 0x41;
int heading;
long id = 1;
#include <Time.h>
#include <TimeAlarms.h>
#include <TextFinder.h>
NewSoftSerial gps(3,4);
TextFinder finder(gps);
const int NUMBER_OF_FIELDS = 8;
int values[NUMBER_OF_FIELDS];
void setup()
{
Serial.begin(9600);
gps.begin(9600);
Serial.println("bloop");
Alarm.timerRepeat(10, RepeatTask);
Wire.begin();
pinMode(8,OUTPUT);
if (!SD.begin(CS)) {
Serial.println("Card failed, or not present");
return;
}
}
void RepeatTask()
{
Serial.println(millis());
Serial.println("");
char mycharpointer[7];
char com[]=",";
char buff[90];
int length=90;
finder.find("$GPGGA,");
finder.getString( "$GPGGA,", "\r\n", buff, length);
Wire.beginTransmission(HMC6352slave);
Wire.send(HMC6352read);
Wire.endTransmission();
delay(10);
Wire.requestFrom(HMC6352slave, 2);
byte MSB = Wire.receive();
byte LSB = Wire.receive();
float headingSum = (MSB<<8) + LSB;
float headingInt = headingSum/10;
sprintf(mycharpointer,"%f",headingInt);
strcat(buff,com);
strcat(buff,mycharpointer);
Serial.println(buff);
Serial.println(headingInt);
File datafile = SD.open("datalog.txt",FILE_WRITE);
if (datafile) {
datafile.println(buff);
datafile.close();
}
}
void loop()
{
Alarm.delay(1000);
}
below is what I get on the serial monitor. All of it prints, except for the last value, which, since I've tested, should be around 78.9
bloop
240001
190106.000,bleeh.9037,N,blahhh.0006,W,2,7,1.30,161.5,M,-33.3,M,0000,0000*62,?
0.00
any advice or insights are much appreciated!