filmov
tv
HX711 Changing Sample Rate Advanced Info
Показать описание
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);
}
}
}
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);
}
}
}
Комментарии