mirror of
https://gitlab.com/lander-team/static-load-test-code.git
synced 2025-06-15 22:56:42 +00:00
IT VERKS
This commit is contained in:
parent
823e5773de
commit
91db1a179d
147
src/main.cpp
147
src/main.cpp
@ -28,13 +28,30 @@ const int pin_lc3 = 20;
|
||||
const int chipSelect = BUILTIN_SDCARD;
|
||||
File dataFile;
|
||||
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
delay(1000);
|
||||
Serial.print("Initializing SD card...");
|
||||
|
||||
// put your setup code here, to run once:
|
||||
pinMode(lc_clock, INPUT);
|
||||
if (!SD.begin(chipSelect)) {
|
||||
|
||||
Serial.println("initialization failed. Things to check:");
|
||||
|
||||
Serial.println("1. is a card inserted?");
|
||||
|
||||
Serial.println("2. is your wiring correct?");
|
||||
|
||||
Serial.println(
|
||||
"3. did you change the chipSelect pin to match your shield or module?");
|
||||
|
||||
Serial.println("Note: press reset or reopen this serial monitor after "
|
||||
"fixing your issue!");
|
||||
|
||||
while (true)
|
||||
;
|
||||
}
|
||||
Serial.println("initialization done.");
|
||||
// Configure load cell data pins as inputs
|
||||
pinMode(lc_clock, INPUT);
|
||||
pinMode(pin_lc0, INPUT);
|
||||
pinMode(pin_lc1, INPUT);
|
||||
pinMode(pin_lc2, INPUT);
|
||||
@ -72,97 +89,49 @@ void setup()
|
||||
State.lc1 = lc1.get_value();
|
||||
State.lc2 = lc2.get_value();
|
||||
State.lc3 = lc3.get_value();
|
||||
|
||||
String dataString = "lc0,lc1,lc2,lc3";
|
||||
File dataFile = SD.open("datalog.csv", FILE_WRITE);
|
||||
|
||||
if (dataFile) {
|
||||
|
||||
dataFile.println(dataString);
|
||||
|
||||
dataFile.close();
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
Serial.println("error opening datalog.csv");
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
dataFile = SD.open("loadCell.csv", FILE_WRITE);
|
||||
dataFile.seek(EOF);
|
||||
|
||||
// put your main code here, to run repeatedly:
|
||||
// write2CSV(State);
|
||||
// delay(20);
|
||||
Serial.println(String(State.lc0) + ",\t" + String(State.lc1) + ",\t" +
|
||||
String(State.lc2) + ",\t" + String(State.lc3));
|
||||
void loop() {
|
||||
String dataString = String(State.lc0) + "," + String(State.lc1) + "," +
|
||||
String(State.lc2) + "," + String(State.lc3);
|
||||
Serial.println(dataString);
|
||||
Serial.println("~+~+~+~+~+~+~+~+~+~+~+~");
|
||||
// delay(1000);
|
||||
|
||||
File dataFile = SD.open("datalog.csv", FILE_WRITE);
|
||||
|
||||
if (dataFile) {
|
||||
|
||||
dataFile.println(dataString);
|
||||
|
||||
dataFile.close();
|
||||
|
||||
Serial.println(dataString);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
Serial.println("error opening datalog.csv");
|
||||
}
|
||||
}
|
||||
|
||||
void read_lc0() { State.lc0 = lc0.get_value(); }
|
||||
void read_lc1() { State.lc1 = lc1.get_value(); }
|
||||
void read_lc2() { State.lc2 = lc2.get_value(); }
|
||||
void read_lc3() { State.lc3 = lc3.get_value(); }
|
||||
|
||||
void write2CSV(LoadCells &State)
|
||||
{
|
||||
|
||||
dataFile.print(String(State.lc0, 5));
|
||||
dataFile.print(",");
|
||||
dataFile.print(String(State.lc1, 5));
|
||||
dataFile.print(",");
|
||||
dataFile.print(String(State.lc2, 5));
|
||||
dataFile.print(",");
|
||||
dataFile.print(String(State.lc3, 5));
|
||||
|
||||
dataFile.close();
|
||||
}
|
||||
|
||||
void initFile()
|
||||
{
|
||||
Serial.print("Initializing SD card...");
|
||||
// see if the card is present and can be initialized:
|
||||
if (!SD.begin(chipSelect))
|
||||
{
|
||||
Serial.println("Card failed, or not present. \n\nABORTING SIMULATION");
|
||||
}
|
||||
Serial.println("Card initialized.");
|
||||
|
||||
int i = 1;
|
||||
const char *fileName;
|
||||
|
||||
if (SD.exists("loadCell.csv"))
|
||||
{
|
||||
while (i > 0.0)
|
||||
{
|
||||
fileName = ("loadCell_" + String(i) + ".csv").c_str();
|
||||
|
||||
if (!SD.exists(fileName))
|
||||
{
|
||||
// Open simOut_i.csv
|
||||
dataFile = SD.open(fileName, FILE_WRITE);
|
||||
|
||||
if (dataFile)
|
||||
{
|
||||
Serial.println("File successfully opened!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if the file didn't open, print an error:
|
||||
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
||||
}
|
||||
i = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Open simOut.csv
|
||||
dataFile = SD.open("simOut.csv", FILE_WRITE);
|
||||
if (dataFile)
|
||||
{
|
||||
Serial.println("File successfully opened!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if the file didn't open, print an error:
|
||||
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
||||
}
|
||||
}
|
||||
dataFile.println("lc0,lc1,lc2,lc3");
|
||||
|
||||
dataFile.close();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user