10 Replies Latest reply on Oct 24, 2016 3:05 PM by Horsten

    Hx711 Read Errors


      I have been using the Hx711 to read a 1000lb. load cell using an Arduino Uno. I am working on adding this to a current project using my Edison with Arduino breakout. I have been trying to use the C++ example code from the UPM GitHub and It compiles and runs fine but the sensor has not been working properly. I have calibrated the sensor to be very close to 0 with no weight but as soon as I try to weigh anything more than 2lb the sensor appears to max out and returns a value of about 63,000 with my calibration factor or with no calibration factor it returns a value above 4 million. The sensor is in fine condition and works perfectly with an Arduino Uno but I can figure out why is going wrong with the Edison. Any advice of where to go from here would be much appreciated.


      This is the code I have been using: upm/hx711.cxx at master · intel-iot-devkit/upm · GitHub 



        • 1. Re: Hx711 Read Errors

          Hi Alex,


          I had similar issues with interfacing the Edison and the Hx711.

          I did not use the upm lib (as it was stated, it was only tested on the Galileo board), but wrote my own interface with bit-banging. It helped to see the internal behavior anyway.

          The datasheet of the HX711 explains, if the clock is held high for over 60us the chip will go down to standby mode. I checked the communication between the Edison and the HX711, only to find clock pulses, eventually as long as 150us. Linux is not a real-time kernel, so I expected some fluctuation, but not this lot. Whenever it occured, it sent the chip to sleep.


          Another problem I met: According to the spec sheet the HX711 holds the data line high as long as it is not ready with the conversion. If this condition is not checked, and one tries to read it within this period, it will prolong the busy state, providing numerous all-bits-high readings. It looks like your case, but as a matter of fact, I found the chip could climb out from this state sooner or later.

          Could you check the lines with an oscilloscope?

          Finally, to procced with my project, I had to give in, and use an AVR microcontroller to interface the HX711 and the Edison - in my application it is tolerable anyway. Still, it would be interesting to see if anybody has ever had success in Edison and HX711.



          2 of 2 people found this helpful
          • 2. Re: Hx711 Read Errors

            Hello Alex,


            If you are using the Arduino IDE I could give you the code to run the HX711 without any libaries.

            It is very simple.

            In native C/C++ it's a little bit tricky as you don't have the command bitWrite().


            PS: The 16-bit resolution of the HX711 is good. The 24-bit resolution produces too much noise.

            • 3. Re: Hx711 Read Errors

              To read the SparkFun HX711 breakout board you really don't need a library.


              Your To Do List is:

              1     Write a few lines of code to read the HX711

              2     Determine the offset value in units

              3     Determine the full scale value in units

              4     Calculate the units to load ratio

              5     Integrate the offset value and the units to load ratio in your code

              6     Ready


              Too 1:

              Do you need 24 bit resolution really?

              My experience is: The least 8 bit are noise only.

              Here a bit code for the Arduino IDE.


              int my_reading;                    // signed 16 bit integer !!


              while (digitalRead(data_pin) == 1)          // Do nothing while the HX711 has no new data



              for (int iteration = 15; iteration >= 0; iteration --)          // Start reading, most significant byte first

                { digitalWrite(clock_pin, HIGH);

                  digitalWrite(clock_pin, LOW);      

                  bitWrite(my_reading, iteration, digitalRead(data_pin)); }   


              // Now you have your 16 bit


              // "Pulse" the next 8 bit out and one additional pulse to program the HX711 with a gain of 128


              for (byte iteration = 1; iteration <= 9; iteration ++)

                { digitalWrite(clock_pin, HIGH);

                  digitalWrite(clock_pin, LOW); }


              Too 2:

              Read the offset units without any load e.g. -521


              Too 3:

              Read the full scale units with maximal load for your load cell e.g. 13,268 with 10,000 g


              Too 4:

              Your units to load ratio is:

              (13,268 - (-521)) / 10,000 = 1.38 units / g


              Too 5:

              Your final reading calculating code:

              (my_reading - offset) / units to load ratio


              Too 6:


              You are ready.



              2 of 2 people found this helpful
              • 4. Re: Hx711 Read Errors

                Hi Horsten,


                Thanks for the advice, I am trying to add this to a project using native C++ so I was hoping to not use the adriano IDE but this will give me a starting place to try and convert to C++. I'm thinking of dropping the Hx711 and setting up an InAmp to just use the built in ADC with the Edison Arduino board. Im not looking for very high precision so I might be able to get by with the built in ADC.


                Thanks for your advise.

                1 of 1 people found this helpful
                • 5. Re: Hx711 Read Errors

                  Hi Alex,


                  I think HX711 is a precise device, for a very affordable price. With all the different breakout boards on market, it is easy-to-use too. It is only unfortunate, that timing is so tight.

                  But if I were you, I surely did not bother with building an amplifier. You will need a rather good one to get any reasonable output.

                  It is a lot easier to use an Atmel ATtiny (e.g ATtiny 20), which is a super cheap, super simple chip to interface it with the Edison on e.g I2C. Edison has drivers to I2C, if C++ is not your piece of cake, use python.

                  ATtiny AFAIK can be programmed with Arduino boards, but then some C++ is inavoidable.

                  One possible way to write this side of the program:


                  Reader function (Too 1 in Horsten's code ):

                  provides 24 pulses to read the HX711,

                  the data is being read bit-by-bit, then shift into a variable (int),

                  the result is stored in an output variable (int).

                  The reader can be activated by a periodic timer, but if you want it simpler than that, execute a read at I2C requests.


                  I2C function:

                  whenever a request comes from the master, it sends the content of the output variable back to it.


                  On the Edison side you can do Too2...5 in either python or C++.


                  I said, I would do this - in fact I did it with a different AVR, which reads 8 HX711's in parallel. If you choose this way. I can give you some help.



                  1 of 1 people found this helpful
                  • 6. Re: Hx711 Read Errors
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Hi terp41,


                    First I want to thank if and Horsten for their detail information regarding the Hx711. We will like to know if you were able to try any of the suggestions recommended in this thread. Please let us know in order to help you.


                    I will be waiting for your reply have a nice day.



                    • 7. Re: Hx711 Read Errors

                      I decided to drop the use of the Hx711 because the project I am working on is in native C++ and the hassle of trying to change Horsten's Arduino code into something in native C++.

                      I went with a INA126 and I'm using the 10 bit ADC from the Edison breakout board which I got working in under a half hour. This is giving me high enough resolution for my application but would not be great for precise applications.

                      • 8. Re: Hx711 Read Errors

                        Hi Alex,

                        Good to hear you've made it.



                        • 9. Re: Hx711 Read Errors
                          Intel Corporation
                          This message was posted on behalf of Intel Corporation

                          Hi terp41,


                          I’m glad to hear that you manage to connect an ADC to your Edison, if you have any more technical questions please don't hesitate to ask. Again thanks to if and Horsten for their contributions to this thread.


                          Have a nice day.



                          • 10. Re: Hx711 Read Errors

                            Dear Alex,


                            I guess that you should think over your last decision regarding the HX711.

                            Please see the code below.


                            #include "mraa.h"

                            #include <stdio.h>

                            #include <stdlib.h>



                            int main()

                            { mraa_gpio_context clock_pin = mraa_gpio_init(47);

                              mraa_gpio_dir(clock_pin, 3);                                              //Set the line to output and initially low

                              mraa_gpio_context data_pin = mraa_gpio_init(48);

                              mraa_gpio_dir(data_pin, 1);                                              //Set the line to input



                              int sample;

                              for (sample = 1; sample <= 1000; sample ++)

                              { int16_t my_reading = 0;                                                   //Signed 16 bit integer!! Initially set to zero!!



                              while (mraa_gpio_read(data_pin))                                    //Do nothing while HX711 has no new data




                              int iteration;                                                                       //Start reading, most significant byte first

                              for (iteration = 15; iteration >= 0; iteration --)

                              { mraa_gpio_write(clock_pin, 1);

                              mraa_gpio_write(clock_pin, 0);

                              if (mraa_gpio_read(data_pin))                                         //Equivalent to the command bitWrite()

                              { my_reading |= 1 << iteration; } }                                    //Only to write the ones necessary



                              // "Pulse" the next 8 bit out and one additional pulse to program the HX711 with a gain of 128



                              for (iteration = 1; iteration <= 9; iteration ++)

                              { mraa_gpio_write(clock_pin, 1);

                              mraa_gpio_write(clock_pin, 0); }



                              printf("Sample number: %4d \t Reading value: %6d \n", sample, my_reading); }



                              return MRAA_SUCCESS; }