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.
#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.
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.
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?
The below is quasi code (you will have to add some formatting.
create an array of say 100 uint32
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?