From e26fc4051bc6f373479bf3605e7a435ba54b5f94 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Mon, 10 Feb 2020 19:41:40 +0100 Subject: [PATCH] replace bodge/HX711 with Sthing/Q2-HX711-Arduino-Library --- mini-beieli-node.ino | 28 ++++++++-------------------- mini_beieli_node.h | 2 +- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/mini-beieli-node.ino b/mini-beieli-node.ino index 5a6c5e1..fbffcec 100644 --- a/mini-beieli-node.ino +++ b/mini-beieli-node.ino @@ -25,7 +25,7 @@ #include #include -#include +#include #include "mini_beieli_node.h" using namespace McciCatena; @@ -132,7 +132,7 @@ Catena_Mx25v8035f gFlash; bool fFlash; // Scales -HX711 LoadCell; +Q2HX711 hx711(A1, A0); // USB power bool fUsbPower; @@ -302,19 +302,9 @@ bool setup_scales(void) // Enable Power digitalWrite(D10, HIGH); - // Initialize library with data output pin, clock input pin and gain factor. - // Channel selection is made by passing the appropriate gain: - // - With a gain factor of 64 or 128, channel A is selected - // - With a gain factor of 32, channel B is selected - // By omitting the gain factor parameter, the library - // default "128" (Channel A) is used here. - LoadCell.begin(A1, A0, 32); - - if (!(LoadCell.wait_ready_timeout(2000))) { - gCatena.SafePrintf("%010d - Scale not ready after Init.\n"); - res = false; - } - + // we wait 400ms (settling time according HX711 datasheet @ 10 SPS + delay(400); + if (config_data.debug_level > 0) { gCatena.SafePrintf("%010d - setup_scale done\n", millis()); } @@ -576,7 +566,7 @@ void bubbleSort(long A[], int len) { long my_read_average(byte gain, byte times) { long res; - int const num_scale_readings = 25; // number of instantaneous scale readings to calculate the median + int const num_scale_readings = 50; // number of instantaneous scale readings to calculate the median // we use the median, not the average, see https://community.particle.io/t/boron-gpio-provides-less-current-than-electrons-gpio/46647/13 long readings[num_scale_readings]; // create arry to hold readings @@ -585,12 +575,10 @@ long my_read_average(byte gain, byte times) { gCatena.SafePrintf("%010d - my_read_average, measurements: ", millis()); } - LoadCell.set_gain(gain); - // we wait 400ms (settling time according HX711 datasheet @ 10 SPS - delay(400); + hx711.setGain(gain); for (int i = 0; i < num_scale_readings; i++) { - readings[i] = LoadCell.read(); // fill the array with instantaneous readings from the scale + readings[i] = hx711.read(); // fill the array with instantaneous readings from the scale } res = median(readings, num_scale_readings); // calculate median diff --git a/mini_beieli_node.h b/mini_beieli_node.h index 867d26f..fbf60ce 100644 --- a/mini_beieli_node.h +++ b/mini_beieli_node.h @@ -56,7 +56,7 @@ enum { | \****************************************************************************/ -static const int32_t fwVersion = 20200207; +static const int32_t fwVersion = 20200210; static const byte INIT_PACKAGE_INTERVAL = 100; // send an init package every 100 packages; static const byte MAX_VALUES_TO_SEND = 8;