The code I have now is
<
void loop() {
Serial.println("Enter y to start - Enter e to erase chip");
Serial.println("EEPROM size : ");Serial.print(EEPROM.length());Serial.println("");
while (Serial.available()) Serial.read(); //Clear the RX buffer
while (Serial.available() == 0); //Wait for a character
byte choice = Serial.read();
if (choice == 'y'){
for (j = 0; j<20; j++) {
if (! bmp.performReading()) {
Serial.println("Failed to perform reading :(");
return;
}
// read the temperature from whatever device you are using
oneRecord.temperature = bmp.temperature,3;
Serial.println(oneRecord.temperature);
// read the pressure from whatever device you are using
oneRecord.pressure = bmp.pressure,3;
Serial.println(oneRecord.pressure);
// read the acceleration from whatever device you are using
//oneRecord.acceleration = ;
// add in the time stamp so you know roughly when the reading happened
oneRecord.timeStamp = millis();
Serial.println(oneRecord.timeStamp);
// write the readings to the flash chip
//Flight num = read address 1? and thta value is the flight no.
myFlash.writeBlock(flashWriteAddress, (uint8_t *)&oneRecord, sizeof(oneRecord) );
// increment the record number - you don't really need this but it will help
// detecting the end of the data when retrieving the data from the flash chip
oneRecord.recordNumber++;
// update the flash write address
flashWriteAddress = flashWriteAddress + sizeof(oneRecord);
// delay for a specific period of time - say 100ms
delay( 100 );
}
dumpData();
choice == "o";
}
else if (choice == 'e')
{
Serial.println("Erasing entire chip");
myFlash.erase();
Serial.println("Chip erased");
Serial.println(" ");
}
else{
Serial.print("Unknown choice: ");
Serial.write(choice);
Serial.println();
}
}
void dumpData() {
uint32_t flashReadAddress = 0;
// read the very first record from the flash chip
myFlash.readBlock(flashReadAddress, (uint8_t *)&oneRecord, sizeof(oneRecord) );
flashReadAddress = flashReadAddress + sizeof(oneRecord);
// quick sanity check - the record number for this entry should be zero
if (oneRecord.recordNumber == 0) {
// print out the headings
Serial.println(F("Rec Num,Timestamp,Temp,Press,Accel"));
// erased flash memory reads as 0xFF to use that to check if the end of the data has been reached
while (oneRecord.recordNumber != 0xFFFFFFFF ) {
//Outputs the flash data
Serial.print( oneRecord.Flightnum );
Serial.print( "," );
Serial.print( oneRecord.recordNumber );
Serial.print( "," );
Serial.print( oneRecord.timeStamp );
Serial.print( "," );
Serial.print( oneRecord.temperature );
Serial.print( "," );
Serial.print( oneRecord.pressure );
Serial.print( "," );
Serial.println( oneRecord.acceleration );
// read the next record from the flash
myFlash.readBlock(flashReadAddress, (uint8_t *)&oneRecord, sizeof(oneRecord) );
flashReadAddress = flashReadAddress + sizeof(oneRecord);
}
}
}
I don't have any code to handle going between the pages.
Maybe I could store the flight number to my SD card and save it as a variable before flight, because the main reason i'm not storing it on the SD is for the in-flight portion.
I think i've run into the page issue and I currently haven't had time to go over the linear search, the maximum number of flights at a time would be maybe like 5-10 MAX so I think it would be suitable.
Im not sure why it can store the other values and not the values at 10, so i'm assuming its a memory error and not a data type error