Not Getting Anywhere Near 80 SPS With HX711

Hi All,

I'm a mechanical engineer without much electronics experience so go easy on me :wink:

I'm working on a project that requires reading a load cell and then sending the measurements along with their timestamps to a Python script for live plotting. I've got the load cell communicating with the Arduino, and the Arduino with Python over serial, however I'm having issues getting the sampling rates I would like. I'm using an HX711 board with the 80 SPS modification (checked continuity and the trace that needed to be cut is in fact cut). However, when I run my code on the Arduino I can't get any more than around 10 SPS. I've tried using both normal digital I/O as well as SPI, but it made no difference. I would greatly appreciate any help, I'm frankly at the end of my wits.

(I'm using a Mega 2560)

Here's my code:

#include <Arduino.h>
#include "HX711.h"

const int LOADCELL_DOUT_PIN = 51;
const int LOADCELL_SCK_PIN = 52;

HX711 scale;

void setup() {
  Serial.begin(115200);
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale(-6397.0629);                
  scale.tare();               
}

void loop() {
  
  unsigned long runTime = millis();
  float t = runTime;
  Serial.print(t/1000, 2);
  Serial.print(',');
  Serial.println(scale.get_units(),2);
}

Thanks!

You might try removing the print statements in the "loop". Make some code that reads the loadcell 100 times then print the time it takes.

This will allow you to find your slowest functions

The longer the sketch runs, the greater "t" will become, and thereby take longer to print out - everything adds up.

At 115200 bauds you get roughly 11520 characters out per second

If the HX711 is really spitting out data at 80 Hz you have enough time to print 144 bytes out (assuming no long blocking of interrupts) so I don’t think this is an issue here, the output buffer likely doesn’t fill up and print does not get blocking.

That being said, to play it safe it’s better to tick the box so that the serial monitor adds the time stamp and the arduino does not have to transmit it.

Testing according t suggestion in post 2 would help confirm the mode is correct

I wrote up a bit of code and it showed that it's taking a sample every 100 ms or so without the print delay. I don't understand how this can be the case, when I confirmed there was no continuity after cutting the trace on the HX711 board. I don't think such a drastic reduction in sample rate could be on the Arduino's side though, could it?

Seems it’s stuck at 10Hz then.

Can you share a picture of your board?

Did you read this discussion?

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