Hi!
I have a HX711, 50kg load cell and adafruit sd7789. Trying to get the readings from HX711 to lcd screen, but dont know where to start..
I have used this code to get it calibrated and open serial monitor to get the values, but now i want to display the readings on a sd7789 display. Is there any easy way just to add some lines to the allready written code?
/*
-------------------------------------------------------------------------------------
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>
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
//pins:
const int HX711_dout = 4; //mcu > HX711 dout pin
const int HX711_sck = 5; //mcu > HX711 sck pin
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int calVal_eepromAdress = 0;
unsigned long t = 0;
void setup() {
Serial.begin(57600); delay(10);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
//LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
//EEPROM.begin(512); // uncomment this if you use ESP8266/ESP32 and want to fetch the calibration value from eeprom
#endif
//EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom
unsigned long stabilizingtime = 2000; // preciscion right after power-up 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");
while (1);
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
Serial.println("Startup is complete");
}
}
void loop() {
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //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) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
newDataReady = 0;
t = millis();
}
}
// 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");
}
}
Can maybe copy and paste something from this sd7789 code i have made, but it was for another purpose (I made this for a cooling system, where the fans would start at a given temperature, but this is not what I'm looking for now)
#define TFT_DC 7
#define TFT_RST 8
#define SCR_WD 240
#define SCR_HT 240
#include <SPI.h>
#include <Adafruit_GFX.h> //https://github.com/adafruit/Adafruit-GFX-Library
#include <OneWire.h>
#include <Arduino_ST7789_Fast.h> //https://github.com/cbm80amiga/Arduino_ST7789_Fast
#include <DallasTemperature.h> //https://github.com/milesburton/Arduino-Temperature-Control-Library
#define ONE_WIRE_BUS 2
#define TEMP_X 20
#define TEMP_Y 85
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int fan1 = A1;
int fan2 = A2;
int temp_sensor = 5;
int lowerLimit = 20;
int higherLimit = 21;
float previousTemp = -100.0;
float tempC = 0;
float minTemp = 200;
float maxTemp = 0;
Arduino_ST7789 tft = Arduino_ST7789(TFT_DC, TFT_RST);
void setup() {
Serial.begin(9600);
Serial.println("Starting up ...");
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
sensors.begin();
tft.init(SCR_WD, SCR_HT);
tft.fillScreen(BLACK);
tft.setCursor(0, 0);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.println(" Temperature");
tft.setCursor(160, TEMP_Y);
tft.setTextSize(5);
tft.setTextColor(WHITE);
tft.println((char)247 );
tft.setCursor(200, TEMP_Y);
tft.println("C");
tft.setCursor(40, 180);
tft.setTextSize(2);
tft.setTextColor(CYAN);
tft.println("MIN");
printMinTempDegreesSymbol();
printMaxTempDegreesSymbol();
tft.setCursor(170, 180);
tft.setTextSize(2);
tft.setTextColor(RED);
tft.println("MAX");
}
void loop() {
delay(1000);
digitalWrite(fan1, LOW);
digitalWrite(fan2, LOW);
Serial.print("Temperature is ");
Serial.print(tempC);
//Setup the fans to act as outputs
if (tempC <= lowerLimit) {
Serial.println(", No fan activated");
} else if (tempC > lowerLimit && tempC < higherLimit) {
Serial.println(", Fan 1 activated");
digitalWrite(fan1, HIGH);
} else if (tempC >= higherLimit) {
Serial.println(", Fan 1 and 2 activated");
digitalWrite(fan2, HIGH);
digitalWrite(fan1, HIGH);
}
sensors.requestTemperatures();
Serial.print("Temperature for the device 1 (index 0) is: ");
previousTemp = tempC;
tempC = sensors.getTempCByIndex(0);
if(tempC<minTemp)
{
deleteMinTemp();
minTemp = tempC;
}
if(tempC>maxTemp)
{
deleteMaxTemp();
maxTemp = tempC;
}
if(previousTemp!=tempC)
{
deletePreviousTemp();
printTemp();
printMinTemp();
printMaxTemp();
}
}
void deletePreviousTemp()
{
tft.setCursor(TEMP_X, TEMP_Y);
tft.setTextSize(5);
tft.setTextColor(BLACK);
tft.println(previousTemp,1);
}
void printTemp()
{
tft.setCursor(TEMP_X, TEMP_Y);
tft.setTextSize(5);
tft.setTextColor(WHITE);
tft.println(tempC,1);
}
void printMinTemp()
{
tft.setCursor(10, 210);
tft.setTextSize(2);
tft.setTextColor(CYAN);
tft.println(minTemp,1);
}
void printMaxTemp()
{
tft.setCursor(150, 210);
tft.setTextSize(2);
tft.setTextColor(RED);
tft.println(maxTemp,1);
}
void deleteMaxTemp()
{
tft.setCursor(150, 210);
tft.setTextSize(2);
tft.setTextColor(BLACK);
tft.println(maxTemp,1);
}
void deleteMinTemp()
{
tft.setCursor(10, 210);
tft.setTextSize(2);
tft.setTextColor(BLACK);
tft.println(minTemp,1);
}
void printMinTempDegreesSymbol()
{
tft.setCursor(70, 210);
tft.setTextSize(2);
tft.setTextColor(CYAN);
tft.println((char)247 );
tft.setCursor(85, 210);
tft.println("C");
}
void printMaxTempDegreesSymbol()
{
tft.setCursor(210, 210);
tft.setTextSize(2);
tft.setTextColor(RED);
tft.println((char)247 );
tft.setCursor(225, 210);
tft.println("C");
}
This is the setup:
Would appriciate all tips, and let me know if the post is missing any important information