Chat freely about anything...

User avatar
By jconenna
#17524 Hi all. I am trying to figure out a way to get my esp-07 running nodeMCU to communicate with an HX711 ADC for weighing purposes. The way I used the HX711 with an Arduino was by bit banging the DOUT AND CLK pins on the board , but am not having much luck getting it to work with the implementation translated into LUA.

Page 4 of the DATA SHEET describes the process. First DT must be read LOW when SCK is LOW to know the ADC is ready to be read. I cannot seem to read DT as anything but HIGH, signifying that the ADC is not ready, and when I attempt to toggle SCK HIGH and LOW DT remains HIGH according to output in LUA. I have the ADC powered by 5v and the data lines bi-directional logic shifted between 5v and 3.3.

Here's a code snippet:
Code: Select allDT = 3
SCK =  4
gpio.mode(DT, gpio.INPUT)
gpio.mode(SCK, gpio.OUTPUT)

out = "" -- 24 bit word

while gpio.read(DT) == 1 do end -- wait until DT goes LOW and ADC is ready to be read

for i=1,24 do
  gpio.write(SCK, gpio.HIGH)
  out = out .. gpio.read(DT)
  gpio.write(SCK, gpio.LOW)
end

print(tonumber(out, 2))


Basically DT is always HIGH so the while loop never terminates and the MCU reboots.

Is there something wrong with the speed of LUA when trying to read/toggle these data lines? I hope this makes sense, as I have only recenctly started working in this framework. I appreciate any feedback/advice regarding this situation or bit banging with NodeMCU in general.

Thanks! :D
User avatar
By dkdileep
#22194 I have a solution for this problem using custom code in NODEMCU firmware. If it is popular enough I can include it in the NODEMCU github.

For now, I am able to do the following
LIB.hx711read, LIB.hx711setgain, LIB.hx711powerdown, LIB.hx711powerup

You can set the Amplifier gain, power down/up and read values using Lua.
User avatar
By rca
#26126
dkdileep wrote:I have a solution for this problem using custom code in NODEMCU firmware. If it is popular enough I can include it in the NODEMCU github.

For now, I am able to do the following
LIB.hx711read, LIB.hx711setgain, LIB.hx711powerdown, LIB.hx711powerup

You can set the Amplifier gain, power down/up and read values using Lua.


that would be sweet, i'm just trying to do the same with lua (in arduino, i could use the hx711 library)

or if you could provide a hint on how to get the pin ready, that would be good too