Hello,
I'm setting up a very simple scale using a load cell, a HX711 load cell amp and an Arduino Uno board. I tested the load cell via the Serial Port, hence I know the load cell code, wiring and calibration is correct.
I then wanted to switch the load cell output reading from being displayed via the serial port to the LCD. When the code starts, the screen lights up, but no info whatsoever is displayed. After some testing, I noticed that when I remove the scale.tare(); line, the LCD starts working correctly (yet no load cell output is displayed since the load cell initialization isn't complete). I changed the load cell pins, to rule this one out, but to no avail.
Hence, for now I get either the load cell or the LCD display working, but not both at the same time. Not sure if there might be an interaction between "LiquidCrystal_I2C.h" and "HX711.h" I am not aware about.
Here is the code. Maybe one of you can see something that eludes me.
Thanks in advance.
M!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "HX711.h"
#define calibration_factor -1300
#define DOUT 19
#define CLK 18
HX711 scale(DOUT, CLK);
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
lcd.begin(20,4);
scale.set_scale(calibration_factor);
scale.tare(); // This line makes the LCD remain blank
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Reading:");
lcd.setCursor(0,1);
lcd.print(scale.get_units(), 1);
}
Have you tried a simple LCD example that e.g. prints "hello world" and does not use the HX711? Does it work?
Yes, I’ve tried a simple LCD example, removing everything related to the HX711 and it works fine in that scenario.
is the HX711 using the i2c bus as well ?
i'm not sure what pins these refer to...
#define DOUT 19
#define CLK 18
Valid point by BabyGeezer. An uno does not really have pins 18 and 19.
18 equals A4 and 19 equals A5, which also are the I2C pins.
This link may be helpful for more information on I2C driven LCD.
sterretje:
18 equals A4 and 19 equals A5, which also are the I2C pins.
so it is also using the i2c bus, which means you have to write some extra code to cater for using the LCD and the HX711 simultaneously.
i haven't yet gotten into using more than one device on the i2c bus so i have no code at hand to help, but that would seem to be the issue you are facing.
BabyGeezer:
so it is also using the i2c bus, which means you have to write some extra code to cater for using the LCD and the HX711 simultaneously.
Just using other pins for the HX711 is probably also a possibility 
Example on this page uses e.g. D2 and D3.
Thank you. It seems I wasn't sufficiently thorough when I tried to rule the pins out as the source of the problem. Changing the pins indeed made the LCD display a reading from the load cell. While I knew that pins 18/19 do not technically exist on the Uno, I was unaware of the way they interacted with the LCD. Thanks for sharing that link which helped clarifying this.
I used these "pins" as this is part of a wider project. Namely a temp controller for fermenting beer. The uno has already a Data Logger and a Battery shield connected to it, as well as 3 digital temp sensors, a relay module (w/ 3 used) and the LCD screen. Not so many extra pins available. So far temp control was based solely on elapsed time, measured since the start of the fermentation process, but now I'm incorporating the measurement of Specific Gravity as a variable which can trigger changes in temperature. The HX711 is now connected to "pins" 16/17 and I still need to make sure there are no other unforeseen interactions with the other components. As a fallback I think I can use pins 0/1, since I don't use serial comms during the operation of the controller itself.
Best,
M!
It's often 'clearer' to do something like below; you can straight away see to which pins it needs to be connected on an Uno board.
It's also a little easier to migrate to another Arduino (e.g. a Mega where pins 18 and 19 are at a different place on the board) if that is ever needed; the Arduino software 'libraries' will take care of mapping to the correct pin on the board.
#define DOUT A5
#define CLK A4
Maybe an image like this helps to prevent issues like you experienced. E.g. PWM on pin 11 or flashing the led on pin 13 will interfere with SPI functionality.
If you're short on pins, you can use e.g. I2C port expanders (will not cost you additional pins on the Uno as you're already using the I2C bus).
Margoye:
While I knew that pins 18/19 do not technically exist on the Uno,
But digital pins 18 and 19 do exist. On an Uno, they are the same as A4 and A5.
i.e. the digital pins go from 0 to 13 and then keep going on the analog pins.
So A0 is 14, A1 is 15, A2 is 16, A3 is 17, A4 is 18, A5 is 19.
As sterretje pointed out, the issue in this case, while not obvious, was pin collision.
The HX711 library is directly using the same pins that i2c uses for something other an i2c which causes the Wire library to not work correctly.
digital pin 18 is the same as analog pin 4 which is the same as i2c SDA
digital pin 19 is the same as analog pin 5 which is the same as i2c SCL
Here are some additional photos of pin mappings for a few of the Arduino boards:
--- bill