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);
}