mirror of
https://gitlab.com/lander-team/static-load-test-code.git
synced 2025-08-02 11:31:28 +00:00
working load cell readout
This commit is contained in:
63
src/main.cpp
63
src/main.cpp
@@ -1,7 +1,7 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include "HX711.h"
|
#include "HX711.h"
|
||||||
#include "LoadCells.h"
|
#include "LoadCells.h"
|
||||||
#include "SD.h"
|
#include "SD.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
LoadCells State;
|
LoadCells State;
|
||||||
|
|
||||||
@@ -24,11 +24,6 @@ const int pin_lc1 = 15;
|
|||||||
const int pin_lc2 = 19;
|
const int pin_lc2 = 19;
|
||||||
const int pin_lc3 = 20;
|
const int pin_lc3 = 20;
|
||||||
|
|
||||||
double lc0Offset = 0.0;
|
|
||||||
double lc1Offset = 0.0;
|
|
||||||
double lc2Offset = 0.0;
|
|
||||||
double lc3Offset = 0.0;
|
|
||||||
|
|
||||||
const int chipSelect = BUILTIN_SDCARD;
|
const int chipSelect = BUILTIN_SDCARD;
|
||||||
File dataFile;
|
File dataFile;
|
||||||
|
|
||||||
@@ -52,9 +47,13 @@ void setup() {
|
|||||||
lc3.set_scale();
|
lc3.set_scale();
|
||||||
|
|
||||||
lc0.tare(50);
|
lc0.tare(50);
|
||||||
|
Serial.println(".");
|
||||||
lc1.tare(50);
|
lc1.tare(50);
|
||||||
|
Serial.println(".");
|
||||||
lc2.tare(50);
|
lc2.tare(50);
|
||||||
|
Serial.println(".");
|
||||||
lc3.tare(50);
|
lc3.tare(50);
|
||||||
|
Serial.println("Load Cells Tared");
|
||||||
|
|
||||||
// Attach ISRs to load cell data pins to read data when available
|
// Attach ISRs to load cell data pins to read data when available
|
||||||
attachInterrupt(digitalPinToInterrupt(pin_lc0), read_lc0, LOW);
|
attachInterrupt(digitalPinToInterrupt(pin_lc0), read_lc0, LOW);
|
||||||
@@ -65,32 +64,6 @@ void setup() {
|
|||||||
Serial.println("Load Cells Initialized");
|
Serial.println("Load Cells Initialized");
|
||||||
Serial.println("Calibrating");
|
Serial.println("Calibrating");
|
||||||
|
|
||||||
// Load Cell Tare
|
|
||||||
double lc0Tot = 0.0;
|
|
||||||
double lc1Tot = 0.0;
|
|
||||||
double lc2Tot = 0.0;
|
|
||||||
double lc3Tot = 0.0;
|
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
lc0Tot += State.lc0;
|
|
||||||
lc1Tot += State.lc1;
|
|
||||||
lc2Tot += State.lc2;
|
|
||||||
lc3Tot += State.lc3;
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
lc0Offset = lc0Tot / 50.0;
|
|
||||||
lc1Offset = lc1Tot / 50.0;
|
|
||||||
lc2Offset = lc2Tot / 50.0;
|
|
||||||
lc3Offset = lc3Tot / 50.0;
|
|
||||||
|
|
||||||
Serial.println(lc0Tot);
|
|
||||||
Serial.println(lc1Tot);
|
|
||||||
Serial.println(lc2Tot);
|
|
||||||
Serial.println(lc3Tot);
|
|
||||||
|
|
||||||
Serial.println("Load Cells Tared");
|
|
||||||
|
|
||||||
// Initializes State variables
|
// Initializes State variables
|
||||||
State.lc0 = lc0.get_value();
|
State.lc0 = lc0.get_value();
|
||||||
State.lc1 = lc1.get_value();
|
State.lc1 = lc1.get_value();
|
||||||
@@ -100,14 +73,18 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
write2CSV(State);
|
// write2CSV(State);
|
||||||
delay(20);
|
// delay(20);
|
||||||
|
Serial.println(String(State.lc0) + ",\t" + String(State.lc1) + ",\t" +
|
||||||
|
String(State.lc2) + ",\t" + String(State.lc3));
|
||||||
|
Serial.println("~+~+~+~+~+~+~+~+~+~+~+~");
|
||||||
|
// delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_lc0() { State.lc0 = lc0.get_value() - lc0Offset; }
|
void read_lc0() { State.lc0 = lc0.get_value(); }
|
||||||
void read_lc1() { State.lc1 = lc1.get_value() - lc1Offset; }
|
void read_lc1() { State.lc1 = lc1.get_value(); }
|
||||||
void read_lc2() { State.lc2 = lc2.get_value() - lc2Offset; }
|
void read_lc2() { State.lc2 = lc2.get_value(); }
|
||||||
void read_lc3() { State.lc3 = lc3.get_value() - lc3Offset; }
|
void read_lc3() { State.lc3 = lc3.get_value(); }
|
||||||
|
|
||||||
void write2CSV(LoadCells &State) {
|
void write2CSV(LoadCells &State) {
|
||||||
|
|
||||||
@@ -122,7 +99,7 @@ void write2CSV(LoadCells &State) {
|
|||||||
dataFile.close();
|
dataFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initFile(){
|
void initFile() {
|
||||||
Serial.print("Initializing SD card...");
|
Serial.print("Initializing SD card...");
|
||||||
// see if the card is present and can be initialized:
|
// see if the card is present and can be initialized:
|
||||||
if (!SD.begin(chipSelect)) {
|
if (!SD.begin(chipSelect)) {
|
||||||
@@ -133,9 +110,9 @@ void initFile(){
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
const char *fileName;
|
const char *fileName;
|
||||||
|
|
||||||
if (SD.exists("simOut.csv")) {
|
if (SD.exists("loadCell.csv")) {
|
||||||
while (i > 0.0) {
|
while (i > 0.0) {
|
||||||
fileName = ("simOut_" + String(i) + ".csv").c_str();
|
fileName = ("loadCell_" + String(i) + ".csv").c_str();
|
||||||
|
|
||||||
if (!SD.exists(fileName)) {
|
if (!SD.exists(fileName)) {
|
||||||
// Open simOut_i.csv
|
// Open simOut_i.csv
|
||||||
@@ -165,7 +142,5 @@ void initFile(){
|
|||||||
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
Serial.println("Error opening output file. \n\nABORTING SIMULATION");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataFile.println(
|
dataFile.println("lc0,lc1,lc2,lc3");
|
||||||
"lc0,lc1,lc2,lc3");
|
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user