0

I have used hx711 and loadcell with nodemcu (esp8266) in its D1 and D2 pins ( here I have used Logic level shifter and a 5v supply to power hx711).It worked perfectly fine.

Due to the lack of enough pins to accommodate other sensors in Nodemcu, I'm using PCF8574. I have connected hx711 to pins P0 and P1 of PCF8574.I'm not able to get any output in serial monitor while running like this.

The PCF8574 was connected using resource -

https://www.instructables.com/id/PCF8574-GPIO-Extender-With-Arduino-and-NodeMCU/

The Hx711 was connected using this code.It is compiling but not getting any output in serial monitor.

#include "Arduino.h"
#include "PCF8574.h"

// Set i2c HEX address
PCF8574 pcf8574(0x20); // A0,A1,A2 all connected to GND
unsigned long timeElapsed;


include <HX711.h>
HX711 scale;

void setup() {
  Serial.begin(9600);
  Serial.println("initializing");
  pcf8574.pinMode(P0,INPUT);
  pcf8574.pinMode(P1,OUTPUT);
  pcf8574.begin();

  Serial.println("initializing");

  scale.begin(P0,P1); //dt , sck
  scale.get_value(5);  // print the avg of 5 readings from ADC minus tare weight 
  scale.set_scale(-450.f); // callibration value
  scale.tare();// reset scale to zero
}

void loop() {


  int weight = scale.get_units(3);
  Serial.println(weight);
  delay(1000)

}

Or how about this code without a library? Can I do some changes to it and use pcf8574 ?


#define DT D1
#define SCK D2


long sample=0;
float val=0;
long count=0;

unsigned long readCount(void)
{
  unsigned long Count;
  unsigned char i;
  pinMode(DT, OUTPUT);
  digitalWrite(DT,HIGH);
  digitalWrite(SCK,LOW);
  Count=0;
  pinMode(DT, INPUT);
  while(digitalRead(DT));
  for (i=0;i<24;i++)
  {
    digitalWrite(SCK,HIGH);
    Count=Count<<1;
    digitalWrite(SCK,LOW);
    if(digitalRead(DT)) 
    Count++;
  }
  digitalWrite(SCK,HIGH);
  Count=Count^0x800000;
  digitalWrite(SCK,LOW);
  return(Count);
}

void setup()
{
  Serial.begin(9600);
  pinMode(SCK, OUTPUT);
  Serial.println("Weight");
  Serial.println(" Measurement ");
  delay(1000); 
  calibrate();
}

void loop()
{
  count= readCount();
  int w=(((count-sample)/val)-2*((count-sample)/val));
  Serial.print("weight:");
  Serial.print(w);
  Serial.println("g");


 delay(100);
   // val=0;
   // sample=0;
    w=0;
    count=0;
   // calibrate();

}

void calibrate()
{

  //Serial.println("Calibrating...");
  //Serial.println("Please Wait...");
  for(int i=0;i<100;i++)  
  {
    yield(); 
    count=readCount();
    sample+=count;
   // Serial.println(count);
  }
  sample/=100;
  //Serial.print("Avg:");
  //Serial.println(sample);
  count=0;
  while(count<1000)
  {
    yield(); 
    count=readCount();
    count=sample-count;
    //Serial.println(count);
  }

  //Serial.println("Please Wait....");
  delay(100);
  for(int i=0;i<100;i++)  
  {
    yield(); 
    count=readCount();
    val+=sample-count;
   //Serial.println(sample-count);
  }
  val=val/100.0;
  val=val/100.0;       
  //Serial.println(val);
}

  • the HX711l ibrary will not magically use the PCF8574 only because you name the pins Px – Juraj Jan 8 at 17:22
  • Thank you for replying. I understand that Hx711 library doesn't know about the PCF8574. I was hoping to tweak the library and work it out. What changes should we make to the library? – noon masho Jan 9 at 5:34
0

According to library, hx711 sending pulses to mcu and we are scaling with take this pulses. I think you must connect DOUT and SCK pins directly to the MCU or you must counting pulses via I2C after all create a scaling value according the library code and send it to mcu.

  • Thank you for answering. I have to use some GPIO expander as I have limitations of pins. Can you please explain more specifically how it can be done? – noon masho Jan 9 at 6:30
  • I didnt try this method ever but, I checked datasheet and found this code: – Dogan Cignakli Jan 9 at 6:33
  • Pls check the updated Question. – noon masho Jan 9 at 6:38
0

I didnt try this method but; when i check the data sheet, i found this code on last page:

    sbit ADDO = P1^5;
    sbit ADSK = P0^0;
    unsigned long ReadCount(void){
     unsigned long Count;
     unsigned char i;
     ADDO=1;
     ADSK=0;
     Count=0;
     while(ADDO);
     for (i=0;i<24;i++){
     ADSK=1;
     Count=Count<<1;
     ADSK=0;
     if(ADDO) Count++;
     }
     ADSK=1;
     Count=Count^0x800000;
     ADSK=0;
     return(Count); 
}

Here is the pulse counting method i think. So if we are using I2C IC, we must get pulse datas over it to our MCU and count them. But before this scaling method; we must calibrate loadcells and tare them absolutely. And i found a link that pointing i2c with hx711. They used sparkfuns IO expander(communicating via I2C) to fix low io problem and connect loadcells to this expander and how read scalings completely. Here is the link: if you can check, maybe find a solution for your problem. Sparkfun's I2c Expander with Hx711

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.