Posts: 1
Joined: Tue Jul 03, 2018 3:22 am

Interface to HX711 without bit banging

Tue Jul 03, 2018 3:35 am

Hello all,

I'm trying to interface with the HX711 sensor, datasheet link below. I've found various code online to do this however it appears they all use bit-banging and all seem to have issues with that going wrong resulting in random values being read occasionally. Some libraries try to correct for this by throwing away samples too far off the average but overall I'm not very comfortable with the idea of having code producing spurious values. I'm guessing these spurious values are a result of the bit-banging process going wrong.

The HX711 has somewhat of a strange interface; it has two wires - clock and data. During a data transfer you need to send it between 24 clock pulses to retrieve the data and 1-3 additional clock pulses to configure its amplifier gain.

To try to get more reliable interface I looked at using the SPI bus - only connecting the SPI clock and MISO pins to the HX711. The problem is the SPI bus seems to transfer 8 bits per word, leaving me with the option of sending either 24 or 32 clock pulses (both of which are non-comformant to the HX711's datasheet). I've considered just sending 32 clock pulses and then driving the SPI clock pin high for 60 us which would reset the HX711 after i perform my non-comformant 32 clock transaction but I don't know if the wiringPi library would allow me to keep switching between driving the SPI CLK pin as a GPIO and then switching back to using it as a SPI pin.

Does anyone have any recommendations? Solutions using C would be preferred.

User avatar
Posts: 14374
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Interface to HX711 without bit banging

Tue Jul 03, 2018 7:54 am

wiringPi should support changing the GPIO mode between OUTPUT and the ALT mode needed for SPI.

Also see ... n_HX711_py

The auxiliary SPI does provide for a variable word length. Might be worth trying.

Return to “Beginners”