HX711 board not outputting 80hz

Hi everyone,

I am trying to get 80hz data rate from my load cell using a HX711 board. I have moved the 0 ohms resister from the 10hz side to the 80hz side. However when I run my code I am getting around 12hz.

Wiring diagram:

Code:

#include "HX711.h"

int State;
HX711 scale;
unsigned long start = 0;
unsigned long duration = 1000;
unsigned long cell_warmup = 5000;

void setup() {
  pinMode(3,INPUT);//button
  pinMode(7,INPUT);//button
  pinMode(2,OUTPUT);//LED (high = off, low = on)
  scale.begin(9,10);//load cell
  Serial.begin(115200);
}

void loop() {
  State = digitalRead(3);
    if(State==1){
      digitalWrite(2,HIGH);
      scale.tare();
      delay(cell_warmup);
      digitalWrite(2,LOW);

      unsigned long time = millis();
        while(millis()-time < duration){
          if(scale.is_ready()){
          float weight = scale.get_units(1);
          Serial.println(weight);
        }}}
    else{
      unsigned long time = millis();
      digitalWrite(2,HIGH);
    }
}

Is the problem hardware or code related?
I have also run code with the scale.get_units() outside of the loop and that runs much faster. (see picture below)

Are there faster methods of updating the information coming from the load cell than "float weight = scale.get_units(1);", this part seems to be my limiting factor.

Any help would be much appreciated.

Noah

code

Likely the "Serial.println(weight); line. Comment it out and increment a variable for every read. Use the millis() time to measure how much time for say 320 readings. Then print out that time.

1 Like

Hi JohnRob,

I have seen this suggested in other post about similar problems. I do not know how to code this (I am still a beginner). Could you give me a suggestion as to how I should code it?

Thanks for you help,

Noah

Is this the sort of thing you mean?

#include "HX711.h"

int State;
HX711 scale;
unsigned long start = 0;
unsigned long duration = 1000;
unsigned long cell_warmup = 5000;
unsigned long v1;
unsigned long v2;
unsigned long v3;
unsigned long v4;
unsigned long v5;
unsigned long v6;
unsigned long v7;
unsigned long v8;
unsigned long v9;
unsigned long v10;

void setup() {
  pinMode(3,INPUT);//button
  pinMode(7,INPUT);//button
  pinMode(2,OUTPUT);//LED (high = off, low = on)
  scale.begin(9,10);//load cell
  //scale.set_scale(calibrationFactor);
  Serial.begin(115200);
}

void loop() {
  State = digitalRead(3);
    if(State==1){
      digitalWrite(2,HIGH);
      scale.tare();
      delay(cell_warmup);
      digitalWrite(2,LOW);

      unsigned long time = millis();
        while(millis()-time < duration){
          if(scale.is_ready()){
          v1 = scale.get_units(1);
          v2 = scale.get_units(1);
          v3 = scale.get_units(1);
          v4 = scale.get_units(1);
          v5 = scale.get_units(1);
          v6 = scale.get_units(1);
          v7 = scale.get_units(1);
          v8 = scale.get_units(1);
          v9 = scale.get_units(1);
          v10 = scale.get_units(1);
          Serial.println(v1);
          Serial.println(v2);
          Serial.println(v3);
          Serial.println(v4);
          Serial.println(v5);
          Serial.println(v6);
          Serial.println(v7);
          Serial.println(v8);
          Serial.println(v9);
          Serial.println(v10);
        }}}
    else{
      unsigned long time = millis();
      digitalWrite(2,HIGH);
    }
}

Close but not quite.

The below is quasi code (you will have to add some formatting.

  1. create an array of say 100 uint32
  2. if scale is ready
int j = 0;
while millis() - time < duration{
       scale.get_uints = array(j);
   };
Serial.print(j);

at this point you know the duration of the while loop and the printed "j" will give you the number of readings you were able to collect in that duration.

So what is your final goal? Your initial post stated you were not getting the full 80 Hz advertised. What is your plan for data coming in at 80Hz?

BTW you will get better data at the 10Hz rate.

1 Like

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