HX711 Changing Sample Rate Advanced Info

preview_player
Показать описание
How to customize the sample rate in 2 different ways. Bonus tip about changing the rate with a digital pin. How I discoved a missing ground link on the HX711 board used in video.

The code used in the video is below, copy and paste into a blank sketch in Arduino IDE or similar. Unfortunately Youtube won't allow greater than symbol near end of code so you will need to replace it in the IDE. Just try to compile the code and it will find it for you.

//Timer and PWM setup works for Uno or Nano only (ATmega328P)
#include "HX711.h"

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4; //Can be another pin
const int LOADCELL_SCK_PIN = 5; //Can be another pin
const int RATE = 8;

HX711 scale;

long reading;
unsigned long previousMillis = 0;
int counter = 0;
int sampleTime = 0;
float samplePerSec = 0;
bool rate = 0;

void setup() {
//Set up PWM on pin 3
TCCR2A = bit(COM2A1) | bit(COM2B1) | bit(WGM21) | bit(WGM20);
TCCR2B = bit(WGM22) | bit(CS20);
OCR2A = 2; // 14 for 1MHz min recommended, 1 for 8MHz
OCR2B = 1; // half of OCR2A for 50% duty, 0 for 8MHz
pinMode(3, OUTPUT); // Output pin 3 for OCR2B connected to XI via 20pF capacitor
pinMode(RATE, OUTPUT); //Change sample rate with pin 8
digitalWrite(RATE, LOW); //set HX711 sample rate to slow
}

void loop() {
counter ++;
}
if (counter == 10) { // average over 10 samples can be changed for high or low sample rates but change value 4 lines below from 10000.0
counter = 0;
sampleTime = millis() - previousMillis;
previousMillis = millis();
samplePerSec = 10000.0 / sampleTime; // 10000 = 1000 x counter

digitalWrite(RATE, rate);
}
}
}
Рекомендации по теме
Комментарии
Автор

Hey mate, you really saved my skin. Thanks to your video I was able to change the SPS of my HX711 and can now take high-frequency readings with my thrust-test-station. :D

nlywatching
Автор

Please tell if i use long wires between load cell and HX711 what capacitor or amplification system has to be done to HX711 ?

GURU_
Автор

I'm curious if you have noticed any change in accuracy with using faster or slower sampling rates?

bfgillan
Автор

Thank You very much for this, wonderful explanation, I am also doing a project related to hx711 for knowing the viscosity of concrete. This will help me .if you would like I can send you the experiment . It would be great to get some knowledge from your experience. by the way I am the 399, 400, 401 subscriber . (hehe) for your channel
as your video is helping me currently at my part-time job as a student in a small company.

AnkitPal-lstz
Автор

Thanks for the informational video!
Two questions though:
I can't seem to find any crystal oscillators with 3 pins, only 2 pin ones. Could you provide a link to one in the description? Or would it work to buy a 2 pin one and connect it to 13 & 14 pins skipping the ground?
Also what frequency oscillator are you using? New to this, sorry if it's a stupid question.

NNLegaL
Автор

I tried to use a 22.1184mhz crystal (on a customized break board) and got 160hz, the output rate formula on page 3 in the datasheet.

zhaojia
Автор

Thanks Ed R. Great video. Is there any way to get a 0-5v output from these hx711? I have build a load cell from strain gauges and want to make a pressure sensitive gear stick for my car.

Turbesky
Автор

Hi Ed, if I have a premade board with pads "rate". It does not matter if I brisge those or not, rate remains 10hz, pin 15 is low. Would you, as a HX711 expert, know what I am doing wrong? Its a Jopto CJMCU-711. I would be so happy if you xould help?

willywodka
Автор

hey,
I would like to use the PWM on Pin 3 to change the sample rate. Do you have an explanation for this?
best regards

DennisRauh
Автор

Not sure If I missed something. Is there any issue using the onboard oscillator for sampling with the rate pin grounded for slow sampling or pulled high for faster sampling?

bfgillan
Автор

Hi is there any way where I can find applied voltage and output voltage from HX711 on loading with different loads in python programming.

sapsan
Автор

I'll try all your connections because I can't get stable values from neither of mine different 4 load cells and five similar hx711 chips... tried many things, but not even close to stability we can se in Bacon's or Indrek's tutorials... :(

MegaFurka