bogde / HX711

An Arduino library to interface the Avia Semiconductor HX711 24-Bit Analog-to-Digital Converter (ADC) for Weight Scales.
MIT License
896 stars 538 forks source link

Random outputs on multiple HX711 on HUZZAH32 (ESP32 Feather) #204

Closed Nailik closed 3 years ago

Nailik commented 3 years ago

Hi, i want to make a scale with two load bar cells. Therefore i also tryied to use 2 HX711 (one for one cell). When i tare one an read the values i get correct values. But as soon as i want to read both sensors, i get really mixed up things. They don't tare, sometimes one tares but i also get sth like -80 from one an 500 from the other (calibrated to gramms).

This is my pretty simple code:

#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LEDBackpack.h>
#include <HX711.h>

#define PIN_LED_BT_TARA 27 //27
#define PIN_PUSH_BT_TARA 39 //A3

#define PIN_LED_BT_ON_OFF 33 //33
#define PIN_PUSH_BT_ON_OFF 34 //A2

#define LOAD_CELL_O_D_OUT_PIN 14//14
#define LOAD_CELL_1_D_OUT_PIN 15//15
#define LOAD_CELL_SCK_PIN_0 26 //A0
#define LOAD_CELL_SCK_PIN_1 25 //A1

#define CAL_0 3692
#define CAL_1 3692

#define SENSOR 2 //0 = 0, 1 = 1, 2 = both

int tara_state_led = HIGH;
int on_off_state_led = HIGH;

int tara_state_old = LOW;
int on_off_state_old = LOW;

Adafruit_7segment matrix = Adafruit_7segment();
#if SENSOR == 0
HX711 scale_0;
#endif
#if SENSOR == 1
HX711 scale_1;
#endif
#if SENSOR == 2
HX711 scale_0;
HX711 scale_1;
//random output
/*
 * 592.2
scale[0]
-80.1
scale[1]
672.2

 */
#endif

float oldValue = 0;

void setup() {
    pinMode(PIN_LED_BT_TARA, OUTPUT);
    pinMode(PIN_LED_BT_ON_OFF, OUTPUT);

    pinMode(PIN_PUSH_BT_TARA, INPUT);
    pinMode(PIN_PUSH_BT_ON_OFF, INPUT);

    // initialize LED digital pin as an output.
    matrix.begin(0x70);
    matrix.clear();
    matrix.setBrightness(50);

    Serial.begin(9600);
    Serial.println("setup");

#if SENSOR == 0
    scale_0.begin(LOAD_CELL_O_D_OUT_PIN, LOAD_CELL_SCK_PIN_0);
    scale_0.set_scale(CAL_0);
    scale_0.tare();
#endif
#if SENSOR == 1
    scale_1.begin(LOAD_CELL_1_D_OUT_PIN, LOAD_CELL_SCK_PIN_1);
    scale_1.set_scale(CAL_1);
    scale_1.tare();
#endif
#if SENSOR == 2
    scale_0.begin(LOAD_CELL_O_D_OUT_PIN, LOAD_CELL_SCK_PIN_0);
    scale_1.begin(LOAD_CELL_1_D_OUT_PIN, LOAD_CELL_SCK_PIN_1);
    scale_0.set_scale(CAL_0);
    scale_1.set_scale(CAL_1);
    scale_0.tare();
    scale_1.tare();
#endif

    Serial.println("start");
}

void loop() {
    digitalWrite(PIN_LED_BT_ON_OFF, on_off_state_led);
    digitalWrite(PIN_LED_BT_TARA, LOW);

    float val = 0;

#if SENSOR == 0
    float value = scale_0.get_units();
    val+=value;

#endif
#if SENSOR == 1
    float value2 =  scale_1.get_units();
    val+=value2;
#endif
#if SENSOR == 2
    float value = scale_0.get_units();
    float value2 =  scale_1.get_units();

    Serial.println("scale[0]");
    Serial.println(value, 1);

    Serial.println("scale[1]");
    Serial.println(value2, 1);
    Serial.println("\n");

    val+=value+value2;
#endif
    if(val != oldValue) {
        oldValue = val;

        Serial.println(val, 1);
        matrix.print(val, 1);
        matrix.writeDisplay();
    }
}

I hope someone could be me out with this Problem.

Nailik commented 3 years ago

I failed. I didn't read the instructions carefully and forgot to connect VDD.