Hallo zusammen, bin neu hier ... habe ein Problem.. Ich hoffe Ihr könnt mir helfen:
Also ich habe mir eine Waage mit dem HX711 aufgebaut und modifiziere der Zeit den Standartsketch.
Alles funktioniert soweit, aber die blinkende Anzeige gefällt mir nicht, ich möchte gerne, dass sich der Wert statisch darstellt und nicht immer blinkt auch wenn keine Wertänderung da ist.
Schön wäre es, wenn man die Differenz wann eine neue Anzeige ausgegeben wird definieren könnte.
Anbei mein Sketch.. es geht um den rot markierten Bereich...
Danke für Eure Hife ![]()
/*
-------------------------------------------------------------------------------------
HX711_ADC
Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales
Olav Kallhovd sept2017
-------------------------------------------------------------------------------------
*/
/*
Settling time (number of samples) and data filtering can be adjusted in the config.h file
For calibration and storing the calibration value in eeprom, see example file "Calibration.ino"
The update() function checks for new data and starts the next conversion. In order to acheive maximum effective
sample rate, update() should be called at least as often as the HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS.
If you have other time consuming code running (i.e. a graphical LCD), consider calling update() from an interrupt routine,
see example file "Read_1x_load_cell_interrupt_driven.ino".
This is an example sketch on how to use this library
*/
#include <HX711_ADC.h>
#include <EEPROM.h>
#include <TFT.h>
#include <SPI.h>
//pins:
const int HX711_dout = 4; //mcu > HX711 dout pin
const int HX711_sck = 5; //mcu > HX711 sck pin
#define cs 10
#define dc 9
#define rst 8
TFT TFTscreen = TFT(cs, dc, rst);
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int calVal_calVal_eepromAdress = 0;
unsigned long t = 0;
char sensorPrintout[6];
void setup() {
Serial.begin(57600); delay(10);
Serial.println();
Serial.println("Starting...");
//initialize the library
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
//set the text size
TFTscreen.setTextSize(3);
int calibrationValue; // calibration value
calibrationValue = 22.63; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266) || defined(ESP32)
// EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch this value from eeprom
#endif
//EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch this value from eeprom
LoadCell.begin();
unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration factor (float)
Serial.println("Startup is complete");
}
while (!LoadCell.update());
Serial.print("Calibration value: ");
Serial.println(LoadCell.getCalFactor());
Serial.print("HX711 measured conversion time ms: ");
Serial.println(LoadCell.getConversionTime());
Serial.print("HX711 measured sampling rate HZ: ");
Serial.println(LoadCell.getSPS());
Serial.print("HX711 measured settlingtime ms: ");
Serial.println(LoadCell.getSettlingTime());
Serial.println("Note that the settling time may increase significantly if you use delay() in your sketch!");
if (LoadCell.getSPS() < 7) {
Serial.println("!!Sampling rate is lower than specification, check MCU>HX711 wiring and pin designations");
}
else if (LoadCell.getSPS() > 100) {
Serial.println("!!Sampling rate is higher than specification, check MCU>HX711 wiring and pin designations");
}
}
void loop() {
static boolean newDataReady = 0;
const int serialPrintInterval = 500; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
// get smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
int i = LoadCell.getData();
// i = i * 0.1 ;
Serial.print("Load_cell output val: ");
Serial.println(i);
newDataReady = 0;
t = millis();
String sensorVal = String(i*(-0.001));
sensorVal.toCharArray(sensorPrintout, 6);
// set a random font color
TFTscreen.stroke(255, 255, 255);
TFTscreen.text("kg", 120, 40);
[color=red]TFTscreen.text(sensorPrintout, 20,40);
delay (200);
// erase the text you just wrote
TFTscreen.stroke(0, 0, 0);
TFTscreen.text(sensorPrintout, 20,40);
delay (200);[/color]
}
}
// receive command from serial terminal, send 't' to initiate tare operation:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
}