Hello,
I am trying to connect 4 weight scale outputs from Hx711 adc to multiplexer cd74hc4067 which is connected to Arduino.
I tried using the sample codes from HX711_ADC/examples/Read_2x_load_cell at master · olkal/HX711_ADC · GitHub and HX711-multi/HX711-multi.ino at master · compugician/HX711-multi · GitHub
I am just confused with the inital step of defining pins for Hx7111 adc from the line 6 in the code. As in the above code, it is directly connected to pins of Arduino. I went through datasheet but could not find any infromation about the same
#include <HX711_ADC.h>
#include <CD74HC4067.h>
CD74HC4067 my_mux(9, 10, 11, 12); // create a new CD74HC4067 object with its four control pins
//pins: How should I give channel names here?
const int HX711_dout_1 = 4; //mcu > HX711 no 1 dout pin
const int HX711_sck_1 = 5; //mcu > HX711 no 1 sck pin
const int HX711_dout_2 = 6; //mcu > HX711 no 2 dout pin
const int HX711_sck_2 = 7; //mcu > HX711 no 2 sck pin
const int HX711_dout_3 = 8; //mcu > HX711 no 3 dout pin
const int HX711_sck_3 = 9; //mcu > HX711 no 3 sck pin
const int HX711_dout_4 = 10; //mcu > HX711 no 4 dout pin
const int HX711_sck_4 = 11; //mcu > HX711 no 4 sck pin
//HX711 constructor (dout pin, sck pin)
HX711_ADC LoadCell_1(HX711_dout_1, HX711_sck_1); //HX711 1
HX711_ADC LoadCell_2(HX711_dout_2, HX711_sck_2); //HX711 2
HX711_ADC LoadCell_3(HX711_dout_3, HX711_sck_3); //HX711 3
HX711_ADC LoadCell_4(HX711_dout_4, HX711_sck_4); //HX711 4
const int g_common_pin = A0; // select a pin to share with the 16 channels of the CD74HC4067
unsigned long t = 0;
void setup() {
pinMode(g_common_pin, OUTPUT); // set the initial mode of the common pin.
Serial.begin(57600); delay(10);
Serial.println();
Serial.println("Starting...");
float calibrationValue_1; // calibration value load cell 1
float calibrationValue_2; // calibration value load cell 2
float calibrationValue_3; // calibration value load cell 3
float calibrationValue_4; // calibration value load cell 4
calibrationValue_1 = 696.0; // uncomment this if you want to set this value in the sketch
calibrationValue_2 = 15.72; // uncomment this if you want to set this value in the sketch
calibrationValue_3 = 696.0; // uncomment this if you want to set this value in the sketch
calibrationValue_4 = 733.0; // uncomment this if you want to set this value in the sketch
LoadCell_1.begin();
LoadCell_2.begin();
LoadCell_3.begin();
LoadCell_4.begin();
//LoadCell_1.setReverseOutput();
//LoadCell_2.setReverseOutput();
unsigned long stabilizingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
byte loadcell_1_rdy = 0;
byte loadcell_2_rdy = 0;
byte loadcell_3_rdy = 0;
byte loadcell_4_rdy = 0;
while ((loadcell_1_rdy + loadcell_2_rdy + loadcell_3_rdy + loadcell_4_rdy) < 4) { //run startup, stabilization and tare, both modules simultaniously
if (!loadcell_1_rdy) loadcell_1_rdy = LoadCell_1.startMultiple(stabilizingtime, _tare);
if (!loadcell_2_rdy) loadcell_2_rdy = LoadCell_2.startMultiple(stabilizingtime, _tare);
if (!loadcell_3_rdy) loadcell_3_rdy = LoadCell_3.startMultiple(stabilizingtime, _tare);
if (!loadcell_4_rdy) loadcell_4_rdy = LoadCell_4.startMultiple(stabilizingtime, _tare);
}
if (LoadCell_1.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 no.1 wiring and pin designations");
}
if (LoadCell_2.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 no.2 wiring and pin designations");
}
if (LoadCell_3.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 no.3 wiring and pin designations");
}
if (LoadCell_4.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 no.4 wiring and pin designations");
}
LoadCell_1.setCalFactor(calibrationValue_1); // user set calibration value (float)
LoadCell_2.setCalFactor(calibrationValue_2); // user set calibration value (float)
LoadCell_3.setCalFactor(calibrationValue_3); // user set calibration value (float)
LoadCell_4.setCalFactor(calibrationValue_4); // user set calibration value (float)
Serial.println("Startup is complete");
}
void loop() {
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell_1.update() or LoadCell_2.update() or LoadCell_3.update() or LoadCell_4.update() ) newDataReady = true;
LoadCell_2.update();
LoadCell_3.update();
LoadCell_4.update();
//get smoothed value from data set
if ((newDataReady)) {
if (millis() > t + serialPrintInterval) {
float a = LoadCell_1.getData();
float b = LoadCell_2.getData();
float c = LoadCell_3.getData();
float d = LoadCell_4.getData();
Serial.print("Load_cell 1 output val: ");
pinMode(g_common_pin, a);
Serial.print(a);
Serial.print(" Load_cell 2 output val: ");
Serial.println(b);
pinMode(g_common_pin, b);
Serial.print(" Load_cell 3 output val: ");
pinMode(g_common_pin, c);
Serial.println(c);
Serial.print(" Load_cell 4 output val: ");
pinMode(g_common_pin, d);
Serial.println(d);
newDataReady = 0;
t = millis();
}
}
// receive command from serial terminal, send 't' to initiate tare operation:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') {
LoadCell_1.tareNoDelay();
LoadCell_2.tareNoDelay();
LoadCell_3.tareNoDelay();
LoadCell_4.tareNoDelay();
}
}
//check if last tare operation is complete
if (LoadCell_1.getTareStatus() == true) {
Serial.println("Tare load cell 1 complete");
}
if (LoadCell_2.getTareStatus() == true) {
Serial.println("Tare load cell 2 complete");
}
if (LoadCell_3.getTareStatus() == true) {
Serial.println("Tare load cell 3 complete");
}
if (LoadCell_4.getTareStatus() == true) {
Serial.println("Tare load cell 4 complete");
}
pinMode(g_common_pin, OUTPUT); // set the initial mode of the common pin.
// This can be changed in loop() for for each channel.
}
How can such problems be dealt? How can I define pins of Mux such that I can give it to ADC hx711. Or is there any other solution for the same?