olkal / hx711_adc Goto Github PK
View Code? Open in Web Editor NEWArduino library for the HX711 24-bit ADC for weight scales
License: MIT License
Arduino library for the HX711 24-bit ADC for weight scales
License: MIT License
Hello,
the HX711 has to channels. I would like to connect two load cells but how can I read them?
The return type for HX711_ADC::start()
is int
, though it does not return anything.
The return type for HX711_ADC::conversion24bit()
is uint8_t
, though it also returns nothing.
It does compile fins with these errors in Arduino IDE, but I am getting errors in Sloeber. I have fixed them by modifying the source code, I suggest this is done here as well.
Hi,
compiling fails on SAMD21 Cortex M0 boards such as the Adafruit Feather M0 (and Arduino Zero?) as the sei() and cli() functions do not exist there.
Replacing calls to them in smoothedData() with interrupts() and noInterrupts() allows it to build.
see also
adafruit/Adafruit_TLC59711#7
https://forum.arduino.cc/index.php?topic=130583.0
thanks,
Hamish
A timeout in the function startMultiple() is required, as in the tare() function.
Hi,
Before anything thanks for creating this library! it's really helpful, i've been using it in a personal project and it uses 4 LC's (each with it's owns HX711) and i'm using 80Hz as i need the faster response.
I was wondering what changes in the code, if anything, when using 80 Hz, since i've been testing the examples 'read1x' and 'read2x' and i didn't notice a big difference between using 80Hz or 10Hz.
Thank you very much!
hello guys.
have anny change can i do to make the program more fast to find my weight? actually he takes 2 seconds to give me my right weight but for my aplication i need that a little bit more fast.
i tried some alterations on smoothData and not work (in hexadecimal values).
thanks for you time.
Allan Johnson
First of all, thanks for this awesome library!
I'm not sure if this is the case, but it feels like if I perform some task in loop()
that takes some time to finish (but only needs to be done once in a while), LoadCell.getData();
takes some time to flush out data recorded in the past, and only after some time does it go back to fresh / current weight reading. I want to first confirm that this is indeed the case - since I could be imagining things I guess... But if this is the case, is there a way to clear the "stale" data so that LoadCell.getData();
starts reporting more "real-time" data even after a blocking task on mcu?
Thanks!
Is there a way to construct the HX711_ADC object without assingning pins right away? For my program it is needed to ask for the pins of the HX711 in a dialog and then construct the HX711. All while Loadcell beeing a global object. Like this:
`HX711_ADC Loadcell();
void setup(){
dialog(); //user sets pin1 and pin2 through serial dialog
HX711_ADC Loadcell(pin1, pin2);
}`
Thanks for anyone who can help!
Hi,
I haven't found any units for measurement ? Have I overlooked it or units aren't written anywhere ?
Cheers
Hi,
I have big LoadCell with total 200 MT.
Using this library on 5KG and 10 KG has no issue,
But when connected to 200MT LoadCell,
Reads of get data is unstable and fluctuated.
Do you have any idea to resolve this problem?
Thank you
Hi,
I've found an issue in the startMultiple() function(s) of your library. At the beginning of the function (lines 86 and 135), the timeout for the tare completion is initialized as:
static unsigned long timeout = millis() + tareTimeOut;
This makes the timeout variable to be set the first time the startMultiple() function is executed. So, it assumes the tare completion has to occur tareTimeOut milliseconds after that first execution. Nevertheless, since the function executes some conversions (update()) continuously during the stabilization time, before the tare is triggered (doTare is set), it is possible (and frequent) that the timeout has already completed even before triggering the tare. This causes the tareTimeoutFlag to be set in situations it shouldn't.
To solve the issue, I think moving the timeout initialization line (as is, keeping the "static") just before doTare = 1 (lines 106 and 157) should suffice.
P.S. I'm too lazy right now to make a pull request.
Sorry to keep bothering you.
First of all, congratulations for the library. This was the only one I used that managed to get data from multiple HX711 without any problem.
My question: is there a way to change the number of samples used for the smooth average without changing the library (HX711_ADC.h) itself? As far as I noticed there isn't any function to change this variable.
If there isn't indeed, would you accept it as a Pull Request?
In function HX711_ADC::tare() , there is a while (rdy !=2) {...
This while loop can cause an endless loop if no valid conversions are received (e.g. due to a hardware issue). I propose to add a timeout to the function:
void HX711_ADC::tare()
{
uint8_t rdy = 0;
uint8_t timeout = 255;
doTare = 1;
tareTimes = 0;
while(rdy != 2) {
rdy = update();
if (timeout == 0) {
Serial.println("Tare timed out");
break;
}
timeout++;
}
}
When i put the calibration code in for the load cell, I get the output of zeros over and over again and when I press the load cell it doesn't read it. Sometimes though when I'm not touching it at all it jumps to high number like 3000. Help
tareNoDelay() is defined in the cpp file, however the associated keyword is listed as taretareNoDelay()
18:56:24.402 -> ⸮⸮⸮⸮⸮⸮j⸮⸮�#⸮⸮ĥ1⸮⸮�⸮DaA⸮
18:56:28.321 -> c⸮�⸮!��PŲ
hello, I am getting the above output when I run the calibration file with a single load cell and using arduino uno, please can you tell me why is the output so weird?
currently when doing an update(), the code writing to the data smooth index handling looks to see if it is buffer size - 1 and then sets it to 0. Unfortunately, if you create this with new, or you are putting it into stack memory that has already been used, the index initially can be outside the range 0 - buffersize -1.
To fix this the safest thing would be before it writes to the buffer, the index should be checked to ensure it is >= 0 and < buffer size and if it is outside that range, set to 0,.
An alternative would be to initialize the index to 0 on construction, but this does leave the possibility of some other bug setting it out of range and the update() continuing to overwrite memory it doesn't own.
Hi,
Thank you for the great library! With my latest CoG-scale I encountered with a problem; everything else works like earlier but there is a linear drift in readings, depending on weight area it is from 0,1 g / 5 sec to maybe 0,2 g / sec. The same issue applies on both load cell-HX711 -pairs, so I think there is no HW problem. Have you bumped in to this kind of problem? If library's smoothing function is disabled the drifting turns slower but still exists. I tried also different sample sizes (config.h) and disabling the outlier -compensation.
Originally posted by @aaromalila in #33 (comment)
This code work perfect, calibrating i so easy.
After I calibrated the calFactor using examples/Calibration.ino, its save to eeproom.
And i just run another examples and get calFactor from eeprom.
It's work perfectly.
But, when I restart the serial monitor with mass at the load cell, the value is reset to 0. And value become negative when taking out mass from the loadcell.
How to start the code if we have mass at the loadcell without reset the value?
Thank you
sorry, i m not using english
Hello
Thank you for sharing your code.
One of your examples have 2 load cell, but they use different CLK pin
Any chance there might be possible to hook up multi HX711 boards that share the same CLK pin?
Hi,
Board - Arduino uno
IDE - Arduino 1.8.1
Code - HX711_ADC/examples/Calibrate/Calibrate.ino
ADC + Amplifier - HX711 Breakout board (Green color)
Sensor - 1Kg load cell
Vcc - 3.3
Gnd - Gnd pin
data - pin 3
clock -pin 4
I am trying to read data from load cell.I only get the output as 0 sometimes -0.00 even if i put some load on the load cell.
output -
Wait...
Startup + tare is complete
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
Load_cell output val: 0.00
some one please help me?
Thank you
When doing
LoadCell.begin();
long stabilizingtime = 2000; // tare preciscion 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);
LoadCell.setCalFactor(calibrationValue); // user set calibration value (float)
LoadCell.setSamplesInUse(1)
if (LoadCell.update()) newDataReady = true;
//get smoothed value from data set
if (newDataReady) {
float a = LoadCell.getData();
}
I get wrong data. Shouldn't
Line 112 in dff0de8
be initialized to 0?
Building a dual weight with individual HX711 sensors, but need a function for re-calibrating bouth sensors individually within a sketch.
When using the Calibration Sketch, I can get the raw number using getData(), but are not able to retreive this inside a sketch. Then I only get the calibrated number.. Tried getTareOffset(), but it's not the same as what I get using getData() in the calibration sketch.
How can I easily re-calibrate HX711 (not just setting a new setCalFactor()) using two individual sensors within the Read_2x_load_cell.ino sketch?
Originally posted by @msevland in #33 (comment)
Hi Olav,
Shouldn't the function update() be called, instead of getData()? Otherwise, the stabilization for taring due to initial conversions is not achieved
Line 50 in d8c661a
Best regards,
Miguel
Hello @olkal,
first of all: great library!
When compiling your example sketches I get several warnings. You can easily improve the code:
See all warnings below.
Best wishes, Wolfgang
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\examples\Read_1x_load_cell\Read_1x_load_cell.ino: In function 'void loop()':
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\examples\Read_1x_load_cell\Read_1x_load_cell.ino:69:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (millis() > t + serialPrintInterval) {
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\examples\Read_1x_load_cell\Read_1x_load_cell.ino:80:11: warning: unused variable 'i' [-Wunused-variable]
float i;
^
In file included from C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\examples\Read_1x_load_cell\Read_1x_load_cell.ino:22:0:
C:\Users\Ewald\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\libraries\EEPROM\src/EEPROM.h: At global scope:
C:\Users\Ewald\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\libraries\EEPROM\src/EEPROM.h:145:20: warning: 'EEPROM' defined but not used [-Wunused-variable]
static EEPROMClass EEPROM;
^~~~~~
Compiling libraries...
Compiling library "HX711_ADC"
"C:\Users\Ewald\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Users\Ewald\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino" "-IC:\Users\Ewald\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\variants\standard" "-IC:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src" "-IC:\Users\Ewald\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\libraries\EEPROM\src" "C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src\HX711_ADC.cpp" -o "C:\Users\Ewald\AppData\Local\Temp\arduino_build_388271\libraries\HX711_ADC\HX711_ADC.cpp.o"
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src\HX711_ADC.cpp: In member function 'int HX711_ADC::startMultiple(unsigned int)':
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src\HX711_ADC.cpp:99:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(millis() - startMultipleTimeStamp > startMultipleWaitTime) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src\HX711_ADC.cpp: In member function 'int HX711_ADC::startMultiple(unsigned int, bool)':
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src\HX711_ADC.cpp:148:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(millis() - startMultipleTimeStamp > startMultipleWaitTime) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src\HX711_ADC.cpp: In member function 'void HX711_ADC::setSamplesInUse(int)':
C:\Users\Ewald\Documents\Arduino\libraries\HX711_ADC\src\HX711_ADC.cpp:425:6: warning: unused variable 'old_divbit' [-Wunused-variable]
int old_divbit = divBit;
^~~~~~~~~~
When I read the value, the resonse data increase or decrease slowly in step of aroud 3~4 g and finally stablize in the item weight. Is that possible to get the data immediately or much faster? I use the Ardiuno UNO board for testing. Code as below.
#include <HX711_ADC.h>
#include <LiquidCrystal.h>
float Weight = 0;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//HX711 constructor (dout pin, sck pin)
HX711_ADC LoadCell(10, 13);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Welcome!");
LoadCell.begin();
long stabilisingtime = 100; // tare preciscion can be improved by adding a few seconds of stabilising time
LoadCell.start(stabilisingtime);
LoadCell.setCalFactor(696.0); // user set calibration factor (float)
delay(3000);
}
void loop() {
lcd.clear();
LoadCell.update();
Weight = LoadCell.getData();
lcd.print("Weight = ");
lcd.print(Weight); //the true weight
lcd.print(" g");
delay(1000);
}
Hello.
First of all, thanks for this amazing work.
I followed the steps to calibrate and read one single sensor but when I remove any item from my scale the value showed to me change between -0.1 and -0.0, do you know how to fix this in zero?
Thanks again
Hello,
I'm truing to use the library with an Arduino MKR1010 Wifi, however the MKR boards don't have EEPROM. I was wondering if there's any advice on how to get this done.
Thanks!
Hello,
is this supposed to work with the ESP8266 module?
Get only errors and the module restart and restart
`⸮Wait...
Soft WDT reset
ctx: cont
sp: 3ffef220 end: 3ffef430 offset: 01b0
stack>>>
3ffef3d0: 3ffe84a0 00000000 3ffee3e4 40202139
3ffef3e0: 3ffe8425 feefeffe 3ffee2ac 40201ea6
3ffef3f0: feefeffe feefeffe 3ffee2ac 40201ed3
3ffef400: 3fffdad0 3ffee2ac 3ffee3e4 40201c2b
3ffef410: feefeffe 00000000 3ffee400 402025f4
3ffef420: feefeffe feefeffe 3ffee410 40100114
<<<stack<<<
⸮⸮b !⸮⸮d
Wait...
`
In general multiplication is faster than division. The Atmega 328 (and I assume 168) has hardware multiply but not hardware division so multiply is very much faster. I suggest changing calFactor to a multiplier internally.
calFactorRecip = 1 / calFactor;
and then multiply raw values by calFactorRecip.
I may be able to get a pull request done with proposed changes but I don't know when so I will raise this as an issue.
I see hardcoded Serial calls in this lib, which as far as i know, exclude it from use on the AT tiny 85.
Hi,
could you add license such as MIT or LGPL so other can use your library ?
Cheers
I dont know if this is the expexted behavior but i got a lot of issued because of this.
When you connect a weight cell to the hx711 without a load. We get a value close to zero out of conversion24bit()
If you now pull on the weightcell, the data overflows and we get a value close to 2^24.
The problem is, that some weightcells and or HX711 Chips have an offset at the beginning...
This means when you have no load on the weightcell than we get a value close to 2^24 out of conversion24bit()
.
When you now start to put a weight on the weightcell then the data out of conversion24bit()
overflows and it jumps close to zero.
This means you meassure a huge negative value and you cant really meassure anymore...
My Solution:
By inverting the MSB we can shift the data we get out of conversion24bit()
to the middle of the range.
This results in a decrease in number when we pull on the weightcell and an increase when we put a weight on it. An offset at the beginning has no effect anymore because there is no overflow near to zero/no weight.
I added this line to conversion24bit()
which fixes the problem for me...
data = data ^ 0b10000000000000000000000; //Invert MSB
Here i try to visualize it... xD
Before the "fix"
0
|-------------------------|
After the fix
0
|-------------------------|
0 Is the position with no weight on the loadcell and |--| the range of the 24 bit.
I have a simple code to setup and read the data from the load cell. However when I start the scale with load on it, it starts at 0 rather than the initial weight of the object on it.
Is there a way to disable the tare() so it gets the actual weight on the loadcell even at the start point?
Code I have:
HX711_ADC LoadCell(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
void setup() {
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(200.0); // calibration factor for load cell
}
void loop(){
LoadCell.update(); // retrieves data from the load cell
long reading = LoadCell.getData(); // get output value
Serial.print("HX711 reading: ");
Serial.println(reading);
}
Hi I am a beginner in Arduino. I wanted to use the HX711_ADC library in my sketch. I want to set the calibration factor myself. My sketch is meant for issuing an abort signal to a process when the mass measured by load cell crosses a certain value.
Pardon my questions as I am only a beginner.
In HX711_ADC::startMultiple(unsigned int t) appears the line
if(millis() < startMultipleTimeStamp + startMultipleWaitTime)
which will fail to work as expected if startMultipleTimeStamp + startMultipleWaitTime wraps around the clock. The fix is to work with durations instead of times.
if ( millis() - startMultipleTimeStamp > startMultipleWaitTime)
See https://www.norwegiancreations.com/2018/10/arduino-tutorial-avoiding-the-overflow-issue-when-using-millis-and-micros/
I will create a PR but it may be a few days before I can do that.
Hi! I am successfully using your lib with an ADS1231, but I can't get getSingleConversionRaw() to work, it seems it is missing in the cpp file...? Regards and Thanks!!!
I use the code on my ESP8266 and the tare command doesn't finish, if no Hardware is connected. This results in unwanted watchdog-Resets.
For me the hardware should be optional and recurrent reset is not an option.
My changes:
void HX711_ADC::tare()
{
uint8_t rdy = 0;
doTare = 1;
tareTimes = 0;
int okcounter = 200;
while(rdy != 2) {
rdy = update();
if (okcounter-- == 0){
// Prevents from endless loop and watchdog-firing, if no HX711 is connected
break;
}
}
}
more a FYI.
It seems that ESP32 needs the 1s sck_delay. Maybe you could add this to Readme
Previously i used Version 1.0.2 or 1.1.0 and updated now to 1.1.6 . With the new Version and no delay the values went like this: From 0 to around 50 fine , and after that than suddenly jumped to around -33500 and stayed there in the 5 digits, slightly decreasing with increasing force.
With the delay everything seems to be back to normal.
Hi! First of all, thanks for this wonderful library! I have a question: there is getTareOffset() but no setTareOffset(): that would remove the need to tare the scale which is useful for permanent scale projects. Will you add such a function in the future? Best regards, jpk73
hi, i have an issue with my sketch.
when i'm measuring an item and i remove it, the weight value not return to 0 . i would like to know if it is possible to recall a void or a function that reset the weight value or return to tare value propertly, so i can assign this function to a phisic button.
like the tare button on a kitchen scale for example.
thanks for now...waiting news. regards
Hi,
I'm building a scale, with load cells, HX711 as a signal amplifier and Esp 32 as a microcontroller.
I chose Esp 32 because with sleep mode I can save much energy and therefore feed the system with a photovoltaic panel and a small lead-acid battery (the scale is in a remote site).
The problem I would like to solve concerns the tare of the scale: I have to use the system continuously "sleeping down" (and "wakeing up") the controller every hour ... As you can imagine the system performs the tare at each wakeup so that already at the second weighing the object to be weighed is included in the tare and the weight shown on the display is zero.
Has anyone found themselves having to solve a similar problem?
Thank you for the answer...
Hi,
Is there any way to disable the smoothing ?
I need no settling time and also the 80 sps for my project because it is in real time and the measurement increases very quickly.
Regards,
Yves
I am trying to use a 20mhz external oscillator with hx711 and according to its datasheet it is in spec.
When using 20mhz crystal, Reading data doesn't work and it only shows 0 and some high number when a force is applied.
I can read data with a quick test sketch I've made (didn't use the library) to check if all is working, so connections are right and oscillator is working.
Hi Olav,
Is the HX711 really able to provide 80 sps ?
I soldered the two pins on the back of the board together.
I wrote a code with an interrupt on the DOUT pin and another code using micros() function.
I get the same value several times so it creates a curve with aliasing.
I also tried the code you wrote in the issue #25.
I get a curve without aliasing but with much less SPS.
Regards,
Yves
I love this library, thank you for creating it. It worked well first time. My application will be to have an esp-01 on deep sleep and to wake up once per day to take a reading. If I start the the sample code with a mass on the sensor, then it tares it as zero and removing it takes the value negative. Is it possible to start the loadcell without a tare, using my setCalFactor to calibrate the gauge and give me the actual mass on the sensor at start up? I guess I'm asking if tare can be disabled on initiating the sensor?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.