Coder Social home page Coder Social logo

hx711's Introduction

HX711

An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for reading load cells / weight scales.

It supports the architectures atmelavr, espressif8266, espressif32, atmelsam, teensy and ststm32 by corresponding PlatformIO targets.

Synopsis

Blocking mode

The library is usually used in blocking mode, i.e. it will wait for the hardware becoming available before returning a reading.

#include "HX711.h"
HX711 loadcell;

// 1. HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;

// 2. Adjustment settings
const long LOADCELL_OFFSET = 50682624;
const long LOADCELL_DIVIDER = 5895655;

// 3. Initialize library
loadcell.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
loadcell.set_scale(LOADCELL_DIVIDER);
loadcell.set_offset(LOADCELL_OFFSET);

// 4. Acquire reading
Serial.print("Weight: ");
Serial.println(loadcell.get_units(10), 2);

Non-blocking mode

It is also possible to define a maximum timeout to wait for the hardware to be initialized. This won't send the program into a spinlock when the scale is disconnected and will probably also account for hardware failures.

// 4. Acquire reading without blocking
if (loadcell.wait_ready_timeout(1000)) {
    long reading = loadcell.get_units(10);
    Serial.print("Weight: ");
    Serial.println(reading, 2);
} else {
    Serial.println("HX711 not found.");
}

FAQ

https://github.com/bogde/HX711/blob/master/doc/faq.md

More examples

See examples directory in this repository.

HAL support

Hardware support

The library has been tested successfully on the following hardware.

  • ATmega328: Arduino Uno
  • ESP8266: WeMos D1 mini, Adafruit HUZZAH
  • ESP32: ESP32 DEVKIT V1, Heltec WiFi Kit 32, Adafruit Feather HUZZAH32
  • STM32 F1 (Cortex-M3): STM32F103C8T6 STM32 Blue Pill Board
  • nRF52: Adafruit Feather nRF52840 Express

Thanks, @bogde and @ClemensGruber!

Features

  1. It provides a tare() function, which "resets" the scale to 0. Many other implementations calculate the tare weight when the ADC is initialized only. I needed a way to be able to set the tare weight at any time. Use case: Place an empty container on the scale, call tare() to reset the readings to 0, fill the container and get the weight of the content.

  2. It provides a power_down() function, to put the ADC into a low power mode. According to the datasheet,

    When PD_SCK pin changes from low to high and stays at high for longer than 60μs, HX711 enters power down mode.

    Use case: Battery-powered scales. Accordingly, there is a power_up() function to get the chip out of the low power mode.

  3. It has a set_gain(byte gain) function that allows you to set the gain factor and select the channel. According to the datasheet,

    Channel A can be programmed with a gain of 128 or 64, corresponding to a full-scale differential input voltage of ±20mV or ±40mV respectively, when a 5V supply is connected to AVDD analog power supply pin. Channel B has a fixed gain of 32.

    The same function is used to select the channel A or channel B, by passing 128 or 64 for channel A, or 32 for channel B as the parameter. The default value is 128, which means "channel A with a gain factor of 128", so one can simply call set_gain().

    This function is also called from the initializer method begin().

  4. The get_value() and get_units() functions can receive an extra parameter "times", and they will return the average of multiple readings instead of a single reading.

How to calibrate your load cell

  1. Call set_scale() with no parameter.
  2. Call tare() with no parameter.
  3. Place a known weight on the scale and call get_units(10).
  4. Divide the result in step 3 to your known weight. You should get about the parameter you need to pass to set_scale().
  5. Adjust the parameter in step 4 until you get an accurate reading.

Build

All architectures

This will spawn a Python virtualenv in the current directory, install platformio into it and then execute platformio run, effectively building for all environments defined in platformio.ini.

make build-all

Result

Environment feather_328                 [SUCCESS]
Environment atmega_2560	                [SUCCESS]
Environment huzzah                      [SUCCESS]
Environment lopy4                       [SUCCESS]
Environment teensy31                    [SUCCESS]
Environment teensy36                    [SUCCESS]
Environment feather_m0                  [SUCCESS]
Environment arduino_due                 [SUCCESS]
Environment feather_m4                  [SUCCESS]
Environment bluepill   	                [SUCCESS]
Environment adafruit_feather_nrf52840   [SUCCESS]

Details

https://gist.github.com/amotl/5ed6b3eb1fcd2bc78552b218b426f6aa

Specific architecture

You can run a build for a specific architecture by specifying the appropriate platform label on the command line.

# Build for LoPy4
make build-env environment=lopy4

# Build for Feather M0
make build-env environment=feather_m0

Deprecation warning

This library received some spring-cleaning in February 2019 (#123), removing the pin definition within the constructor completely, as this was not timing safe. (#29) Please use the new initialization flavor as outlined in the example above.

Credits

Thanks to Weihong Guan who started the first version of this library in 2012 already (see [arduino|module]Hx711 electronic scale kit, sources), Bogdan Necula who took over in 2014 and last but not least all others who contributed to this library over the course of the last years, see also CONTRIBUTORS.rst in this repository.

See also

Similar libraries

There are other libraries around, enjoy:


Appendix

Considerations about real world effects caused by physics

You should consider getting into the details of strain-gauge load cell sensors when expecting reasonable results. The range of topics is from sufficient and stable power supply, using the proper excitation voltage to the Seebeck effect and temperature compensation.

See also:

hx711's People

Contributors

amotl avatar bogde avatar deamiter avatar dhmsjs avatar el3ctrician avatar epatel avatar gavingc avatar gulaschcowboy avatar hamidsaffari avatar lemio avatar r-a-i avatar simonas0 avatar siruli avatar zfields avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hx711's Issues

Can't use library due to yield calls on Arduino

I tried using your library as is but it seems like yield() is not a standard call in the Arduino IDE. Trying to google it has lead me to install a wrong Scheduling library and couldn't find a right one either. In the end I had to remove the two calls before installing it.

Calibration issues - erratic values from demo sketch

Hello,

I've set up my load cells and tried the calibration process and HX711SerialBegin code but am having trouble.

I am using the Arduino IDE (1.8.0) on Windows 7 with an Arduino Uno. I have 4 load cells wired together into a Sparkfun Load Cell Combinator and then into a red (not Sparkfun) HX711.

Here are links to the components:
Load cells - http://www.ebay.com/itm/261432803492
HX711 - http://www.ebay.com/itm/181357821017
Combinator - https://www.amazon.co.uk/dp/B01LXUNNPL/ref=pe_1909131_77697121_tnp_email_TE_AMZLdp_3

When I run the raw (no changes) HX711SerialBegin code from the library the Serial Monitor prints out very steady values around 0 - but these figures don't seem to change when I add weight to the sensor (see serial readout below).

withoutcalibration2280f

I then ran some code as per the calibration instructions which seems quite variable in what value it gives me, generally resulting in a value between -0.5 and 0.5 which seems low.

Calibration Code

#include "HX711.h"

HX711 scale;


void setup() {

  // parameter "gain" is ommited; the default value 128 is used by the library
  // HX711.DOUT  - pin #A1
  // HX711.PD_SCK - pin #A0
  scale.begin(A1, A0);

  
  Serial.begin(38400);
  Serial.println("HX711 Calibration");

  scale.set_scale();
  scale.tare();

  Serial.println("You have 15 secs to place a known weight on the sensor");

  delay(15000);

  Serial.print(scale.get_units(5)/380); // known weight is 380g
 
}

void loop() {
}

Value from calibration code in HX711SerialBegin sketch

scale.set_scale(-0.29);                      // REPLACES 2280.f ...this value is obtained by calibrating the scale with known weights; see the README for details

  scale.tare();				        // reset the scale to 0

This then results in very variable results and fluctuating numbers in the demo sketch.

withcalibration0 29

Any help would be much appreciated! Thank you :)

scale.set_zero()

Realy nice and flexible class. Thanks for sharing this lib.

I don't know classes very well and I've tried to set an calibrated zero point only once as the calibrated known weight point. But with know luck.

Can you give me a hint to include a function like scale.set_scale() but to set the zero point, something like scale.set_zero(xxx)?
Thanks.

Gain explanation

Hello all,

First thanks a lot for your code. I ordered a load cell and i almost managed to make it work.

I have a very newbie and stupid question but i was not able to find the answer.
What exactly is / does gain parameter on xh711? I mean what is difference between 128 and 64 ?

Thank you in advance

Current master does not work

I spend almost a day trying to figure out why I receive random readings. I checked wiring several times, each pair of load cells, etc, until I tried another HX711 library which worked great but does not have a powerdown mode and so on.

I already figured out it's because of pull request #38 (commit 0c444e2 works fine), so probably every issue since that pull request may be related, but I would like to explicitly leave it here until the issue is resolved, so nobody going to spend a lot time in headaches.

(I have to clarify: I tested on on arduino nano and a single atmega328p MCU)

Issues running this Library on "Energia" with a MSP432

Hello Bogde,

I tried out your library on an Arduino just to test it out and it works beautifully. I need to use this on an MSP432 that uses Energia, which claims to be an Arduino based IDE. I'm not sure which parts are incompatible but I'm only getting 0 value readings when I run the code. Do you know if there's anything that I should change in order to make them compatible?

Thanks,

HX711 Read returning different value with same load cell but on different MCU

hi Bogde,
Thank you for your HX711 library code. I used it on HX711 and it worked well.
I tried to used same on another MCU.
I observed that the values returned by Read() on Arduino is significantly different from that on another board (NRF52832) though the HX711 module and the loadcell is the same. Yes, have used 3.3v in both.
Following are the sample values returned by Read() as recorded on each. Please share your opinion on what maybe going wrong. I have also pasted the code of long HX711::read() below. I have modified it to use bit operations than nested for loop to form the 24 bit value. Kindly check.

As recorded on Arduino:

HXvLOG:HX711Read():RetVal 8315205
HXvLOG:HX711Read():RetVal 8315038
HXvLOG:HX711Read():RetVal 8314981
HXvLOG:HX711Read():RetVal 8315190
HXvLOG:HX711Read():RetVal 8315342
HXvLOG:HX711Read():RetVal 8315221
HXvLOG:HX711Read():RetVal 8315107
HXvLOG:HX711Read():RetVal 8314698
HXvLOG:HX711Read():RetVal 8315440
HXvLOG:HX711Read():RetVal 8315588

As recorded on other board(NRF52832)

HXvLOG:HX711Read():RetVal 16746359
HXvLOG:HX711Read():RetVal 16746363
HXvLOG:HX711Read():RetVal 16746310
HXvLOG:HX711Read():RetVal 16746301
HXvLOG:HX711Read():RetVal 16746294
HXvLOG:HX711Read():RetVal 16746298
HXvLOG:HX711Read():RetVal 16746318
HXvLOG:HX711Read():RetVal 16746303
HXvLOG:HX711Read():RetVal 16746311
HXvLOG:HX711Read():RetVal 16746311

Following is the source code -->

long HX711::read() {

byte readVal=0;
long retVal=0;

// wait for the chip to become ready
while (!is_ready())
	{
	}

for (int j = 23; j >= 0; j--) 
{
	digitalWrite(PD_SCK, HIGH);
	readVal=digitalRead(DOUT);
	digitalWrite(PD_SCK, LOW);
			
	retVal |= readVal & 0x01;
	retVal = retVal << (1 && j);

}
for (int i = 0; i < GAIN; i++) 
{
	digitalWrite(PD_SCK,HIGH);
	digitalWrite(PD_SCK,LOW);
}

retVal^=0x800000;

//Serial.print(F("HXvLOG:HX711Read():RetVal %d Diff %d\n",retVal, (retVal-pHX711State->OFFSET)); 		  
Serial.print(F("HXvLOG:HX711Read():RetVal "));
Serial.print(retVal);
Serial.print(F(" Diff "));
Serial.println((retVal-OFFSET));
return retVal;

}

HX711 Drift

Hi,
I'm using an HX711 amplifier with 50Kg 4 load cells, like this:
https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide

My problem is that the reads is drifting, even with no load on scale.

Board: ESP8266 e-12
Power source: MB102 Breadboard Power Supply Module 3.3V 5V For Arduino

I'm using Bogde's Hx711 library (https://github.com/bogde/HX711).
My
screen shot 2016-11-21 at 1 50 51 pm
code is very basic:

void loop() {
if(scale.is_ready()){
Serial.print(",");
Serial.print(scale.read_average());
}else{
Serial.println("scale not ready");
}

delay(1000);
}

And the output is keep drifting up (see attachment).

Any ideas what cause the drift? and how do I fix it?

Thanks!

tare function for two load cells

I am trying to use the library with two load cells connected to one HX711 (channel A and B).
As described in the README I can switch between the different load cells with the set_gain function.

How can I use different set_scale and tare for the different channels?

HX711 Standalone

Hi, wanted to use HX711 24-bit adc standalone to measure voltage range of 2mv - 20mv.
Problem is:

  1. I cannot interpret the adc output count.
  2. What should i do in my code(code below) so that it prints voltages not decimal values.
    Tried with different values of voltages(shared below), and i am totally confused with the readings. I don't know how to convert these values in voltage. What is the logic behind. Please help!
    Readings:
    0mv --- 5219
    1.1mv --- 5095
    2.3mv --- 4981
    2.5mv --- 4960
    2.9mv --- 4918
    5mv --- 4693
    10.6mv --- 4075
    15.1mv --- 3597
    22.7mv --- 2700
    40.7mv --- 562
    5volts --- -8388608
    -5volts --- -8388607
    Board is arduino leonardo, and a simple voltage divider is used for voltage generation(for testing only). The voltages are measured and calculated from multimeter and hand calculations. I need HX711 do this for me. What is the differential ADC count and voltage relationship...?
    A bogde/HX711 library is used: https://github.com/bogde/HX711
    Code:

include "HX711.h"

define DOUT 3

define CLK 2

HX711 scale(DOUT, CLK);
void setup() {
Serial.begin(115200);
}
void loop() {
long avg = scale.get_value(60);
Serial.print("Digital Code = ");
Serial.println(avg);
}

last known weight lost on reset

Wither this is a major issue, or I am missing something here. Here is a simple code -

#include "HX711.h"
// HX711.DOUT   - pin #A0
// HX711.PD_SCK - pin #A1
HX711 scale(A0, A1);        // parameter "gain" is ommited; the default value 128 is used by the library

void setup() {
  Serial.begin(9600);
    scale.set_scale(119000);
   scale.tare();
}

void loop() {
  Serial.println(scale.get_units(10));
}

The scale parameter is worked out using the method suggested by you and it works perfect!

The problem is when there is a power/arduino reset and weight is still present on the scale(load cell). The output goes back to 0 and I have to do the following again:

  1. Remove the weight from the load cell
  2. Power reset
  3. Place the weight back on the scale.

Then it shows correct reading again.

Problem is that my weight is 200Kgs and it is not practical to remove weight and reset system each time there is a power failure / reset.

Please suggest code changes. Since this is a commercial application, I am ready to pay for your solution.

Thanks in advance. The library is great!

Calibration goes for a toss on Power reset

I followed the method to calibrate the scale and call tare method in setup and everything works fine. But on power reset, irrespective of weight on the scale, output shows 0, since the setup method runs scale and tare methods again.

Please suggest a workaround. What does the method Tare really do? Is it possible to store its output in EEPROM, etc. ?

Thanks

Arduino compilation error: OFFSET & SCALE initialisation

Hello,

Apologies in advance if this is a noob question and/or an library installing error.

I've installed the library to the Arduino IDE (1.0.5-r2 on Windows 7) and am trying to compile the code in the examples/HX711SerialBegin file.

I keep getting the error ..

In file included from HX711SerialBegin_lmedit.ino:1:
C:....\Arduino\libraries\HX711/HX711.h:16: error: ISO C++ forbids initialization of member 'OFFSET'
C:....\Arduino\libraries\HX711/HX711.h:16: error: making 'OFFSET' static
C:....\Arduino\libraries\HX711/HX711.h:16: error: ISO C++ forbids in-class initialization of non-const static member 'OFFSET'
C:....\Arduino\libraries\HX711/HX711.h:17: error: ISO C++ forbids initialization of member 'SCALE'
C:....\Arduino\libraries\HX711/HX711.h:17: error: making 'SCALE' static
C:....\Arduino\libraries\HX711/HX711.h:17: error: ISO C++ forbids in-class initialization of non-const static member 'SCALE'

I've done some googling and there are some comments suggesting that the variables shouldn't be initialised to a value in the header file but have tried removing these with no luck.

Any help would be much appreciated.

Thanks

Readout Consistently reading 0

Hi,

We're working on a project trying to get the readout using 4 load cell sensors. So we're running the code you provided in the examples folder. However we keep getting a 0V voltage readout. We think it might be due to the readAverage value, but we don't even know how that is computed.

Here is the output we get:
arduino values

Any help will be very much appreciated.

Thank you.

read function is slow

Hello when i use the function get_units() in my code
then the programm slows very down.
i have figured out this is caused by
long HX711::read() {
// wait for the chip to become ready
while (!is_ready()); <<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE

i think it need to be rewritten with attachinterupt or timer?

Read Rate adjustable via sketch?

Using the Sparkfun breakout board and this library is the read data rate adjustable? Looking at the HX711 schematic it looks like the default rate is 10SPS, which seems likely given the rate data gets spit out to the serialprint. Via the library is it possible to change to 80SPS? Yes, there would be more noise, but I'd like to try it to see if the noise is acceptable for my application.

need help measuring milligram weight

is there any function that i can call to get milligram weight, my object is very small and my milligram load cell is connected to a HX711.

Thank you.

Calibration help

Hi Bodge,

thanks for the code! I would like to use just basic features of your code, but I am far too inexperienced to know how to change it. I would like to use it to track the weight of a beehive. This means that the weight will start when I place the scales under the hive at eg 100kg then generally increase (but may decrease) up to ~ 250kg over several weeks.

In that time I would like to use your code to take the total weight twice a day (morning and night) and I will send the weight via GSM.

I am having trouble calibrating - I know I need to change the set_scale figure but I do not now how to get the original reading (which I then divide by the known weight). When you say "call get_units(10)" do I need to enter that line into the sketch code? - or do I use the figure given when running the code in serial monitor from the line?:

Serial.print("\t| average:\t");
Serial.println(scale.get_units(10), 1);

Because my scales will sleep between readings, I think I need to remove your tare function? - I want the scales to show me the current total weight each time the sketch runs/arduino wakes, however as your script auto tares it reads "0" each time I restart the serial if there is already weight on it. Can I just remove the line?:

scale.tare();

Because I will send the date via GSM, I think I will need to assign the weight to a reference, if you have any ideas how to modify your code to let me do this that would be great, otherwise if you had time to help me with my other issues I would really appreciate it. Thanks for your time.

William

Has anyone tried to modifiy this library for a HX712 ?

Hi all,

I would like to try to use the HX712 (i ordered some) which seems to be much better than the HX711 in different points.
I found only a datasheet in chinese, none in english. The AVIA support asking for this later, never answered to my mails...

I suppose the library can be adapted to the few differences between the chips.

Has anyone worked on this ?

Here the link to the chinese datasheet : [http://www.hobos.com.cn/upload/datasheet/HX712.pdf]

Thanks,

Hi bogde

i have old tensile testing machine which has been expired, i thought to make that machine for tensile testing using machine's own load cell and mechanical assembly.
i figured out that i need avia semiconductor 24bit adc, arduino, for calibration of load cell( 0.1 mV / V) and your library same power supply.
i am using your library, and i have been working for last 5,6 days and i have frustrated because of no result.
The issue, i am facing is my load showing unusual behavior when ever i connect load cell and run basic program(yours) it shows continuously fluctuation values with out even little accuracy.
i have tried a lot with different ways (basic program, changed programmed, etc etc)
Kindly help me to solve issue
1

above is status pic

Question - Your HX711 library

Is there an an example on the net somewhere of where you used the HX711 library? Something that shows the hardware and what you built with it?

I am new to both Arduino and github, my aplogies if this is not the correct way to ask a question or contact you.

Thanks,

Jack

Default values for OFFSET and SCALE.

Hi,
I suggest to add a default values for OFFSET (as 0), and for SCALE (as 1), to be able to use .get_units() without first setting them in code.

using channel A + B together?

Would it be possible to get data from the both channels together? If I understand your class right at the moment it's only possible to use only one channel.
Probably the set_gain has to change during reading the adw and that the readings has to be devided to reading from A and B.
Do you have an idea how to change the class the both channels can be read?
Can you explain the context of "pulse the clock pin 24 times to read the data"? Is there a reason to read 24 times?

HX711 RETURN CODE CONTINUED

Don't want to let go. Your library is terrific. Again, we will pay a professional rate for your work. Basically, we just want the sketch to continue even if a scale fails. Currently, the sketch freezes.

If you don't want to continue then, please point us in the right direction for either making modifications ourselves (probably not in our capability) or hiring programming and Is our request feasible?

Ben Becker

Include begin procedure and change object constructor code

From what I understand the moment a global HX711 object is created can not be controlled by the programmer. As a consequence that object might be created before the control of the pins is available. I understand that that is the reason for a lot a libraries to include a "begin" routine like Serial,begin

Because the begin will be execute after the pin control is available that is the correct moment to set any pins is need. I therefore propose to change
HX711::HX711(byte dout, byte pd_sck, byte gain) {
PD_SCK = pd_sck;
DOUT = dout;
pinMode(PD_SCK, OUTPUT);
pinMode(DOUT, INPUT);
set_gain(gain);
}
`

into
HX711::HX711(byte dout, byte pd_sck) { PD_SCK = pd_sck; DOUT = dout; }

and include a new procedure begin like:
HX711::begin(byte gain) { pinMode(PD_SCK, OUTPUT); pinMode(DOUT, INPUT); set_gain(gain); }

Problem with this proposal is that it will break old code! so maybe not replace the new constructor routine such that those calling the constructor without the gain parameter will get the new constructor

scale.get_max

Very handy library. It works well with lcd.print and I've tried modifying my sketch to achieve my desired goal, but I'm not a code guy so what I'm asking may not be possible. Would it be difficult to add this to your library? It would be nice to apply a force to the load cell and watch the numbers climb, stopping at the highest force applied. This would be useful for a load force tester.

Many Thanks,
Chuck

it is work,but can not reboot

Your code works well, but there is a problem with all HX711 connected to espduino(like nodemcu), esprduino can not reboot and boot, do you encounter this problem?
Thanks

Cooperation with accelstepper lib

Hi, I use the lib with the HX711 as previous amplifier TM7709 could not be obtained anymore.
In my curent project I use a steppermotor and the accelstepper lib.
Both libs work seperate without problem.
But when I put in the void loop a simple line like
ForceValueTemp = (scale.read()/100);
It blocks the stepper code and reduce the stepper speed to a single tick per second or so.
It looks like the reading of the sensor bloakcs but could not find code in the .h or .cpp that might be the cause.
I need both options together.
Any idea what might be the cause?

Thanks for your time,

Paco

issue reading A0 on display shield if HX711 loaded

Hi,your HX711 library was very helpful to me but currently I am facing a following problem:

I have an arduino uno with a display shield 1602 connected to it. Additionally I have an HX711 A/D connected over display shield pins in a way that A1 is connected to CK/TX and A3 is connected to DO/RX. If I try to read the A0 (meaning the keys on display shield) with analogRead(A0) everything reads ok until I try to initialize the HX711 library (with HX711 scale(A3, A1); line ) once this is added to my code the analogRead(A0) always returns number 7.

The example code that can be used to replicate is like

include <HX711.h>

include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
HX711 scale(A3, A1);

void setup() {
// set up the LCD's number of columns and rows:

lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("LCD Key Shield");
lcd.setCursor(0,1);
lcd.print("Press Key:");
}

void loop() {
int x;
x = analogRead (0);
lcd.setCursor(10,1);
if (x < 60) {
lcd.print ("Right ");
}
else if (x < 200) {
lcd.print ("Up ");
}
else if (x < 400){
lcd.print ("Down ");
}
else if (x < 600){
lcd.print ("Left ");
}
else if (x < 800){
lcd.print ("Select");
}
}

If the line with HX711 scale(A3, A1); is removed then the keys are read correctly. But once I add that line I always get 'Press Key: Right' message on a display (since analogRead(A0) is always 7).
The HX711 library itself works correctly, returns values from loadcell plugged as expected, but the A0 pin is not readable in that case.

Is there any restriction for usage of other analog pins if some of them are used by HX711 lib? Am I doing anything wrong in relation to initializing the library?

Thanks for any help,

         Marek

Removing the weight does not give value zero (or even close).

Thank you very much for the library. it is very useful and easy to use. I am facing an issue.

When I add weight say 1KG, I see it immediately updated (using the example program). But when I remove it, it takes close to 30 seconds to show the reduced weight gradually. In the first sample , it shows the weight reduced to 0.5 KG then to around 300g, and next 100g etc. I don't know where is the problem. Can you please let me know how do I fix the issue. I am using a pressure load cell FX1901(from mouser.com), with HX11

Setting GAIN after each read

After reading the datasheet for the Hx711 [https://cdn.sparkfun.com/datasheets/Sensors/ForceFlex/hx711_english.pdf] it appears that that 25-27 pulses on PD_SCK are required to set the GAIN and INPUT. Looking at the code, it looks like it's looping 1-3 times. Am I missing something?
25 -> A 128
26 -> B 32
27 -> A 64

Library HX711

Hi Good night i have problem with the code that you use when i try to upload the code, the program send me this message sketch_sep07a:6: error: 'Hx711' does not name a type
sketch_sep07a.ino: In function 'void setup()':
sketch_sep07a:11: error: 'scale' was not declared in this scope
sketch_sep07a.ino: In function 'void loop()':
sketch_sep07a:16: error: 'scale' was not declared in this scope
And i already uploaded the library that you put in web page

I hope can you help me with this issue.

Thanks.
Regards

Can't upload to Arduino

I have an existing sketch that successfully uploads to my Arduino Yún over USB.
If however I include this library and add the HX711 scale(A1, A0); line, I can't upload it anymore.

I'll click upload, the status LED will start blinking, then /dev/cu.usbmodem1421 (Arduino Yún) will disappear from my port list and I'll get a Board at /dev/cu.usbmodem1421 is not available error message.

I tried resetting the Arduino and pressing reset right after initiating the upload to no avail. The only way to actually upload and run my sketch is to comment out the HX711 scale(A1, A0); line.

I'm not really sure how to debug this and tell whether software or hardware is to blame. I tried printing something to serial at the very first line of HX711's constructor, but I can't even get this to show up in Serial Monitor.

Compilation Error

in HX711.cpp the header file is referenced as absolute in the arudino library folder.
Changing the angled brackets to double quote brackets fixes this problem.

Increasing results over time

Hi,

Very well job done on library. Made my work very easy. I am building a scale with 350 kg load cell. I sucessfully got everything working. Found float number for the load cell. When I start my arduino project, everything starts just great. I put weight and the programm shows correct numbers. But when I leave item on the scale for some time (e.g. for 4 hours) the numbers start to change. They may increase or decrease over time. Changes are not very crucial, like 200-300 grams. But I am guessing it will change significantly over long time period.

Any help would be appreciated. Thanks in advance.

Modified read_average()

Hi,

Would it make sense to modifiy the read_average() to make a moving average filtering, like this ?

`long HX711::read_average(byte times) { // modified for moving average filtering
long sum = 0;
long min; // lowest value read
long max; // highest value read
long last; // last value read

for (byte i = 0; i < times; i++) {
    last = read();
    if ( i == 0 || last < min ) min = last; // init and set min value
    if ( i == 0 || last > max ) max = last; // init and set max value

    sum += last; // sum of all readings
}
sum = sum - min; // reject the smalest reading
sum = sum - max; // reject the greatest reading

return sum / (times - 2); // calculate average value from leaving values

}`

Limitation is of course that you need to call it with minimum 3 in times ! Could be checked in code...

Not getting real values.

Hi Bogde...
I tried this thing with a load cell which full scale out put is 0.9mV/V(On the label its shows like that). I think that's FSO of 4.5mV. So I'm getting wrong values with your code if I do calibration. do you have an idea to solve this problem?

Calibration code is constantly Reading 0

So I wired up the combinator and amp just like in the breakout board hookup guide on spark fun. One day the system was working and I was able to set the calibration value. But when I tried it the next day the program was not working and since then all I get is a constant zero value. I've resautered connections but still nothing...any ideas on what could have happened? Here is the code I'm using:

include "HX711.h"

define DOUT 2

define CLK 3

HX711 scale(DOUT, CLK);

float calibration_factor = 7500; //-7050 worked for my 440lb max scale setup

void setup() {
Serial.begin(9600);
Serial.println("HX711 calibration sketch");
Serial.println("Remove all weight from scale");
Serial.println("After readings begin, place known weight on scale");
Serial.println("Press + or a to increase calibration factor");
Serial.println("Press - or z to decrease calibration factor");

scale.set_scale();
scale.tare(); //Reset the scale to 0

long zero_factor = scale.read_average(); //Get a baseline reading
Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
Serial.println(zero_factor);
}

void loop() {

scale.set_scale(calibration_factor); //Adjust to this calibration factor

Serial.print("Reading: ");
Serial.print(scale.get_units(), 1);
Serial.print(" lbs"); //Change this to kg and re-adjust the calibration factor if you follow SI units like a sane person
Serial.print(" calibration_factor: ");
Serial.print(calibration_factor);
Serial.println();

if(Serial.available())
{
char temp = Serial.read();
if(temp == '+' || temp == 'a')
calibration_factor += 10;
else if(temp == '-' || temp == 'z')
calibration_factor -= 10;
}
}

HX711 Return Code

Using your HX711 library with great success; Thank you.

Problem: Monitoring many scales. My sketch freezes if no scale is attached to the specified pins.

ex... HX711 scale(8, 9); If the scale using pins 8 and 9 was disconnected the sketch freezes.

I need the sketch to unconditionally continue and issue a return code so I know if the operation succeeded or failed.

We would certainly pay for your efforts.

Ben Becker
New Era Optical Company
Chicago, Il.
773-427-2252
[email protected]

Incorrect result with Two loadcells

Hi every one
When i connect two loadcells via junction box to hx711 A input i got some values that changes not in linear form.it means that when the load is more than a special value , hx711 sends lower values instead of higher ones.
Can every one help me?

using channel A + B together? version 2

Hi,

Although you already had this question before your answer was not clear to me and I am still wondering if reading reading A and B channel can be done.
Your prevoius answer put some dust around it (although I understadn it can be done) and gave more questions then answers.
I try to understand your thinking but I can not, so are may others but they do not ask again or do not want to share the SOLUTION :-)

If I understand correct this code should work using your lib which I made more simple to understand what is going on in reading the raw values.

include "HX711.h"

// HX711.DOUT - pin #A1
// HX711.PD_SCK - pin #A0
HX711 scale(A1, A0);// parameter "gain" is ommited; the default value 128 is used by the library

void setup()
{
Serial.begin(9600);
}
void loop()
{
//set the gain factor; takes effect only after a call to read()
(scale.read()); // print a raw reading
set_gain(32); //set gain and channel
Serial.println(scale.read()); // print a raw reading from the ADC channel B to display
(scale.read()); // print a raw reading
set_gain(64); //set gain and channel
Serial.println(scale.read()); // print a raw reading from the ADC channel A to display

}

Although this is what I think you tried to explain it is not working.
i get an error on set_gain(32) to start with.
I know manual says the 26 pulses to get B 32 and 27 pulses to get A 64 but does the lib support the 27 pulses to be read and convert to a raw value or only the A 128?

Your help would be highly appriciated.

Paco

Precision Question

For my project I am using your library along with SparkFun's Load cell amplifier.
I pulled a load cell from a small pocket scale that has a max load capacity of 100 Grams and could give readings out to three decimal places. One of the objects I am weighing in my testing is 6.385 Grams.

Using the SparkFun sample software I was able to calibrate and take readings from the load cell. The only problem is that the readings are only out to one decimal place. The sample object I am weighing is showing as 6.3 grams.

Is there a way for me to enable your library to provide a more precise reading?

Turnigy Thrust Stand

Good day!

I'm reading this thrust stand (http://www.hobbyking.com/hobbyking/store/__66623__Turnigy_Thrust_Stand.html) Its connected to an Arduino pro (as instructions from sparkfun HX711 site), and I'm getting some data, so, I proceed to do the calibration, I'm uploading this code to calibrate:

  scale.set_scale();                 
  scale.tare(); 
  delay(5000); // just to have time to put the weight on it...
  Serial.println(scale.get_units(10));

And I'm getting a number like -754935.00, my weight is 200 grams, so, I divide by that, and then I upload a code similar to this:

void setup() {
  Serial.begin(115200);
  scale.set_scale(-3774.675); //   -754935.00/200               
  scale.tare(); 
}

void loop() {
  Serial.print("one reading:\t");
  Serial.println(scale.get_units(), 1);
  delay(1000);
}

And I'm getting this results with no weight:

one reading:    222.2
one reading:    222.2
one reading:    222.2
one reading:    222.2
one reading:    222.2

And this when I put my 200 grams weight:

one reading:    200.1
one reading:    200.1
one reading:    200.1
one reading:    200.0
one reading:    200.0

And this when I put my 500 grams weight:

one reading:    188.3
one reading:    166.3
one reading:    166.6
one reading:    166.6
one reading:    166.6
one reading:    166.6

What am I doing wrong? Any help??

thanks a lot!

Values "rolling over"?

Very nice library! I just purchased a Futek LSM400 for use at work and purchased an HX711 pre-wired breakout board to read it with an Arduino. The datasheet for the load cell specifies an excitation voltage up to 18V:

I saw the specification to connect the HX711 to 5V on this site and at SparkFun's hookup guide, but thought that was for convenience (since one has 5V available from the Arduino).

My primary question with the library is that my load cell has a range of 5lbs, and I was simply stacking some plastic wheels on it from an erector set I had handy (couldn't have been more than a few hundred grams). My values started around -29k, went past zero up to +30k but then would "roll over" back to negative. What might be the symptom of this? I tried setting the scaling to 64 and 32 but got similar results with 64 and pretty much no change with 32 (values hung around 2k no matter what I did).

Unfortunately, I thought I was perhaps not giving my load cell a high enough excitation voltage so I connected a 12V power supply to the HX711 (12V+ to VCC and the - terminal to both the HX711 and Arduino GND to make them common). I got nothing in the serial monitor, and now I can't seem to get any readings from the HX711 anymore :( I'm wondering if I fried it.

In any case, my primary question is on the rollover values. My load cell is 1000k nominal resistance and 2mV/V output. The HX711 should be compatible with this, right?

If you happen to know if it's not voltage protected and could easily tell me if it's likely fried, that would be appreciated too as I'll order another.

Thanks!

Arduino, hx711,

Thanks for sharing your time and software.

I am using a 100/150kg load cell and a green hx711 ADC purchased from Aliexpress.
I have made my own scales using the above load cell (want to measure bee hive weight) and have hooked all the various components and attached my Arduino (Freetronics Eleven) to my Mac Air.

I am a new noob but have played with the Arduino and understand how to use and set it up.

My problem is that when I run the hx711 code my readings are 2 decimals places out. ie If I place 8kg weight on the scale (after waiting a minute to see a reading of 0g) and then place my weight on the scale I get 82.0g (expected 8200g) or if I place a 2kg weight I get 21.1g (expected something like 2000g).

I am running the code as is, using channel A on the hx711 but at a loss as to what I am doing wrong?
Looks like an issue with voltage or reference resistance. Tried 2 different hx711 units.

Can some shed some light? Thanks again.

Strange behavior for arduino newbie

I tried to run your calibration code with my load cell + hx711 + arduino uno setup. In the serial monitor, this is what was displayed:

4������( )�)�!!��41����%)� ��%(���4!� ���)%4����B��1��%!�0���-�!!��

Any idea where the problem might be? Thanks!

Calculating the proper SCALE value

I sat down and worked out the math for actually calculating what the SCALE correction should be for a given system. Someone else can go over and check this if they want, I solved it in the formulaic form and verified it by calculating with real values and checking the results.

scale = (output * gain * adc_range * excitation)/(cell_range * vcc)

where:
output = the output rating of the load cell (mV/V). Should be in volts, if your final result looks wrong see if it is off by some factor of 10 to see if you forgot to account for the unit changes.
gain = the gain setting of the amplifier
adc_range = the range of values that the adc has (precision). For this 24 bit adc this is (2^24)-1= 16777215
excitation = the input voltage for the load cell. For Sparkfun's breakout board this is equal to vcc and the two values cancel out.
cell_range = the max rating for the load cell in whichever units you are using. I was using a load cell rated for 50KG, so to get an output in kilograms I would use the value 50 here.
vcc = the system voltage for the amplifier

I was able to get good readings on my load cell using this formula without having to guess and check.

2's-complement error?

HX711.cpp, read(), line 67:
} else if ((0x7F == data[2]) && (0xFF == data[1]) && (0xFF == data[0])) {
filler = 0xFF;
}

Let's assume we read a value of 0x800000 (min value per datasheet, i.e. -2^23 = -8388608). The idea is to invert this as HX711 presents inverted values (I assume this is the reason the inversion is performed?). It thus becomes 0x7FFFFF, and the filler is set to 0xFF per the above code snippet. It is then joined to form 0xFF7FFFFF and +1 is added, we get 0xFF800000 = -(2^32-2^23) = -4286578688. Oops, not the 8388608 we wanted.

Just skipping the above else-if would yield the correct value:
0x800000 -NOT-> 0x7FFFFF -extend-> 0x007FFFFF -plus1-> 0x00800000

I think the confusion was that +8388608 cannot be represented in a 24-bit 2's-complement format, but as it is extended to 32 bits, it should not present any problem :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.