R Pi pico interfacing with a HX711 load cell module - Page 1
Forum section: electronics / general

author: Alex_Baker
author_rank: Frequent Contributor
timestamp: November 18, 2022, 06:30:40 pm
content: Hello Everybody.I am working on a project that involves reading a load cell with a HX711 module, like the ones you can get on the jungle website for $6. I am using a raspberry pi pico to read the sensor, I have a schematic in the attachments, you can ignore everything except the Pi and the HX711.My issue is with the programming, which is python in the thonny ide. I have done some playing around with the other modules in the schematic, But I am stuck on this one.I been looking at this github:https://github.com/robert-hh/hx711and played around with the code some but I just don't know how it works. In some of the examples, it is trying to import a python module called Hx711_pio, where is that module? I don't really know how modules work.Any input would be appreciated!

author: hubi
author_rank: Regular Contributor
timestamp: November 18, 2022, 11:33:17 pm
content: I have not used the python code you linked, but I have used the library athttps://github.com/endail/hx711and it works very well. It is PIO based and works very reliably at both the slow and fast speeds (11Hz and 80Hz, IIRC).

author: Alex_Baker
author_rank: Frequent Contributor
timestamp: November 19, 2022, 07:15:02 pm
content: Thank you so much, I will look into it!

author: Alex_Baker
author_rank: Frequent Contributor
timestamp: November 19, 2022, 07:18:38 pm
content: Oh, its a C++ library, I need to be able to run code for the HX711 along with python code for a couple of other modules, including a SD card module. I am not sure this would work.Eventually I want to write data from the HX711 to the SD card.

author: hubi
author_rank: Regular Contributor
timestamp: November 20, 2022, 07:25:23 am
content: Oops, I sent the wrong link earlier. This is the library I meant to linkhttps://github.com/endail/hx711-pico-cIt is a C library for the RP2040, the previous link was a C++ library for the Raspberry Pi by the same author. It's not python, but the PIO code might be useful, it is well documented and works very reliably.

author: Alex_Baker
author_rank: Frequent Contributor
timestamp: November 20, 2022, 08:10:47 pm
content: Well now I have something that is working in python, the only problem is that it is returning the data in the form 0x-------, for example 0x23df, or 0xfb4511, which I think is hexadecimal? I need some way to get that into grams or kilograms.

author: hubi
author_rank: Regular Contributor
timestamp: November 20, 2022, 09:41:20 pm
content: That might just be the way you are printing it out? Can you post a link to the code?You may have to convert the HX711 data using two's complement if the highest bit is 1, depending on whether the library you use does that for you or not.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 22, 2022, 02:21:57 am
content: The chip uses a bit unusual data protocol, but it's pretty simple. You send clock pulses to it, and it shifts out data. And apparently you've already figured that out. The main anomalies are that the amount of clock pulses you send determine what the chip does for it's next conversion, and you have to let it sleep a bit to make it predictable of when it does a conversion.There is no way for the chip itself to convert it to a weight or force, because there is a wide range of load cells you can hook up to a chip like this. So the only solution is to calibrate it yourself and apply some math. The minimum would be to add / subtract a value to get to "zero", and then add some multiplication factor so your measured value is converted to the value of your calibration weight. You can also measure some extra weights, and then use them to check linearity.