hx711库函数arduino
扫描二维码
随时随地手机看文章
HX711模块是内置信号放大的24位有符号差分模/数(A/D)转换模块。它内置了最大128倍增益,能够把微小的信号(几mV)进行量化。HX711有2路通道(A通道与B通道),通信过程简单,但是采样率比较低(10Hz/80Hz),广泛应用于电子秤等使用应变片进行压力或拉力测量场所。
HX711的输入电路以桥式电路为主,经典芯片外围电路如下图所示:
HX711模块给的实例程序大部分是51单片机的程序,博主对此进行了翻译,写出了HX711的Arduino驱动程序,以下为程序内容:
uint8_t HX_SCK = D3;
uint8_t HX_DT = D4;
long count0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(HX_SCK, OUTPUT);
pinMode(HX_DT, INPUT);
ReadCount();
delay(100);
count0 = 0;
for(int i=0; i<8; i++)
count0 += ReadCount();
count0 /= 8;
}
void loop() {
// put your main code here, to run repeatedly:
long count = ReadCount() - count0;
Serial.println(count);
delay(100);
}
long ReadCount()
{
digitalWrite(HX_SCK, LOW);
while(digitalRead(HX_DT));
unsigned long count = 0;
for(int i=0; i<24; i++)
{
digitalWrite(HX_SCK, HIGH);
count <<= 1;
digitalWrite(HX_SCK, LOW);
if(digitalRead(HX_DT)) count |= 1;
}
digitalWrite(HX_SCK, HIGH);
if(count & 0x00800000) count |= 0xFF000000;
digitalWrite(HX_SCK, LOW);
return (long)count;
}