tatobari / hx711py Goto Github PK
View Code? Open in Web Editor NEWHX711 Python Library for Raspberry Pi.
License: Apache License 2.0
HX711 Python Library for Raspberry Pi.
License: Apache License 2.0
I'm working with a 3kg load cell and when I run example.py
with hx.set_reference_unit(1)
it outputs:
55372
55334
55426
55433
55350
55411
55342
55459
55441
55514
55469
55432
55462
55399
adding 2kg to the load cell changes the output to:
1347015
1347079
1347217
1347085
1347154
1347143
1347165
1347071
1347179
1347080
1347089
1347133
1347182
1346994
1347174
1347168
1347150
1347136
1347186
1347048
1347081
1347139
1347240
i used hx.set_reference_unit(673)
since 1347126 / 2000 = 673
but the output does not change after running
please help :(
Hello everybody, I've broken my head for days
I have a Pi3 with HX711
Meanwhile, I've got the balance as a service and loads the values sent via UDP.
Now I have only one problem the balance reset after each restart and that must not be.
Bottles are measured by weight. These bottles can not be taken off the balance every time the machine is restarted but must remain permanently on it.
#!/usr/bin/env python
import time
import sys
import os
import socket
from hx711 import HX711
def cleanAndExit():
client.disconnect();
print "Cleaning..."
GPIO.cleanup()
print "Bye!"
sys.exit()
hx = HX711(27, 17)
hx.set_reading_format("LSB",)
hx.set_reference_unit(92)
hx.reset()
hx.tare()
UDP_IP = "192.168.210.113"
UDP_PORT = 1234
while True:
try:
val = hx.get_weight(5)
print val
val2 = str(val)
MESSAGE = "GewichtGas="+ val2
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
hx.power_down()
hx.power_up()
time.sleep(0.5)
except (KeyboardInterrupt, SystemExit):
cleanAndExit()
I'm trying to troubleshoot my sporadic spiking +/- values. Using example.py's debugging with MSB and LSB, uncommenting the hx.get_np_arr8_string() causes an error that this is not an attribute of hx. Do I need numpy installed to use this library?
Thank you,
Toby
I am new to coding and really appreciate you sharing this content. Looking at "example.py"; would it be possible to comment what each of the lines does? For example, trying to understand what "EMULATE_HX711=FALSE" does..
Is it possible to read to 0.1g accuracy? I am using 3 of these load cells: https://www.amazon.com/gp/product/B00R1J9DZ6.
Thanks,
Chris
Hello,
In case of an even number, to get the arithmetic mean of the two middle values, shouldn't it be:
midpoint = len(valueList) // 2
return sum(valueList[midpoint-1:midpoint+1]) / 2.0
instead of:
midpoint = len(valueList) / 2
return sum(valueList[midpoint:midpoint+2]) / 2.0
Line 224 in 14a8e3f
I was just wondering where in the code you can change the GPIO pins you are using. I see that in the initialization of the hx711 class it is setting some settings for GPIO, but I'm not sure those are the pins.
On a related note, would there be any issue with changing the pins to any other numbers? I'm wanting to run multiple load cells out of one Pi and so I was hoping I could do multiple groups like 1,2,3,4 and then 5,6,7,8 for the next one and so on. Would the library still be able to correctly read from these?
First off let me thank you for the great code! Worked fine after my son figured out the schematic was wrong on Amazon. Be careful out there. Attached is correct one.
My son is using this to monitor weight placed on a structure that sends an MQTT message when weight reaches over X amount. He used 4 50Kg load cells and some rubber crush pads to get upto 500lbs.
Hello,
I am fairly new at this and this HX711 code has worked best for me so far. However, is there a place that i can change the resolution? for some reason my output is only in integers, it doesnt show decimals in any amount of places (looking for atleast 2 decimal places).
Thanks
So is this the latest library to your knowledge? Or is it better to use the one in the readme?
https://gist.github.com/iilxy/f8b95cd039759b18edcdfe60684a6b8f
ello Tato,
thanks for providing your code and explanation,
but I’m still struggling with a few things.
First: Can you please explain how to evaluate the tare value and the value for the defined (1kg)
Second: Maybe depended on above
With changing the Vcc to 3,3 V the results get better, but still a very inconstant.
My scale consists out of 4 Load Cells which are linked as Wheatstone Bridge.
(tare & 1kg as in our example)
e.g.
Empty scale:
pi@raspberrypi:/scale/hx711 $ python hx.py/scale/hx711 $ python hx.py ## with 1kg
0.000
1.076
-0.043
4.500
-0.033
0.000
-0.033
0.000
0.022
-0.022
-0.033
0.022
-0.011
-0.011
-0.022
^CCleaning...
Bye!
pi@raspberrypi:
0.000
0.043
0.043
0.033
18.261
0.011
0.196
0.022
0.087
0.087
0.000
0.011
^CCleaning...
Bye!
pi@raspberrypi:~/scale/hx711 $ python hx.py ##wtih 5kg
0.000
0.022
0.033
0.033
0.076
0.043
0.043
0.065
-0.011
0.022
0.033
^CCleaning...
Bye!
pi@raspberrypi:~/scale/hx711 $
Any idea or advice?
Thanks
u-l-m-i
My Hx711 and Load Cell works fine with Arduino Uno (giving outputs with +-4 grams of fluctuations ).
But when I run example.py on my Rpi with following connection:
DT>>5
SCK>>6
VCC>>5V
GND>>GND(RPi 3B+)
I'm getting random values even when nothing placed on load cell.
I get the following result when I run example.py with nothing placed on the Loadcell:
-3939697
-4791665
123791
-1186929
-859249
-4595057
-1252465
-3546225
-7150961
-3808625
-7019889
-4529521
-7478641
-8854897
-4005233
-7609713
-7347569
-9706865
-6888817
-6692209
3859087
-73073
3138191
320143
Plz Help !!!
I'm using python2.7 to run example.py which comes pre installed on Raspbian which is running on my RPi 3B Plus
Hello,
I am in the process of building a weight scale which consists of:
4 load cells connected in a full bridge config as shown in: https://i.stack.imgur.com/9vDyI.jpgHX711Raspberry Pi
I have not been able to find a code to run in my Rs Pi (python or C). Has anyone worked on this or know where I can find the code?
Note1) I am hoping to get the final values in kg or g, and do a little bit calibration for my system at the end.
Note2) I have found a C code which is written for a single bar load cell connected to HX711 - Rs Pi, and tried running it directly. I get 0 values initially without any load and the output does increase with increasing force applied, though the scale is way off (~100g output when I press on the scale hard).
greatly appreciated!
Hi,
I am currently using your library to use some loadcells with a Raspberry Pi 4+.
The values I get are super random so I want to debug the values of MSB en LSB.
According to your code in ' example.py' there should be two functions called 'get_np_arr8_string()' and ' get_binary_string()'. Both functions are not available.
Could you add them in the library?
Hi,
The code works great for a single hx711 connected to one pi.
I am trying to connect multiple load sensors to a single pi and I am just wondering is it possible to do this by changing part of this code?
I have tried creating a new instance like hx711(8,9) where 8 and 9 are the corresponding pins connecting to the hx711 but this does not seem to be working. I am very new to all of this so I could be doing it completely wrong.
Ideally I would like to be able to connect 4+ sensors but even if I could connect 2 simultaneously then that would be great.
Thanks
Hi, I'm trying to combine the signal 4 S-beam 5-wire load cells (E+,E-,S+,S-,Sh) into a junction box (Output: E+,E-,S+,S-,Sh), amplify the data through HX711 and into the RPi. Wiring diagrams are as below. After wiring and running the code, the output data keeps being 0 or 1 and sometimes fluctuates to 1000/2000 and dropped back to 0/1 every time I connect VCC and/or VDD to power (3.3V/5V). However, if I disconnect the VCC and VDD, the output read around -833000... In both cases the output doesn't react to the applied weight onto the load cell.
I wasn't sure what was going on. I'm using BCM mode and GPIO pin 5 for DATA and 6 for CLK. So far, I've tried:
According to the datasheet, the S-beam load cells work with voltage up to 10V but the supplier's tech support said that it should still work with 5V, just with less accuracy and requires more tuning. Can you please help me verify what's going on?
I've an application developed in Python and i'm using hx711.py source code to import the HX711 class, after importing, i'm getting stuck on return GPIO.input(self.DOUT) == 0
. I tried running the example.py code and also had the same error: MYPATH/hx711py/hx711.py", line 51, in is_ready return GPIO.input(self.DOUT) == 0
Is this a hardware error or a software error? I checked HX711 module board VCC and it was receiving 4.85V, that's ok, but I think DOUT is on level HIGH.
I run the code on beaglebone Black and I am getting only zeros @ output, what am I supposed to do!
Hi I plan to run this script on boot and use the printed value in CODESYS.
When I run this script in the Pi Desktop view via remote control on windows or in Putty, everything is fine. But when I auto start this on boot/login, I get random numbers between -800 and + 1200 for exsample after the tare.
While having the start command in the "sudo nano /etc/profile" file to auto start it, I also get the random rumbers in Putty after stoping the script and starting it manuell again.
But when I remove the line in the profile, starting the script manuelly in Putty has nu issue and the numbers are fine.
It looks like the issue when having the referenceUnit = 1. When I changed the referenceUnit to 424, my printed values are pretty accurate. Also I power the the hx711 with 3.3V. I use only one load cell.
Also, when I change the GPIOs, I still get the same error message you see in the screenshot. This message I get also when I start it manually in shell directly on the pi (without Putty). Is this error a/the problem?
What might be the reason?
I am confused on how to attach from the HX711 to the raspberry pi. In the example code the line
hx = HX711(5, 6)
Makes me believe that DAT and CLK are connected to pin 5 and 6 respectfully. But which ones are pin 5 and 6? Because it seems like pin 5 is SCL and 6 is GND which I doubt is correct.
Thanks
Karl
when i exec python3 setup.py install
command,an error has occurred
source/py_gpio.c:87:4: error: function definition is not allowed here
{
^
source/py_gpio.c:143:10: warning: implicit declaration of function 'cleanup_one' is invalid in C99 [-Wimplicit-function-declaration]
cleanup_one();
^
source/py_gpio.c:143:10: warning: this function declaration is not a prototype [-Wstrict-prototypes]
source/py_gpio.c:172:13: warning: implicit declaration of function 'cleanup_one' is invalid in C99 [-Wimplicit-function-declaration]
cleanup_one();
^
source/py_gpio.c:200:24: error: function definition is not allowed here
int setup_one(void) {
^
source/py_gpio.c:293:13: warning: implicit declaration of function 'setup_one' is invalid in C99 [-Wimplicit-function-declaration]
if (!setup_one())
^
source/py_gpio.c:293:13: warning: this function declaration is not a prototype [-Wstrict-prototypes]
source/py_gpio.c:323:12: warning: implicit declaration of function 'setup_one' is invalid in C99 [-Wimplicit-function-declaration]
if (!setup_one())
^
source/py_gpio.c:345:21: error: function definition is not allowed here
int output(void) {
^
source/py_gpio.c:419:18: error: called object type 'PyObject *' (aka 'struct _object *') is not a function or function pointer
if (!output())
~~~~~~^
source/py_gpio.c:475:18: error: called object type 'PyObject *' (aka 'struct _object *') is not a function or function pointer
if (!output())
~~~~~~^
6 warnings and 5 errors generated.
error: Setup script exited with error: command 'gcc' failed with exit status 1
i want to know ,how to solve it?
Hi Tato
Thank you so much for offering to help. I am using Pi 2 Model B. I have connected the Hx711 as follows:
VCC - 3v3
GND - Ground
CLK - GPIO23
DATA - GPIO24
I've only changed line 140 in the code to: hx = HX711(23, 24)
After running it with "sudo python hx711.py" I get the following output
It appears to be very erratic. I have also tried to switch the CLK and DATA pins around and I get the value "18.23" constantly even with the addition of a weight. Thanks again
Regards
Im trying to implement this code with the Raspberry pi 4b, on python3. It is giving random values, I tried switching between MSB/LSB, I tried all combinations of the load cell wires to check if there is a difference between the supported formats of hx711 and the load cell that I have. I am not able to debug from the code because the binary values array function doesnt exist. Can you help me understand what mistakes I might be making.
From the sensor I have taken the red and black to E+ and E-, The green and white as A+ and A-.
Please help me im stuck on this for quite a while I need to figure out a solution for delivery as soon as possible. Any help would be appreciated!
Hello,
Is there a way to make it sample data faster than ~1Hz?
Thanks
Hi mr.tatobari,
forgive my ignorance
I am having trouble on assigning variable to get an initial data using my 20kg Load cell bar
and HX711
I copied one of your lines and made a test run.
I got a message of syntax error. Is the "val" the only variable i can use?
I am trying to get a percentage ratio from the initial weight and the current weight but still do not
have an answer for almost 3weeks.
This here is one of the lines i am using in my RPi3
try:
val = max(0, int(hx.get_weight(5)))
mylcd.lcd_display_string("Load={0:0.1f}g" .format(val),2)
hx.power_down()
hx.power_up()
print(val)
val2 = hx.get_weight(5)
mc = (1 - (val2-val)/val2) * 100
mylcd.lcd_display_string("MC={0:0.1f}%" .format(mc),4)
except (KeyboardInterrupt, SystemExit):
cleanAndExit()
P.S your codes and lines are being used in education not on any kind to get an income
P.P.S specifically, on my thesis project
I am hoping and wishing to get a response. Big thanks for even noticing me.
Hi
When i use HX711 and 4 load cell for my project with Jetson Nano 4GB, i'm getting zero value, however same wiring method with arduino nano or RPi 4 it works. I'm wondering is this library not compatible with Jetson Nano?
Hi sir tatobari,
Do you have some way to get the first initial mass from the code?
like.. after the Tare where the value is 0, then you suddenly lumped in a 3kg you get to record and save the 3kg value sensed by the loadcell to be used in equation like these:
MC = (1-(initial mass - present mass)/initial mass) * 100
Ive tried this code and got myself a 1% because of lack of initial mass value:
Hi,
I believe it is not ideal to indicate that the HX711 should be connected to 5V. That is totally fine with an Arduino, but probably unsafe with the RPi.
I am not sure what exactly might happen, but the RPi (especially older ones, I guess?) might get damaged in the process.
I will be linking this conversation: https://forums.raspberrypi.com/viewtopic.php?t=335497.
"Arduino UNO's GPIOs maximum current is rated at 40mA at 5V, whereas RPi's is 3.3V at 16mA."
Thus, making the HX711 run at 5V with the RPi might not be safe.
Unless... am I missing something?
Hello, and I appreciate any help I can get.
I am using 4 degraw 50kg sensors. Using Standard example.py, I have only changed the reference unit, and commented read long and uncommented get weight. Also tried playing with uncommenting hx.tare().
As I’m completely new to python I am pretty sure I am doing something wrong and need clarification.
Should hx.tare be commented or uncommented, or changed after calibrating? I only ask because comments on SparkFun page said they had to uncomment to get it to work.
Should calibration be done using read long or get weight?
Using get weight I get readings of around 32,000 with no weight, and that does not change when I add weight. Changing reference unit can bring that number down, but will still not read weight.
Again I appreciate any help or clarification for my troubleshooting. Been trying to figure this out for two days but some information on other sites has confused me.
Tatobari,
So I was wondering if you knew a way to speed up how fast it takes readings, because I had read that it should be able to take about 80 readings per second. Yet I can only get about 2 readings per second. So if there is anything that I can do to get the amount of readings to be much higher it would be highly appreciated.
Update: I changed the argument in the get_weight
method to 1
instead of 5
and now I can get 6
readings per second. I also commented out the power_down
, power_up
, and the time.sleep
parts. Also I am using a Raspberry Pi Zero if that helps
Thanks
Karl
First off let me say thanks for the code. However am still getting inconstant values.
A typical measurement looks as follows:
-30217
-30187
2742472
2742470
-30228
-30231
645318
-30186
2742424
-20956
-29201
-30305
-30259
When I use the exact same setup with https://github.com/ggurov/hx711 which is written in C. I don't have the issue. However it's C and is going to be a pain to get that into flask. Any advice/solution?
Hello, I am getting zero values so I followed the comment
I am using GPIO pin5 & 6 (GPIO5 for DT & GPIO 6 CLK)
Tried changing power source to both with VCC 5V and 3.3V
Tried with Different set_reference_units
still I getting zero values.
Please help me I am really determined to do it.
Dear,
I am looking for a change in the program. Once the scale is set, tare is known, it should run at startup without rescale. Is it possible to change this?
Hello everyone,
I tested your programm, but i have a error: AttributeError: 'HX711' object has no attribute 'get_weight'.
What have i done wrong? Can someone help me.
Thank you
I want to read the values from 3 separate load cells, each with its own HX711. I need the weight value to stay the same from each reading, or basically, I need to read the values from each load cell without tareing them. Is there a way to do this without having multiple HX711 instances?
(Example code only shows two instances)
from hx711 import HX711
hx1 = HX711(5, 6)
hx1.set_reading_format("MSB","MSB")
hx1.set_reference_unit(687)
hx1.tare()
hx1.power_down()
hx2 = HX711(7, 8)
hx2.set_reading_format("MSB","MSB")
hx2.set_reference_unit(687)
hx2.tare()
hx2.power_down()
if selectedlc == 1:
hx1.power_up()
intWeight = hx1.get_weight(5)
hx1.power_down()
if selectedlc == 2:
hx2.power_up()
intWeight = hx2.get_weight(5)
hx2.power_down()
Hello Tato
Thank you for your script. I am doing a calibration as well, and I have some troubles with my output since a get large signal value output interval from the raspberry 3. I have been calculating the signal values to kg, by using the linear equation y = ax + b.
But unfortunately, I get signal values from 28687 to -1508217, wich corresponds to -0.4 kg and 24 kg wich should not accrue since I only was adding 2.6 kg to my loadcell.
BTW: I chanced getweigth(5) to getweigth(1) and out commented I also commented out the power_down, power_up, and the time.sleep in example.py
Hope you can help:)
Hello, I am getting random values so I followed the comment
#If you're experiencing super random values, change these values to MSB or LSB until to get more stable values.
if I am right it means we can only change the values between MSB and LSB in Line 34 hx.set_reading_format("MSB", "MSB")
In later comment #According to the HX711 Datasheet, the second parameter is MSB so you shouldn't need to modify it.
so I did not changed 2nd parameter and tried with hx.set_reading_format("LSB", "MSB")
still I get random values. I tried changing power source to 3.3 V as i read in one of the solved issue.
Please help me I am really determined to do it.
@tatobari hx711 for raspberryPi working Fine.
Same code with hx711 -for jetson nano getting random values on adding or removing weight.
I am stuck here. Could you please help?
board used - Jetson nano developer kit, load cell -5kg, HX711
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.