Chat freely about anything...

User avatar
By rca
#26539
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.


@dkdileep, please post if you can. I've tried implementing it in lua, but it gives non-sensical readings

Code: Select allDOUT = 6;
SCLK =  5;

gpio_mode = gpio.mode;
gpio_read = gpio.read;
gpio_write = gpio.write;

INPUT = gpio.INPUT;
OUTPUT = gpio.OUTPUT;
HIGH = gpio.HIGH;
LOW = gpio.LOW;
SCALE = 1;
OFFSET = 0;
GAIN = 1;


function is_ready()
    return gpio_read(DOUT) == LOW;
end

function set_gain(b)
    if b == 128 then
        GAIN = 1;
    elseif b == 64 then
        GAIN = 2;
    elseif b == 32 then
        GAIN = 3;
    end
    gpio_write(SCLK, LOW);
end

-- read data from the sensor
function read()

  local bytes = {}
  local bitStream = {}
  for j=1,24,1 do
      bitStream[j] = 0
  end
   
  while (not is_ready()) do end
 
  for i = 24, 1, -1 do
    gpio_write(5, 1)
    bitStream[i] = gpio_read(6)
    gpio_write(5, 0)
  end

  print(table.concat(bitStream, ""))

  local bitS = {}
  for j = 0, 2 do
    base = j * 8;
    for k=1,8 do
        bitS[k] = bitStream[base+k]
    end
    --print(table.concat(bitS, ""))
    bytes[j] = table.concat(bitS) -- tonumber(table.concat(bitS, ""), 2)   
  end

  -- set thee gain for the next reading
  for x = 1, GAIN do
     gpio_write(5, 1)
     gpio_write(5, 0)
  end
 
 
  bytes[2] = bit.bxor(bytes[2], 0x80)
  bytes[2] = bit.lshift(bytes[2], 16)
  bytes[1] = bit.lshift(bytes[1], 8)

  return bit.bor(bytes[2], bytes[1], bytes[0])
     
end

function read_average(num_try)
    s = 0
    print (num_try)
    for i=1, num_try do
        s = s + read()
    end
    return s / num_try
end

function get_value(times)
    return read_average(times) - OFFSET;
end

function set_offset(off)
    OFFSET = off;
end

function set_scale(scale)
    SCALE = scale
end

function tare(times)
    set_offset(read_average(times))
end

function get_units(times)
    return get_value(times) / SCALE;
end

gpio_mode(DOUT, INPUT);
gpio_mode(SCLK, OUTPUT);
set_gain(128);
User avatar
By sirsajid
#42212
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.

"dkdileep"
i am getting the acd value but do you know how do i convert the value in to pounds
User avatar
By sirsajid
#42303 [quote="dkdileep"]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.

I have the api returning the ACD values but I do not know how to convert it in to pounds?