HX711 amp with load cell

Hi-
I am pretty new to Arduino and need some help. I am making a tensile tester device using 2 UNO boards.
One board is controlling the stepper motor which controls the force gantry. The other board controls the rotary encoder and load cell. I used two boards because I cannot get a smooth movement in the stepper with the two sensors in the loop.

Here is my issue - the read rate on the HX711 and analog pins are really slow...like one sample per second slow through the serial monitor. I have increase the baud rate and it doesn't seem to do anything. I have found some very complicated code to change clock speed on board, etc...it's honestly a little beyond me still.

Am I using the wrong amp entirely? Is there some simple code to increase sample rate? Do you think this is due to using the rotary encoder in the same loop? Can I connect the HX711 to digital pins.

Please any help would be greatly appreciated - sample code especially. I will return the favor to forum some day!!! Thanks.

You can try the following codes:

Setup:
Arduino UNO
HX711 Module
GND -----> GND
Vcc ------> 5V
DT -------> A1
SCLK ----> A0

E+ -------> Load Cell +
E- --------> Load Cell -

A+ -------> Load Cell Output +
A- --------> Load Cell Output -

Codes:

/* This program takes 10 samples from LC + HX711 at
   1-sec interval and then computes the average. Gain and offset have been manually calculated to get the response equation: y = mx + C and then weight has been measured and displayed*/

unsigned long x = 0, y=0;
unsigned long dataArray[10];
int j = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(A1, INPUT); //data line  //Yellow cable
  pinMode(A0, OUTPUT);  //SCK line  //Orange cable
}

void loop()
{

  for (int j = 0; j < 10; j++)
  {
    digitalWrite(A0, LOW);//SCK is made LL
    while (digitalRead(A1) != LOW) //wait until Data Line goes LOW
      ;
    {
      for (int i = 0; i < 24; i++)  //read 24-bit data from HX711
      {
        clk();      //generate CLK pulse to get MSB-it at A1-pin
        bitWrite(x, 0, digitalRead(A1));
        x = x << 1;
      }
      clk();
      Serial.println(x, HEX);
      y = x;
      x = 0;
      delay(1000);
    }
    dataArray[j] = y;
  }

  Serial.println("===averaging process=========");
  unsigned long sum = 0;

  for (j = 0; j < 10; j++)
  {
    sum += dataArray[j];
  }
  Serial.print("Average Count = ");
  sum = sum / 10;
  Serial.println(sum, HEX);
  float W = (float)0.005331 * sum - 1146.176;
  W = (float)W / 1000.00; 
  Serial.println(W, 3);
}

void clk()
{
  digitalWrite(A0, HIGH);
  digitalWrite(A0, LOW);
}

You should be able to get a minimum of 10 samples per second and up to 80 samples per second with the HX711. Read the HX711 documentation or google how to get 80 (has nothing to do with "complicated code"). It has been discussed many times on this forum.

If you are only getting one sample per second, and not at least 10, it probably has something to do with your code, which you neglected to show us.

You should be able to do your project with one Arduino.

sorry - I uploaded my code, I didn't post it. Here it is:

#include "hx711.h"

// Tensile Tester Code ver. 106 09/10/18
//IMPORTANT - set baud rate to 57600 on monitor for correct speed interp.

// Load cell below
// Hx711.DAT - pin #A1
// Hx711.CLK - pin #A2

Hx711 scale(A1, A2);

// Rotary encoder code below
// Red - 5V
// Black - GND
const int encoder_a = 2; // Green - pin 2 - Digital
const int encoder_b = 3; // White - pin 3 - Digital
long encoder = 0;

void setup()
{

Serial.begin(57600);

//encoder code below
pinMode(encoder_a, INPUT_PULLUP);
pinMode(encoder_b, INPUT_PULLUP);

}
void loop (){

attachInterrupt(0, encoderPinChangeA, CHANGE);
attachInterrupt(1, encoderPinChangeB, CHANGE);

}

void encoderPinChangeA() {
encoder += digitalRead(encoder_a) == digitalRead(encoder_b) ? -1 : 10;
}

void encoderPinChangeB() {
encoder += digitalRead(encoder_a) != digitalRead(encoder_b) ? -1 : 10;
Serial.println(encoder);

Serial.print(scale.getGram(), 2);
Serial.println("gm");

}

This is my code when trying the stepper, rotary encoder and load cell all on one board. I get a very slow loop of 1 step, 1 reading from the rotary and 1 load cell count...but they are 1sec apart, way too slow. Out of desperation I increased my baud rate to max.

#include <Stepper.h>
#include "hx711.h"

// Tensile Tester Code ver. 106 09/10/18
//IMPORTANT - set baud rate to 2000000 on monitor for correct speed interp.

// Load cell below
// Hx711.DAT - pin #A1
// Hx711.CLK - pin #A2

Hx711 scale(A1, A2);

// Stepper below
int steps;
int Speed;
Stepper stepper(200, 8, 9, 10, 11);

// Rotary encoder code below
// Red - 5V
// Black - GND
const int encoder_a = 2; // Green - pin 2 - Digital
const int encoder_b = 3; // White - pin 3 - Digital
long encoder = 0;

void setup()
{
while (!Serial);

Serial.begin(2000000);

//encoder code below
pinMode(encoder_a, INPUT_PULLUP);
pinMode(encoder_b, INPUT_PULLUP);

}
void loop (){

attachInterrupt(0, encoderPinChangeA, CHANGE);
attachInterrupt(1, encoderPinChangeB, CHANGE);

Serial.println("Gantry speed 1-100 "); //Prompt User for Input
while (Serial.available()==0){ } //Wait for User Input
Speed = Serial.parseInt(); //Read User Input

Serial.println("Gantry travel UP 10-2800 or - FOR DOWN "); //Prompt User for Input
while (Serial.available()==0){ } //Wait for Input
steps = Serial.parseInt(); //Read User Input

stepper.setSpeed(Speed);
stepper.step(steps);

}

void encoderPinChangeA() {
encoder += digitalRead(encoder_a) == digitalRead(encoder_b) ? -1 : 1;
}

void encoderPinChangeB() {
encoder += digitalRead(encoder_a) != digitalRead(encoder_b) ? -1 : 1;
Serial.println(encoder);

Serial.print(scale.getGram(), 2);
Serial.println(" gm");

}

One problem is that you are using blocking functions. Go to the Programming Questions subforum, click on the second link "Useful links...," and study the two serial input posts in the Communications section.

Another is that you are using Serial.print in an ISR. Read this: Gammon Forum : Electronics : Microprocessors : Interrupts

Hi,

I know this is an old discussion, but in case you are looking, the attached TIFF shows a fix to the Tension compression problem with the INA125 using the 5V from an Arduino Nano (can use other Arduino boards). Basically you use a HX711 for the load cell excitation and tie the -E to the psuedogroud on the INA125.

If you do not use an LCD, you can get millis output.