add sd card

This commit is contained in:
interfisch 2022-06-19 15:07:40 +02:00
parent dda957b763
commit 7e02287892
2 changed files with 37 additions and 1 deletions

View File

@ -27,4 +27,5 @@ lib_deps =
adafruit/Adafruit BusIO@^1.11.3 adafruit/Adafruit BusIO@^1.11.3
https://github.com/adafruit/Adafruit-GFX-Library https://github.com/adafruit/Adafruit-GFX-Library
arduino-libraries/SD@^1.2.4 arduino-libraries/SD@^1.2.4
mathertel/OneButton@^2.0.3 mathertel/OneButton@^2.0.3
arduino-libraries/SD@^1.2.4

View File

@ -183,6 +183,13 @@ uint8_t controlmode=0;
#define MODE_GAMETRAK 2 #define MODE_GAMETRAK 2
// SD Logging
#include <SPI.h> //SCK=13, MISO=12, MOSI=11
#include <SD.h> //Format sd cart with FAT or FAT16
#define SDCHIPSELECT 16
boolean datalogging=true;
void updateInputs(unsigned long loopmillis); void updateInputs(unsigned long loopmillis);
void updateDisplay(unsigned long loopmillis); void updateDisplay(unsigned long loopmillis);
void display_show_stats(); void display_show_stats();
@ -192,8 +199,19 @@ void display_show_menu();
void setup() { void setup() {
Serial.begin(SERIAL_BAUD); //Debug and Program Serial.begin(SERIAL_BAUD); //Debug and Program
esc.init(); esc.init();
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(SDCHIPSELECT)) {
Serial.println("Card failed, or not present");
datalogging=false; //disable logging
}else{
Serial.println("Card initialized.");
}
analogReadResolution(12); analogReadResolution(12);
pinMode(PIN_GAMETRAK_LENGTH_A, INPUT_PULLUP); pinMode(PIN_GAMETRAK_LENGTH_A, INPUT_PULLUP);
@ -529,6 +547,23 @@ void loop() {
#endif #endif
} }
static unsigned long last_datalogging_write=0;
if (datalogging) {
#define LOGGINGINTERVAL 100
if (loopmillis-last_datalogging_write>LOGGINGINTERVAL)
{
last_datalogging_write=loopmillis;
File dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile) { // if the file is available, write to it
dataFile.println("TEST asdf");
dataFile.close();
}
}
}
esc.update(loopmillis); esc.update(loopmillis);