First post.
I'm a mech engg who pokes about in code. I never got to objects and actually using C the way it was meant to be. (What's even a class?? when's it the right time to make one? for example)
Ready sorted Commercial Off The Shelf DAQ systems are expensive, and this is a learning opportunity for me. I'm trying to make a DAQ that will get values off ADC pins, and an I2C Bus, and write these in csv format to be imported to a computer into a Pandas Dataframe where 0-1023 will be calculated into a real world temperature or force etc.
I understand there's a new SdFat library for Teensy and I think was meant to use many of the same calls but that's not been my experience thus far, lots of new words and phrases that don't match legacy norms. They're just variable names, but feels far less friendly to newbies - myself a newbie there's something I'm just not grasping here.
sketch_aug31a:39: error: no matching function for call to 'FsFile:pen(String&, int)'
if(!file.open(fileNumString, O_RDWR | O_CREAT | O_TRUNC)){
Looking through the example files TeensySdioLogger uses this function in this exact way with no issue, only difference, as I see it, is file name.
future improvement, initSD will just find the next file name and return it, a function createFile(fileName); will be called when the DATA_BUTTON falls - no sense creating a file if you never turn on data collection. For right now though, I just can't even create a file as is.
I'm a mech engg who pokes about in code. I never got to objects and actually using C the way it was meant to be. (What's even a class?? when's it the right time to make one? for example)
Ready sorted Commercial Off The Shelf DAQ systems are expensive, and this is a learning opportunity for me. I'm trying to make a DAQ that will get values off ADC pins, and an I2C Bus, and write these in csv format to be imported to a computer into a Pandas Dataframe where 0-1023 will be calculated into a real world temperature or force etc.
I understand there's a new SdFat library for Teensy and I think was meant to use many of the same calls but that's not been my experience thus far, lots of new words and phrases that don't match legacy norms. They're just variable names, but feels far less friendly to newbies - myself a newbie there's something I'm just not grasping here.
sketch_aug31a:39: error: no matching function for call to 'FsFile:pen(String&, int)'
if(!file.open(fileNumString, O_RDWR | O_CREAT | O_TRUNC)){
Looking through the example files TeensySdioLogger uses this function in this exact way with no issue, only difference, as I see it, is file name.
future improvement, initSD will just find the next file name and return it, a function createFile(fileName); will be called when the DATA_BUTTON falls - no sense creating a file if you never turn on data collection. For right now though, I just can't even create a file as is.
Code:
#include "SdFat.h"
#include "RingBuf.h"
#include <Bounce2.h>
#include <Wire.h>
#include <FastLED.h>
#define RING_BUF_CAPACITY 400*512
#define LOG_FILENAME "DataFile"
// Size to log 10 byte lines at 25 kHz for more than ten minutes.
#define LOG_FILE_SIZE 10*25000*600 // 150,000,000 bytes.
#define DATA_BUTTON 0
Bounce debouncer = Bounce();
unsigned long buttonPressTimeStamp;
boolean dataFlag;
SdFs sd;
FsFile file;
FsFile root;
RingBuf<FsFile, RING_BUF_CAPACITY> rb;
void initSD(){
//My struggles are here, trying to initialize the file on the SD card
if(!sd.begin(SdioConfig(FIFO_SDIO))){
sd.initErrorHalt(&Serial);
}
//Open the 'next integer' Data log file
String dir = "/HotWheelzData/";
int exist = 0;
String fileNumString = "";
for (int fileNum = 0; exist == 0; fileNum ++){
fileNumString = dir + LOG_FILENAME + "_" + String(fileNum) + ".csv";
exist = sd.exists(fileNumString);
}
//Now we've figured out the filename, let's create the file
if(!file.open(fileNumString, O_RDWR | O_CREAT | O_TRUNC)){
Serial.println("open failed\n");
return;
}
//File must be pre-allocated to avoid huge delays searching for free clusters.
if(!file.preAllocate(LOG_FILE_SIZE)){
Serial.println("preAllocate failed\n");
file.close();
return;
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while (!Serial){}
initSD();
pinMode(DATA_BUTTON, INPUT);
debouncer.attach(DATA_BUTTON);
debouncer.interval(5);
//FastLED setup removed for brevity
}
void loop() {
// put your main code here, to run repeatedly:
debouncer.update();
if (debouncer.fell() ){
//initiate MPU_6050's
if (dataFlag == false){
dataFlag = true;
}
}
if (debouncer.rose() ){
//closeFile(); //safely close the file, release memory. Haven't gotten here yet
if (dataFlag == true){
dataFlag = false;
}
}
if (dataFlag == true){
//logData(); //Read ADC pins, read I2C for MPU data, and write the data to SD file
}
}