Hello,
I have a load cell. This bring diferent variations of numbers. I wanna to reproduce this numbers to a screen.
Thank you a lot.
LIBRARIES DOWN BELLOW
#include <HX711_ADC.h>
#include <EEPROM.h>
//HX711 constructor (dout pin, sck pin):
HX711_ADC LoadCell(3, 2);
const int eepromAdress = 0;
long t;
/////////////////////CANVI
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
float calValue; // calibration value
calValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266)
//EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch the value from eeprom
#endif
//EEPROM.get(eepromAdress, calValue); // uncomment this if you want to fetch the value from eeprom
Serial.begin(9600); delay(10);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
if(LoadCell.getTareTimeoutFlag()) {
Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calValue); // set calibration value (float)
Serial.println("Startup + tare is complete");
}
//////////////////////CANVI
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}
void loop()
{
//update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
//use of delay in sketch will reduce effective sample rate (be carefull with use of delay() in the loop)
LoadCell.update();
//get smoothed value from data set
if (millis() > t + 250) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
t = millis();
}
//receive from serial terminal
if (Serial.available() > 0) {
float i;
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}
//check if last tare operation is complete
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
/////////////CANVI
// lcd.clear();
// lcd.setCursor(0,0);
// lcd.print(millis()/1000.0);
// delay(200);
//
}
Please read the sticky post at the top of the forum about how to properly post your code using code tags. It helps people help you.
If you want to print the scale value on the lcd, then move all your lcd.print() statements into the your if() statement so that the value will be available. You could also pick a better name for your variables rather than 'i' and 't'
#include <HX711_ADC.h>
#include <EEPROM.h>
//HX711 constructor (dout pin, sck pin):
HX711_ADC LoadCell(3, 2);
unsigned long lastTime;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
float calValue; // calibration value
calValue = 696.0; // uncomment this if you want to set this value in the sketch
Serial.begin(9600); delay(10);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
const unsigned long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calValue); // set calibration value (float)
Serial.println("Startup + tare is complete");
}
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Hello, world!");
lcd.setCursor(2, 1);
lcd.print("Ywrobot Arduino!");
/* you only have 2 lines on your lcd so you
can't move to lines 3 and 4
lcd.setCursor(0, 2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2, 3);
lcd.print("Power By Ec-yuan!");
*/
}
void loop()
{
LoadCell.update();
//get smoothed value from data set
if (millis() - lastTime >= 250) {
float scaleValue = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(scaleValue);
lastTime = millis();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(millis() / 1000);
lcd.setCursor(0,1);
lcd.print(scaleValue,2);
}
//receive from serial terminal
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");
}
}
Ok, thanks.
Yes are showed.
But the truth is that i have the code of the load cell ( is like a weighing machine) and it works, I could see the numbers of the data. This was the code
and also I have the code of the screen (is down ) but I cant mix the two codes.
//-------------------------------------------------------------------------------------
// HX711_ADC.h
// Arduino master library for HX711 24-Bit Analog-to-Digital Converter for Weigh Scales
// Olav Kallhovd sept2017
// Tested with : HX711 asian module on channel A and YZC-133 3kg load cell
// Tested with MCU : Arduino Nano, ESP8266
//-------------------------------------------------------------------------------------
// This is an example sketch on how to use this library
// Settling time (number of samples) and data filtering can be adjusted in the config.h file
#include <HX711_ADC.h>
#include <EEPROM.h>
//HX711 constructor (dout pin, sck pin):
HX711_ADC LoadCell(3, 2);
const int eepromAdress = 0;
long t;
void setup() {
float calValue; // calibration value
calValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266)
//EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch the value from eeprom
#endif
//EEPROM.get(eepromAdress, calValue); // uncomment this if you want to fetch the value from eeprom
Serial.begin(9600); delay(10);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
if(LoadCell.getTareTimeoutFlag()) {
Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calValue); // set calibration value (float)
Serial.println("Startup + tare is complete");
}
}
void loop() {
//update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
//use of delay in sketch will reduce effective sample rate (be carefull with use of delay() in the loop)
LoadCell.update();
//get smoothed value from data set
if (millis() > t + 250) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
t = millis();
}
//receive from serial terminal
if (Serial.available() > 0) {
float i;
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}
//check if last tare operation is complete
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
}
and then I have the code of the screen (That it works)
[code]
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(millis()/1000.0);
delay(200);
}
But I cant mix the two codes
Thanks a lot
const int eepromAdress = 0;
long t;
/////////////////////CANVI
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
float calValue; // calibration value
calValue = 696.0; // uncomment this if you want to set this value in the sketch
#if defined(ESP8266)
//EEPROM.begin(512); // uncomment this if you use ESP8266 and want to fetch the value from eeprom
#endif
//EEPROM.get(eepromAdress, calValue); // uncomment this if you want to fetch the value from eeprom
Serial.begin(9600); delay(10);
Serial.println();
Serial.println("Starting...");
LoadCell.begin();
long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
if(LoadCell.getTareTimeoutFlag()) {
Serial.println("Tare timeout, check MCU>HX711 wiring and pin designations");
}
else {
LoadCell.setCalFactor(calValue); // set calibration value (float)
Serial.println("Startup + tare is complete");
}
//////////////////////CANVI
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("Ywrobot Arduino!");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("Power By Ec-yuan!");
}
void loop()
{
//update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS
//use of delay in sketch will reduce effective sample rate (be carefull with use of delay() in the loop)
LoadCell.update();
//get smoothed value from data set
if (millis() > t + 250) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
t = millis();
}
//receive from serial terminal
if (Serial.available() > 0) {
float i;
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}
//check if last tare operation is complete
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
Add some lcd.prints of the same information. No doubt it will be a nasty mess.
You will then need to set cursor positions or clear the lcd or overwrite some area with spaces, but at least you'll have something showing, it's just a matter of cleaning it up.
You already know about cursor positioning - you're using it in setup.