How to connect HX711 with Multiplexer CD74HC4067

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?

Which Arduino.

There are libraries that share the clock pins of the HX711 (HX711-multi),
so you only need five Arduino pins for four HX711 boards.
Leo..

@Wawa I am using Arduino Uno for the project.

HX711-multi/HX711-multi.ino at master · compugician/HX711-multi · GitHub - This package uses a common clock. But the same problem i have here too. How can i define the pins connected to Mux in the first few lines?

// Pins to the load cell amp
#define CLK A0      // clock pin to the load cell amp
#define DOUT1 A1    // data pin to the first lca
#define DOUT2 A2    // data pin to the second lca
#define DOUT3 A3    // data pin to the third lca

I fail to see your problem.
You already have defined the pins for the four HX711 in post#1
So what are you trying to do with that mux. Switch load cells?
Leo..

1 Like

Hi, @ankitjaiswal1201
Welcome to the forum.

Can you please post a schematic of your project?
Please include power supplies, component names and pin labels.

Are you weighing one object at the same time with the 4 weight scales, or four individual and different masses?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Question, are you trying to use 1 HX711 board with 4 sensors? If that is what you are trying to do.....

  1. Connect one sensor to the HX711 board and get that working the way you want.
  2. Connect all the sensor E+ and E- to the HX711 board.
  3. Connect the A+ and A- to the CD74HC4067

Software function:

  1. Set the Mux input #1
  2. Read the HX711
  3. Set the Mux to input #2
    etc.

Can't. The 4067 is like a single deck rotary switch.
16 to 1 or 1 to 16.
You would need two chips to switch A+ and A-
There are other chips in that family, like the HC4052 (two decks).

But I think OP is trying to use your HX711 boards, not more load cells connected to one board.
In which case he doesn't need a muxer.
Leo..

Ah.... didn't really look into the 4067 :frowning: You are of course correct.

Personally I wouldn't suggest such a setup anyway, just because of the low signal.

If 4 x HX711, I would guess all the clocks could be common and the data on different pins. Would not be difficult to program. One should verify the quantization noise from the "other" HX711's is not a noise issue.

This question piqued my interest only because I am working on a project with a HX711 (my 1st HX711). The ubiquitous ebay HX711 board seems pretty simple.

@Wawa In this code, A1, A2 and A3 are the pins already defined in the code for Arduino Board. But I want this A1, A2 and A3 be replaced by channels of Mux.

Just to give an overview about the project. I have 8 weight scales and 8 Ultrasonic sensor which I want to connect with RaspberryPi.

So my previous circuit for RaspberryPi looked something like this

But as mcp3008 did not work with the weight scale and was suggested to have a microcontroller in the project so decided to have Arduino Uno in the project.

So now to use so many sensors, we needed multiplexer as we cannot connect so many devices together with Arduino due to lack of pins. So when I searched for Analog Multiplexer, I got cd74hc4067 which can be used with hx711 adc.

Now the problem i am facing is, in the sample codes of Hx7111 adc, at the start you give the D-out and clock pins where it is connected to Arduino.

But in my case, the D-out pin is connected to channel 0. So how can I replace A0 pin of Arduino to channel0 of the multiplexer in the sample code. That I am not understanding.

This is how my connection of Hx711 with multiplexer looks like(Just made a short circuit layout). So how can i tell arduino that my hx711 d-out pin is connected to multiplexer instead of A1?

Capture (1)
coud not upload this image in last comment

the way I see here, you need to gently take it step by step, like

starting off first by making sure cd74hc4067 works as It should with your Uno

you can create simple custom functions to read/write from/to the MUX pins like digitalReadMux() and digitalWriteMux()

and If all is good, that's when you can merge the cd74hc4067 code with the HX711 library

you will have to tweak the HX711.cpp (and .h if needed ) files and replace all the digitalRead() and digitalWrite() in it with the newly defined functions you created above ie: digitalReadMux() and digitalWriteMux() which are of course globally declared using macros(#define) or something

Hello @KASSIMSAMJI , I tried a small experiment of potentiometer with cd74hc4067. Adam meyer | Arduino + CD74HC4067 . That worked fine for me. It was just a small and easy experiment.

But i don't know if i can access this multiplexer pins with names and give it to Hx711 or else i will have to tweek .cpp file. I have not worked much with C language so need to see that.

Hi,

Please a schematic, hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

were you able to digitalRead() and digitalWrite() the cd74hc4067 ?

I still don't see the need for a 4067 muxer.
An Uno has enough pins to connect and process up to 17 (seventeen) HX711 boards.

Maybe you think you need analogue pins for the HX711, you don't.
The HX711 outputs a digital signal, and any Uno pin can be used.

I don't know the Rpi (this is an Arduino forum),
but I assume that if you use HX711 boards for 3.3volt processors, then you can connect those also directly to the Rpi. Sparkfun is AFAIK the only supplier of 3.3volt-logic HX711 boards.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.