tlfong014766Mon 15:49Errata – (1) INNA and INPA are load cell inputs to one channel of the HX711(2) INNB and INPB are the Channel B inputs to the HX711(3) It is the terminals/pins PD_CLK (Power Down and Clock) and DOUT (Digital Out) to connect to two separate Rpi GPIO pins.(4) Rpi uses two GPIO pins to interface with HX711’s two channels.(5) So forget what I said earlier to put aside the load cell, you need the load cell to do the testing (You might break away load cell output and use Gnd to connect to INNA, 0V or 3V3 as input to connect to INPA. But this make things confusing, so I won’t try it now)To make sure I am not going to make more errors, I am reading my old testing notes and copy and paste some notes to refresh my memory, and also for your reference.
(removed)I learnt HX711 from SparkFun some two years ago. You might also read SparlkFun’s tutorial.Now, my programming notes:HX711 Summary Notes for programming and debugging V0.2 tlfong01 2020oct26hkt1611
(1) ***Analog Inputs***
Channel A differential input is designed to interface directly with a bridge sensor’s differential output. It can be programmed with a gain of 128 or 64. The large gains are needed to accommodate the small output signal from the sensor.
When 5V supply is used at the AVDD pin, these gains correspond to a full-scale differential input voltage of ±20mV or ±40mV respectively.
Channel B differential input has a fixed gain of 32. The full-scale input voltage range is ±80mV, when 5V supply…(see full text)(2) ***Output Data Rate and Format***
When using the on-chip oscillator, output data rate is typically 10 (RATE=0) or 80SPS (RATE=1).
The output 24 bits of data is in 2’s complement format.
When input differential signal goes out of the 24 bit range, the output data will be saturated at 800000h (MIN) or 7FFFFFh (MAX), until the input signal comes back to the input range.(3) ***Serial Interface***
Pin PD_SCK and DOUT are used for data retrieval, input selection, gain selection and power down controls.
When output data is not ready for retrieval, digital output pin DOUT is high. Serial clock input PD_SCK should be low.
When DOUT goes to low, it indicates data is ready for retrieval.
PD_SCK high min = 0.2uS, max 50uS (1/50uS = 20kHz) (typ 1uS)
PD_SCK low min = 0.2uS (typ 1uS, 1MHz)
By applying 25~27 positive clock pulses at the PD_SCK pin, data is shifted out from the DOUT output pin.(see full text)Cem52Mon 16:21Hi tlfong01, first really appreciate your feedback and help. I’m close to give up 🙂 after browsing the web up and down. All the stuff is beyond my oldish brain can chew. There is a lot out there with arduino which seems to work better. But couldn’t find anyone using multiple HX711 on a Rpi. The simple code example you shared doesn’t work at all for me with error message from indentation to not defined variables (was about to try to install .GPIO.RPI in python 3.I was thinking to bypass all this hassle by just using first one load cell, save the values, disconnect and connect the other and do the readings with the second load cell and finally just combine them. Does that make sense ? tlfong01I also google my old HX711 photos to make sure my wiring scheme is still OK. Cembtw I think my wiring is correct after I tried to understand this BCM and Board thingy and BCM refers to GPIO numbering whereas Board to pin numbering. correct ? tlfong01Ha, your clarification confuses me. Let me try my broken English. (1) BOARD scheme refers to the physical numbering of the 40 pin header. (2) BCM means what BoardCom designer who denotes their GPIO pin number, which is “logical”, and has not correspondence to “physical” layout. (Only 50% sure. :)) Cemhaha I think we speak the same language, that confirms my understanding hence I chose BCM and the “logical” numbering tlfong014766Good. I should also said that “BOARD” refers to the printed circuit BOARD. So no problem about pin numbering. Let us move on, before you finally give up.Yes, I am not surprised that you said the following: (1) All the stuff is beyond my oldish brain can chew. (2) There is a lot out there with Arduino which seems to work better. (3) But couldn’t find anyone using multiple HX711 on a Rpi.Let me the OK boomer make a couple of suggestions: First One (1) You sit back and watch what the OK boomer is now struggling along. I will try to do the following: (a) Install the package/library I recommended earlier, (b) Try it on my HX711 module which is lying in a junk box, collecting dust for two years now. CemMon 16:41nice – watching 😉 tlfong014766I suggest you to sit back and watch, because there are quite a lot of stumbling blocks and mental barriers for newbies to do HX711. It is not that newbies are stupid, but the developers are dwelling in the Tower of Barbel. Without wasting more time, let me start.You don’t need to follow closely. You can come back from time to time, or tomorrow, to see if I am still going, or already given up! 😦 I am a Lonely Planet programmer, very comfortable going solo, without asking anybody questions for a long while. You might have questions when I go along, but you might not need to ask questions for now, because later when you look back my whole journey, then most your too afraid to ask questions might then disappear. Cheers. Cemlol at least thanks having chuckle here solo tlfong014766Mon 17:22(removed)H1. Now I am going to start installing the following package:
hx711 18.104.22.168 pip install hx711, A library to drive a HX711 load cell amplifier on a Raspberry Pi – PyPi.Org
H2. I am writing a reading log.
This library allows to drive a HX711 load cess amplifier with a Raspberry Pi. It just provides the capabilities:
to set channel an gain and
to read raw values
Getting started Just install by pip3 install HX711. A basic usage example is given below: #!/usr/bin/python3 from hx711 import HX711 try: hx711 = HX711( dout_pin=5, pd_sck_pin=6, channel='A', gain=64 ) hx711.reset() # Before we start, reset the HX711 (not obligate) measures = hx711.get_raw_data(num_measures=3) finally: GPIO.cleanup() # always do a GPIO cleanup in your scripts! print("\n".join(measures))
(see full text)Note H2:
The tutorial has this first statement in the demo program.
This a newbie scary cryptic CLI (Command Line Interface) shorthand statement, usually for linux experts to work crazily fast in BASH command line mode. But the OP is using newbie friendly Thonny python IDE. So I will not follow the package guide closely, and start with the newbie Thonny. (By the way, I am using Rpi4B buster.)Now I am keeping the HX711 installation record for later reference.
tlfong014766Mon 18:04Next is to run the demo program using Thonny IDE. There is no real hx711 module in hand. So I just did a fake run. So far so good.(removed)
So far so good. Now I know Thonny python can import the hx711 module and create a hx711 module object. Thonny python can create the object even though there is no real hx711 connected, because the object creation just blindly set GPIO pins as input or output, without caring if the GPIO pins are connected to any thing. In other words, I am more or less cheating the hx711m01 object.Next is to search my junk bin for the old hx711 module board which has been collecting dust there for two years.Ah, locking down jogging and supper time! See you late this evening or tomorrow. Cheers.Ah, I forgot my old hx711 module is red, green, or purple. So I searched my old photo gallery to refresh my momory.
Cem52Mon 18:20oh are we in same time zone ? My wife is preparing dinner too …my HX711 is the green one but I just noticed I’m struggling with some basics. pipe3 command doesn’t work, when I try to install it says it’s there… when I check my python version it’s 2.7xy even so the other day I spent 8 hoers installing 3.8 just to find out there is 3.7 installed already.So when I try sudo pipe3 install HX711 it’s kind half baked thing but maybe I’m missing something. When I go to the 3.7xy library there are 2 HX711 folders…hm you don’t get any error messages. Need to read how to make python 3 standard I guess that’s one issue 4 hours later… tlfong014766Mon 22:27Ah, you remind me the first time I try to upgrade my Rpi1 or Rpi2 from default python 3.5.3 to python 3.7.3. It took me about 3 hours before I gave up. I knew I did not have the prerequisite linux knowledge and tools, to locate the problem. I made a mess of the directories. I still do not know what are “alias” directories, and I am not keen to learn, because the new buster GUI tools including the new install/upgrade tools solve almost all my install problems.I still remember trying “curb”, “NMB” (not sure if I spell correctly) and a couple of otherinstallation tools. The problem is the following:Important advice to newbies(1) When your package is supposed to run in python 2.7, then you should almost always use “pip”, which means by default “pip2”. If you wrongly use “pip3”, the package is installed in a directory for python3. Often you can try to “pip” again to install the package in a directory for python 2.7. Now the default “path” command would be changed to python3 to python 2 directory.But if you are using python3 now and python2 some other time, then no one will automatically change the path config files for you, with the result of a big mess.What I said is the “Tower of Barbel” is that some python packages are ported from Ubantu or other linux variants, by so many hackers in different places at different times, and they might have left their gitHub package unsupported, and other new hackers come along and “fork” new versions of the old package.The most disgusting or criminal thing is that some hackers (they call themselves “developers”) when forking a new version of the old package, do not following the standard of moving the directories for pip/pip3 etc, with the following horrible result:In some rare cases, when you first wrongly use “pip3”, find it does not work, and try your luck using “pip”, it is too late, because the auto config thing won’t bother to take care of going back to pip2. The only solution I know, at least for me newbie, is the following.When trying new things, always keep the working image as a backup, and make a test/work SD image to try the new things, and as you go smoothly, make work image #2 and move on, then #3 and move on etc. When you have trouble using say, work 15, them fall back to work 14, and still no luck, fall back further to #13. And if #13 ok, then make #14a and move on.This is a general troubleshooting technique called “swapping” test/troubleshooting. Of course many people said it is just common sense, no big deal. But then I learn the following in a hard way: The difference between a pro and a non-pro is that a pro makes backup.Bed time. Call it a day. See you tomorrow. PS – I found my old hx711 module proto board in the junk bin. Might try it tomorrow. 11 hours later… tlfong014766yst 10:22My old hx711 module on proto board does not seem to have collected too much dust. But I have forgotten which wires for which use. So I need to browse my photo gallery again.
Cem52yst 11:00good morning (still kinda), again I really appreciate your support and taking the time to explain the stuff and I understand better but I understand also that this most likely simply doesn’t work hence there is no one out there who used 2 HX711 at the same time with a Rpi.The more I fiddle (this morning another 3 hours) there in a mess I end up.
Currently none of the example.py’s run, somehow after making python 3.7 the default and installing HX711 I have another folder under usr/local/lib/ with hx711-1.1.23 which is different to what have in another HX711 folder, this new is reading the mean… but any py I try to run I get Attribute erros for HX711. I will attempt 2 last tries but with the goal to use only one load cell and one hx711 module at a time: 1. default back to python 2.7 use the “old” example py I had modified (tried to modify) if things are stil…(see full text)Cemyst 11:12reinstalling Rpi OS ggrrrr tlfong014766yst 11:24@Cem You said “no one out there who used 2 HX711 at the same time with a Rpi“. Well, at least one crazy hobbyist programmer in this Lonely Planet is using more than two HX711’s. If you search rpi-org-forum you might find some one was using ESP8266-12 LUA to control a couple of MCP23017’s each of which has 16 GPIO ports, each pair of ports control one HX711 module.So the other crazy guy is controlling 4 x mcp23017 (can be up to 8) each of which is controlling 8 x hx711, each of which is controlling two load cells. So it is 4 x 4 x 8 x 2 = 128 load cells (note: my dodgy calculations is not proofread. )@Cem Ah, this is what I am doing: “the goal to use only one load cell and one hx711 module at a time …”. This is called the Occam Razor approach – Make the thing as simple as possible, but not simpler.”You might have heard that StackOverflow did a survey a year ago, telling the whole planet the results that SCALA is the most money making language for the programmers. Scala means “A scalable language”, which means that once you know how to talk to one hx711, you can talk to as many as hx711’s as you like, …Yes, I am not using Scala, but you don’t need to use Scala to do Scala, You can use LUA C#, or F#, or Python to do Scala. Of course you can also use stupid C/C++ to do Scala, but that would take 100 times longer, and still end up a big mess. By the same token, I am doing OO programming without OO languages, Agile development without using Agile tools (Google Uncle Bob to know more of what I am talking). So I sometimes call myself a “be water programmer“, … 🙂 tlfong014766yst 12:14Now I am making a 500g load cell testing rig.
Ah, locking down lunch time! See you late this afternoon or evening. Cheers. tlfong014766yst 12:28Before I go, I would recommend you to watch an Uncle Bob’s talk. He is talking about Future Programming. I forgot to mention I am trying to write my programs Future Proof. In other words, I am also a ***Future Programmer***. ***Uncle Bob Martin The Future of Programming*** – 2016may18, 1,530,276 views
youtube.com/… 8 hours later… Cemyst 20:26Occam Razor approach – I like that. btw I’m in Singapore though from Germany (been now 16 years here). reinstalled OS, putting things together, calibrated one load cell, tomorrow next and then hopefully final wind tunnel tests which will probably last a day with 4 month research and preparation… enjoy the evening tlfong014766yst 20:45Ah, I also just calibrated the 500g load cell, with results shown below.
Next is to upgrade the hx711 test program from v0.1 to v0.2. Now I am going to connect Rpi to the real thing, the hx711 module, and see if it can measure something, at least can reset itself. Two years ago this time I used ESP8266/Rpi3B+ stretch LUA/python MCP23017 to try to talk to hx711, but ended up a mess. So I gave up.This time I don’t have much confidence and dare not to write my own program (actually not that difficult, if using python, but at that time Rpi3B+ I2C was buggy, and couldn’t change frequency, only flat 100kHz. (OK my excuse 🙂 😦 ).Anyway, Rpi4B I2C is bug free now. Moreover, the PiPy library I am trying now is in python, and I peeked inside and found the logic simple: just send 20 something bytes and read back the 24 bit raw result and convert it to decimal. As usual, I won’t write the tedious 2’C compliment to decimal myself, I just steal the conversion code from somewhere. 🙂 2 hours later… tlfong014766yst 22:33Now I have upgraded my very simple hx711 test v0.1 program to also very simple v0.1. The Rpi to hx711 is also as simple as possible:Only the right hand side 4 pin connector are used, from top to bottom:Vcc – connected to 3V3hx711 Data to Rpi pin 14 (TxD)hx711 Clock to Rpi pin 15 (RxD)hx711 Ground to Rpi GroundThe 5 pin of the left side connected is left Not Connected (NC)The only upgrade function added is just to reset hx711. Last hx711 was connected, excuting reset would hang the program. This time the reset function executes smoothly, verifying Rpi can talk to hx711 and ask it to do something like reset. I have not tried the get raw data yet. I am a humble guy, I dare not to go too fast. The v0.2 program, with sample output, is listed below.
# Program description # hx711test02a.py tlfong01 2020oct27hkt2109 # System Config # Rpi4B 2GB Thonny python 3.7.3 # HX711 PyPi Library Install # pi@raspberrypi:~ $ date Tue 27 Oct 2020 09:14:01 PM HKT # pi@raspberrypi:~ $ pip3 install hx711 # Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple # Requirement already satisfied: hx711 in ./.local/lib/python3.7/site-packages (22.214.171.124) # *** Imports *** import RPi.GPIO as GPIO from datetime import datetime from hx711 import HX711
11 hours later… tlfong0147669:58I read the comments of the 2017 tutorial you are following. It appears that there are comments about your hx711 unreliability problem, you might like to read them to see the comment are helpful to solve you problem. I also found another gitHub python 3 only library you might try.(1) Felix – Build a digital Raspberry Pi Scale (with Weight Sensor HX711) – 2017
(2) Gandaf15 – hx711 gandalf15 python 3 library – 2019jan02
github.com/gandalf15/HX711/… 2 hours later… tlfong01476611:53I also found that the pyPi hx711 python3 library I am using is based on gandaf15. Also that your green module is different from mine, which has rate pin jumpers. Gandaf15 has a tip to set rate, as shown below.
3 hours later… tlfong01476614:45Now I am going to calibrate the 5kg load cell. My test plan is the following.(1) Test 1 hx711 module with 2 channels each of which handling 1 load cell.(2) Test 2 hx711 modules, each Channel A handles one load cell.
Now I am searched for my old calibration record of the 5kg Load Cell.(1) HX711 Forum Discussion Notes 1/4
(2) HX711 Forum Discussion Notes 1/4
(3) HX711 Forum Discussion Notes 1/4
1kg = 3.2mV
(4) HX711 Forum Discussion Notes 1/4 (calibration Notes)
raspberrypi.org/forums/…A very rough summary of the 5V load cell calibration results is the following:For Vcc = 5V:(1) It is about 5mV for 5kg max load,(2) Or 1mV/V sensitivity (I forgot what this exactly means! 🙂My rough rult of thumb is the following:Either Vcc = 3V3 or 5V0. The voltage output for max loading, either 500g or 5kg, is about 5mV. In other words, the HX711 load cell amplifier should be set to the following:gain factor = 3V3 / 5mV = 3300 / 5 ~= 600. This 600 gain factor is what I am going to set in the coming Hx711 ADC test.The calibration record for 5kg load cell: