diff --git a/TwoCellMagChar/CalibConsts.hpp b/TwoCellMagChar/CalibConsts.hpp new file mode 120000 index 0000000..3281564 --- /dev/null +++ b/TwoCellMagChar/CalibConsts.hpp @@ -0,0 +1 @@ +../loadCellCode/CalibConsts.hpp \ No newline at end of file diff --git a/TwoCellMagChar/MagCharTrial.xlsx b/TwoCellMagChar/MagCharTrial.xlsx new file mode 100644 index 0000000..1ef3910 Binary files /dev/null and b/TwoCellMagChar/MagCharTrial.xlsx differ diff --git a/TwoCellMagChar/TwoCellMagChar.ino b/TwoCellMagChar/TwoCellMagChar.ino new file mode 100644 index 0000000..6ba984a --- /dev/null +++ b/TwoCellMagChar/TwoCellMagChar.ino @@ -0,0 +1,79 @@ +#include "HX711.h" +#include "CalibConsts.hpp" + +HX711 c0, c1; + +// adjust pins if needed. +#define c0Data 2 +#define c0Clock 3 +#define c1Data 4 +#define c1Clock 5 + +#define DIR0 7 +#define PWM0 6 +#define DIR1 8 +#define PWM1 9 + +void setup() +{ + pinMode(DIR0, OUTPUT); + pinMode(PWM0, OUTPUT); + pinMode(DIR1, OUTPUT); + pinMode(PWM1, OUTPUT); + + Serial.begin(115200); + Serial.println(); + Serial.println(__FILE__); + Serial.print("HX711_LIB_VERSION: "); + Serial.println(HX711_LIB_VERSION); + Serial.println(); + + c0.begin(c0Data, c0Clock); + c0.set_offset(OFFSET0); + c0.set_scale(SCALE0); + + c1.begin(c1Data, c1Clock); + c1.set_offset(OFFSET1); + c1.set_scale(SCALE1); +} + +void loop() { + while (Serial.available()) Serial.read(); + Serial.println("Enter any key to begin reading"); + while (!Serial.available()); + Serial.println("Reading Load Cells (Mean over 10 Readings)"); + float c0Avgs[11] = {0}; + float c1Avgs[11] = {0}; + uint8_t ind = 0; + + for (int16_t i = -250; i < 255; i+=50) { + Serial.print("Running PWM: "); + Serial.println(i); + digitalWrite(DIR0, i >= 0); + digitalWrite(DIR1, i >= 0); + analogWrite(PWM0, abs(i)); + analogWrite(PWM1, abs(i)); + delay(200); + for (uint8_t j = 0; j < 10; j++) c0Avgs[ind] += c0.get_units(); + c0Avgs[ind] /= 10; + for (uint8_t j = 0; j < 10; j++) c1Avgs[ind] += c1.get_units(); + c1Avgs[ind] /= 10; + ind++; + } + + digitalWrite(DIR0, 0); + digitalWrite(DIR1, 0); + digitalWrite(PWM0, 0); + digitalWrite(PWM1, 0); + + Serial.println("Average Values:"); + for (uint8_t i = 0; i < 11; i++) { + Serial.print("PWM "); + Serial.print((int) -250+i*50); + Serial.print(" - Cell 0: "); + Serial.print(c0Avgs[i]); + Serial.print("g, Cell 1: "); + Serial.print(c1Avgs[i]); + Serial.println("g"); + } +} \ No newline at end of file diff --git a/loadCellCode/CalibConsts.hpp b/loadCellCode/CalibConsts.hpp index 2181273..9d5c9a1 100644 --- a/loadCellCode/CalibConsts.hpp +++ b/loadCellCode/CalibConsts.hpp @@ -1,7 +1,10 @@ #ifndef CONSTANTS_H #define CONSTANTS_H -#define OFFSET 19532 -#define SCALE 108.633064 +#define OFFSET0 19532 +#define SCALE0 108.633064 + +#define OFFSET1 164066 +#define SCALE1 102.531166 #endif \ No newline at end of file diff --git a/loadCellCode/loadCellCode.ino b/loadCellCode/loadCellCode.ino index 204dc99..cf43a6a 100644 --- a/loadCellCode/loadCellCode.ino +++ b/loadCellCode/loadCellCode.ino @@ -11,8 +11,8 @@ HX711 myScale; // adjust pins if needed. -uint8_t dataPin = 2; -uint8_t clockPin = 3; +uint8_t dataPin = 4; +uint8_t clockPin = 5; void setup() @@ -25,8 +25,8 @@ void setup() Serial.println(); myScale.begin(dataPin, clockPin); - myScale.set_offset(OFFSET); - myScale.set_scale(SCALE); + myScale.set_offset(OFFSET1); + myScale.set_scale(SCALE1); } void loop()