#include <LiquidCrystal.h>
//| LCD Pin | ESP8266 D1 Mini Pin |
//|-----------|---------------------|
//| VDD | 5V |
//| VSS | GND |
//| VO | Via Resistor to GND |
//| RS | D2 |
//| RW | GND |
//| E | D3 |
//| D4 | D4 |
//| D5 | D5 |
//| D6 | D6 |
//| D7 | D7 |
//| A (if available) | 5V |
//| K (if available) | GND |
//
//- **VDD** to **5V**: Powers the LCD.
//- **VSS** to **GND**: Ground connection.
//- **VO** with a resistor to **GND**: Controls the contrast.
//- **RS**, **E**, **D4** - **D7**: Data and control lines.
//- **A** (Anode) to **5V** and **K** (Cathode) to **GND** (if your LCD has backlight).
//
//This table assumes you're using a fixed resistor for contrast control connected to VO. Adjust the resistor value to get a readable contrast.
int counter = 0; // Variable to hold the count
// Initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(D2, D3, D4, D5, D6, D7); // RS, E, D4, D5, D6, D7
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // RS, E, D4, D5, D6, D7
// Scale
//| Wägezelle | HX711 | ESP8266 |
//|--------------|--------------|----------|
//| Rot (E+) | E+ | - |
//| Schwarz (E-) | E- | - |
//| Weiß (A-) | A- | - |
//| Grün (A+) | A+ | - |
//| - | VCC | 5V |
//| - | GND | GND |
//| - | DT | D2 (oder ein anderer GPIO-Pin) |
//| - | SCK | D1 (oder ein anderer GPIO-Pin) |
//
#include "HX711.h"
// HX711-Schaltung
#define LOADCELL_DOUT_PIN 8
#define LOADCELL_SCK_PIN 9
HX711 scale;
float calibration_factor = 1671;
//float calibration_factor = 72;
//float calibration_factor = 9387500;
void setup_scale() {
Serial.begin(115200);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(calibration_factor);
scale.tare(); // Tarieren mit leerer Wägezelle
}
void loop_scale() {
if (scale.is_ready()) {
float weight = scale.get_units(5); // Gewicht in Gramm (oder der von Ihnen gewählten Einheit)
Serial.print("Gewicht: ");
Serial.print(weight);
Serial.println(" g");
long reading = scale.read();
Serial.print("Messwert: ");
Serial.println(reading);
} else {
Serial.println("HX711 nicht bereit");
}
delay(100);
}
void setup_display() {
Serial.println("Started!");
Serial.begin(115200);
lcd.begin(16, 2);
lcd.print("Counter: ");
}
void loop_display() {
Serial.println(counter);
// Set the cursor to column 9, row 0
// Adjust the column number if your text doesn't fit
lcd.setCursor(9, 0);
// Print the current count
lcd.print(counter);
// Increase the counter by 1
counter++;
// Wait for a second
delay(1000);
}
void setup() {
setup_scale();
setup_display();
}
void loop() {
loop_scale();
loop_display();
}