#include <SerialFlash.h>
#include <SPI.h>
#include "BMI088.h"
const int cspin = 10; // change this to match the chip select pin on your board
SerialFlashFile file;
struct mystructtype{ // size can be modified depending on what variables you want to log
float ax;
} mystruct;
Bmi088Accel accel(Wire,0x18); // change based on your sensor
Bmi088Gyro gyro(Wire,0x68);
uint32_t prevMillis, currentMillis = 0;
const uint32_t sampleInterval = 1000;
float accel_reading;
void writedata(){
currentMillis = millis();
SerialFlash.create( "datafile.txt", 1024 ); // change the size of the text file if you need more space (which you will if you want multiple pieces of data)
file = SerialFlash.open("datafile.txt");
if ( currentMillis - prevMillis > sampleInterval ) {
prevMillis = currentMillis;
accel.readSensor();
gyro.readSensor();
accel_reading = accel.getAccelX_mss();
mystruct.ax = accel_reading; // whatever function is used to get data
file.write( (uint8_t *)&mystruct, sizeof(mystruct) );
}
}
void readdata(){
file = SerialFlash.open("datafile.txt");
file.read( (uint8_t *)&mystruct, sizeof(mystruct) );
Serial.println( mystruct.ax );
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
SerialFlash.begin(cspin);
accel.begin();
gyro.begin();
}
void loop() {
// put your main code here, to run repeatedly:
writedata();
readdata();
delay(1000); // delay so that the serial monitor will be readable
}
why is this code not working?
library - GitHub - PaulStoffregen/SerialFlash: Library for using SPI Flash memory with a filesystem-like interface