I could not get the scale code working on a Wemos, It kept on resetting.
Worked ok with a mysensors sketch.
I did not realize the load cell needs a base to sit on and was getting inconsistent readings. This printed part solved that issue.
Anyway thank you for sharing your project.
Here is the mysensors sketch if anyone is interested
/**
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* http://www.mysensors.org/build/light
* copied and adapted from HA Mysensors documentation
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <HX711.h>
#include <MySensors.h>
#define SN "BedScale"
#define SV "1.0"
#define CHILD_ID 1
unsigned long SLEEP_TIME = 3000; // Sleep time between reads (in milliseconds)
// Scale Settings
const int SCALE_DOUT_PIN = 3;
const int SCALE_SCK_PIN = 2;
HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);
MyMessage msg(CHILD_ID, V_WEIGHT);
float lastWeight = 0;
bool initialValueSent = false;
void setup()
{
sendSketchInfo(SN, SV);
present(CHILD_ID, S_WEIGHT);
scale.set_scale(-1830341/80);// <- set here calibration factor- read value with known weight(80Kg)/ Known weight
scale.tare();
}
void loop()
{
if (!initialValueSent) {
Serial.println("Sending initial value");
send(msg.set(String(lastWeight)));
Serial.println("Requesting initial value from controller");
request(CHILD_ID, V_WEIGHT);
wait(2000, C_SET, V_WEIGHT);
}
float weight = scale.get_units(1);
//Serial.print("Weight is:");
// Serial.println(String(weight, 2));
if (weight != lastWeight) {
send(msg.set(weight, 2));
lastWeight = weight;
}
sleep(SLEEP_TIME);
}
void receive(const MyMessage &message) {
if (message.type == S_WEIGHT) {
if (!initialValueSent) {
Serial.println("Receiving initial value from controller");
initialValueSent = true;
}
}
}```