From 632176765d56299e19fb4ff05390f3b35de03215 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Wed, 10 May 2023 09:38:27 +0200 Subject: [PATCH] Added define to adjust calibration precision. (#18613) Co-authored-by: JeroenSt --- tasmota/my_user_config.h | 1 + tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index df6d82b53..0f4c01480 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -991,6 +991,7 @@ // #define TM1638_MAX_LEDS 8 // Add support for 8 leds //#define USE_HX711 // Add support for HX711 load cell (+1k5 code) // #define USE_HX711_GUI // Add optional web GUI to HX711 as scale (+1k8 code) +// #define HX711_CAL_PRECISION 1 // When HX711 calibration is to course, raise this value //#define USE_DINGTIAN_RELAY // Add support for the Dingian board using 74'595 et 74'165 shift registers // #define DINGTIAN_INPUTS_INVERTED // Invert input states (Hi => OFF, Low => ON) diff --git a/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino b/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino index 0a833b6fa..f6c78d83c 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino @@ -43,6 +43,10 @@ #ifndef HX_SCALE #define HX_SCALE 120 // Default result of measured weight / reference weight when scale is 1 #endif +#ifndef HX711_CAL_PRECISION +#define HX711_CAL_PRECISION 1 // When calibration is to course, raise this value. +#endif + #define HX_TIMEOUT 120 // A reading at default 10Hz (pin RATE to Gnd on HX711) can take up to 100 milliseconds #define HX_SAMPLES 10 // Number of samples for average calculation @@ -340,7 +344,7 @@ void HxEvery100mSecond(void) { for (uint32_t i = 2; i < HX_SAMPLES -2; i++) { sum_raw += Hx.reads[i]; } - Hx.raw_absolute = sum_raw / (HX_SAMPLES -4); // Uncalibrated value + Hx.raw_absolute = (sum_raw / (HX_SAMPLES -4)) * HX711_CAL_PRECISION; // Uncalibrated value Hx.raw = Hx.raw_absolute / Hx.scale; // grams if ((0 == Settings->weight_user_tare) && Hx.tare_flg) { // Reset scale based on current load