hi all,
Im working on a small compass/gps datalogger. The program works for the most part, the only problem is that the compass reading only prints once, rather than 100 times each time the full program loops. After the first loop of serial gps readings, it prints one compass measurement, then waits 10 seconds and loops through the gps readings again. Does anyone have an idea as to why it might be doing this, instead of completing the entire for loop?
thanks for any advice or insights
#include <NewSoftSerial.h>
#include <Wire.h>
#include <SD.h>
int CS=8;
NewSoftSerial nss (3,4);
char inData[250];
byte index = 0;
int HMC6352slave =0x42;
int HMC6352read = 0x41;
int heading;
long id = 1;
void setup()
{
HMC6352slave = HMC6352slave>>1;
Serial.begin (115200);
Serial.println("start");
nss.begin (9600);
Wire.begin();
pinMode (CS,OUTPUT);
if(!SD.begin(CS))
{
Serial.println("Card Failure");
return;
}
}
void loop()
{
for( int j=0;j<10000;j++)
{
while(nss.available() > 0)
{
char inChar = nss.read();
if (index < (250))
{
inData[index++] = inChar;
inData[index] = '\0';
if (index == (250))
{
File gps = SD.open("gps.txt",FILE_WRITE);
gps.print(inData);
gps.println(j);
gps.close();
Serial.print(inData);
index=0;
}
}
}
}
for(int k=0;k<100;k++);
{
Serial.println("");
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;
Serial.println(headingInt);
Serial.println("");
File compass = SD.open("compass.txt",FILE_WRITE);
compass.println(headingInt);
compass.close();
delay(5000);
}
int k = 0;
delay(5000);
}