Hello Arduino Forum
I am reaching out to you because I am in need of desperate assistance with my code and LCD display not functioning. I will attempt to make this problem as clear as possible and try to include everything.
My goal is to create a functioning load cell sensor that can give measurements on a LCD display monitor either in weight (g) or force (N).
The parts I am using includes an Arduino Uno, straight bar (100g) load cell sensor and an I2C 16x2 Arduino LCD display from DFRobot. The load cell and display will be provided in the links below.
Display: I2C 16x2(1602) LCD Display Module for Arduino - DFRobot
Load cell: https://www.digikey.com/catalog/en/partgroup/mini-load-cell-100g-and-500g-straight-bar-tal221/83054
As soon as I had all the parts I began to make the connections. Attached is the fritzing diagram I followed accompanied with photos of my attempt at connecting. MAJOR DIFFERENCE my DAT is connected to pin 2 on the arduino board and CLK is connected to 3 instead of 4,5 from fritz diagram.
I realize the setup is messy at best and my soldering skill is poor from attachments pic1 and 2 lol. However, the good news is that there is a response when using load cell on serial monitor therefore I can conclude that it's not a hardware connection problem.
Problem:
It all began when implementing the code. The same site I received the fritzing diagram from is where I got the code from.
// (c) Michael Schoeffler 2017, http://www.mschoeffler.de
#include <HX711_ADC.h> // GitHub - olkal/HX711_ADC: Arduino library for the HX711 24-bit ADC for weight scales
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
HX711_ADC LoadCell(4, 5); // parameters: dt pin, sck pin
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(999.0); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(16, 2); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to secon row
lcd.print(i); // print out the retrieved value to the second row
}
I was hoping that this would be a simple copy/paste thank you miss daisy, but no, how wrong I was to assume simplicity.
After extensive research I was able to figure out the simple problems like changing address according to the display, and eventually getting the damn code to compile. However, I am now faced with a problem I just can’t figure out no matter how much research I do. When uploading my code the display simply dims the light and nothing happens.
MY CODE
#include <HX711_ADC.h> // GitHub - olkal/HX711_ADC: Arduino library for the HX711 24-bit ADC for weight scales
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // LiquidCrystal_I2C library
HX711_ADC LoadCell(2, 3); // parameters: dt pin, sck pin
LiquidCrystal_I2C lcd(0x20, 16,2); // 0x27 is the i2c address of the LCM1602 IIC v1 module (might differ)
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(999.0); // calibration factor for load cell => strongly dependent on your individual setup
lcd.begin(16, 2); // begins connection to the LCD module
lcd.backlight(); // turns on the backlight
}
void loop() {
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
lcd.setCursor(0, 0); // set cursor to first row
lcd.print("Weight[g]:"); // print out to LCD
lcd.setCursor(0, 1); // set cursor to second row
lcd.print(i); // print out the retrieved value to the second row
}
I know it’s not the LCD display hardware because when using the HELLOWORLD code from the website it works fine.
CODE:
//DFRobot.com
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // set the LCD address to 0x20(Cooperate with 3 short circuit caps) for a 16 chars and 2 line display
void setup(){
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.home();
lcd.setCursor(0, 0);
lcd.print("Hello world...");
lcd.setCursor(0, 1);
lcd.print("dfrobot.com");
while(1);
}
int backlightState = LOW;
long previousMillis = 0;
long interval = 1000;
void loop(){
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
if (backlightState == LOW)
backlightState = HIGH;
else
backlightState = LOW;
if(backlightState == HIGH) lcd.backlight();
else lcd.noBacklight();
}
}
So I dont know what the issue is. If anyone could help me out with this I would be greatly appreciative it has been very stressful.
Im sure the problem is a simple code change but need help seeing it.
Thank you for your time
