diff --git a/config.yml b/config.yml index 1c5024d3cd6b60da6cba784f6f722cc2afdf43df..b21ad45af74cf32710441f55ff1e7301682b4212 100644 --- a/config.yml +++ b/config.yml @@ -7,13 +7,13 @@ DataLogger: InfoLogger: backupCount: 10 # number of logs to keep - maxBytes: 1000000 # size of single log + maxBytes: 1000000 # size of single log in bytes filename: log # filename for logs levels: # log level for outputting to file and to stdout respectivly - INFO - WARNING Data: - factors: [1, 1, 1, 0.9] # factors for the 4 dms + factors: [1, 1, 1, 1] # factors for the 4 dms delta_time: 30 # time between logging data - smoothing: false # wether to smoothe the logged data + smoothing: false # whether to smoothe the logged data diff --git a/main.py b/main.py index 0d38a1f1ea750108f847266597483d2a5e5c7101..6b57fec2ce0aeceead5ce14eb9537b58d5ae2234 100644 --- a/main.py +++ b/main.py @@ -77,8 +77,8 @@ def get_offset() -> np.ndarray: f"Time difference between last logged value and current time is very large: {difference.total_seconds():.0f}s." ) return np.array([float(num) for num in lines[-1].split(",")[1:5]]) - # didnt find any old files, so no offset - logger.warning(f"Didnt find any old offsets, so starting at 0.") + # didn't find any old files, so no offset + logger.warning(f"Didn't find any old offsets, so starting at 0.") return np.array([0, 0, 0, 0]) diff --git a/scripts/write.bash b/scripts/write.bash index f7049db74a7e84139baa4981b3bf04158e1813a5..828047c301069b48e4802b88fc3ab2d5174c0bae 100755 --- a/scripts/write.bash +++ b/scripts/write.bash @@ -7,13 +7,18 @@ core=arduino:avr id=$(python3 ../scripts/serial_id.py) -if [[ $id != "0" ]] +if [[ $id == "1" ]] then serial_dms=/dev/ttyACM0 serial_temp=/dev/ttyACM1 -else +elif [[ $id == "0" ]] +then serial_temp=/dev/ttyACM0 serial_dms=/dev/ttyACM1 +else + echo -e "\x1b[31mError: Something went wrong.\x1b[0m" + echo -e "Exiting" + exit 1 fi echo -e "Info: DMS arduino: $serial_dms, Temp arduino: $serial_temp" @@ -25,7 +30,7 @@ connected_devices=$(echo -e $device_list | grep "^\(\($serial_dms\)\|\($serial_t if [[ $connected_devices != "2" ]] then - echo -e "\x1b[31mError: not all arduino devices are connected\x1b[0m" + echo -e "\x1b[31mError: not all arduino devices are connected,\x1b[0m" echo -e "Connected devices are:\n$device_list" echo -e "Exiting." exit 1 diff --git a/sketches/DmsMessung/DmsMessung.ino b/sketches/DmsMessung/DmsMessung.ino index 7182fa07e945feceb1838c5ce577d62194c859d1..29d1bcf516a56ae5825114466a6db93907471f94 100644 --- a/sketches/DmsMessung/DmsMessung.ino +++ b/sketches/DmsMessung/DmsMessung.ino @@ -1,16 +1,27 @@ #include <HX711_ADC.h> +#include "cstring" HX711_ADC loadCells[] = {HX711_ADC(2, 3), HX711_ADC(6, 7), HX711_ADC(8, 9), HX711_ADC(12, 13)}; float measurements[4]; float offsets[4]; -int count = 1000; +int count = 100; long stabilization = 2000; void readData() { + // write the averaged data over 'count' measurements into 'measurements'. + + std::memset(measurements, 0, sizeof measurements); // zero out measurements + + for (int i = 0; i < count; i++) { + for (int j = 0; j < sizeof(loadCells) / sizeof(*loadCells); j++) { + loadCells[j].update(); + measurements[j] += loadCells[j].getRareData() - offsets[j]; + } + } + for (int i = 0; i < sizeof(loadCells) / sizeof(*loadCells); i++) { - loadCells[i].update(); - measurements[i] = loadCells[i].getRareData() - offsets[i]; + measurements[i] /= count; } } @@ -21,12 +32,11 @@ void setup() { loadCells[i].begin(); loadCells[i].start(stabilization, true); - - loadCells[i].update(); - - // zero out load cells - offsets[i] = loadCells[i].getRareData(); } + + // zero out load cells + readData(); + std::memcpy(offsets, measurements, sizeof offsets); } void loop() {