diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 78f8c5e..8fde7d0 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,8 +1,10 @@ -{ - "recommendations": [ - "ms-vscode.cpptools", - "wayou.vscode-todo-highlight", - "usernamehw.errorlens", - "platformio.platformio-ide" - ] -} \ No newline at end of file +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "ms-vscode.cpptools", + "platformio.platformio-ide", + "usernamehw.errorlens", + "wayou.vscode-todo-highlight" + ] +} diff --git a/include/LoadCells.h b/include/LoadCells.h new file mode 100644 index 0000000..5150db6 --- /dev/null +++ b/include/LoadCells.h @@ -0,0 +1,43 @@ +struct LoadCells { + HX711 loadcell_0; + HX711 loadcell_1; + HX711 loadcell_2; + HX711 loadcell_3; + + double lc0Value; + double lc1Value; + double lc2Value; + double lc3Value; + + double lc0Calibration; + double lc1Calibration; + double lc2Calibration; + double lc3Calibration; +}; + +void init_LoadCells(LoadCells &loadCells) { + + + const int lc_clock = 23; + + const int lc_data_0 = 0; + const int lc_data_1 = 1; + const int lc_data_2 = 2; + const int lc_data_3 = 3; + + Serial.begin(9600); // Begin serial connection + pinMode(LED_BUILTIN, OUTPUT); // Configure LED pin + // Configure clock pin with high impedance to protect pin (if this doesn't + // work, change to OUTPUT) + pinMode(lc_clock, INPUT); + // Configure load cell data pins as inputs + pinMode(lc_data_0, INPUT); + pinMode(lc_data_1, INPUT); + pinMode(lc_data_2, INPUT); + pinMode(lc_data_3, INPUT); + + loadCells.lc0Calibration = loadCellCalibrate(loadcell_0); + loadCells.lc1Calibration = loadCellCalibrate(loadcell_1); + loadCells.lc2Calibration = loadCellCalibrate(loadcell_2); + loadCells.lc3Calibration = loadCellCalibrate(loadcell_3); +} \ No newline at end of file diff --git a/include/teensy.h b/include/teensy.h index 49cf3ef..4f6f64e 100644 --- a/include/teensy.h +++ b/include/teensy.h @@ -1,22 +1,20 @@ #include "Vehicle.h" -#include - void thrustInfo(struct Vehicle &); void processTVC(struct Vehicle &); void write2CSV(struct outVector &, struct Vehicle &); void printSimResults(struct Vehicle &); -double loadCellCalibrate(); +double loadCellCalibrate(struct LoadCells &); -double loadCellCalibrate() { +double loadCellCalibrate(LoadCells &loadCells) { // place code to calibrate load cells in here - double loadTotal; + double loadTotal = 0.0; for (double t = 0; t == 10; ++t) { - loadTotal += 1; + loadTotal += loadCell.read(); delay(15); } - return loadTotal / 10; + return loadTotal / 10.0; } void thrustInfo(Vehicle &State) { diff --git a/platformio.ini b/platformio.ini index dcd71dc..529de37 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,13 +8,14 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html - [env:NATIVE] platform = native build_flags = -std=c++11 -Wall -O1 -D NATIVE +lib_deps = bogde/HX711@^0.7.4 [env:teensy41] platform = teensy board = teensy41 framework = arduino build_flags = -std=c++11 -Wall -O1 -D TEENSY +lib_deps = bogde/HX711@^0.7.4 diff --git a/src/main.cpp b/src/main.cpp index f2ad13d..4310051 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #include #elif defined(TEENSY) #include +#include "HX711.h" unsigned long last; #endif @@ -21,6 +22,7 @@ unsigned long last; #include "native.h" #elif defined(TEENSY) #include "teensy.h" +#include "LoadCells.h" #endif Vehicle State; @@ -45,7 +47,11 @@ void setup() { burnStartTimeCalc(State); Serial.println("Starting Height Calculated"); delay(1000); - loadCellCalibrate(); + + LoadCells loadCells; + + init_LoadCells(loadCells); + Serial.println("Load Cells Calibrated"); delay(1000); }