hx711庫(kù)函數(shù)arduino
HX711模塊是內(nèi)置信號(hào)放大的24位有符號(hào)差分模/數(shù)(A/D)轉(zhuǎn)換模塊。它內(nèi)置了最大128倍增益,能夠把微小的信號(hào)(幾mV)進(jìn)行量化。HX711有2路通道(A通道與B通道),通信過(guò)程簡(jiǎn)單,但是采樣率比較低(10Hz/80Hz),廣泛應(yīng)用于電子秤等使用應(yīng)變片進(jìn)行壓力或拉力測(cè)量場(chǎng)所。
HX711的輸入電路以橋式電路為主,經(jīng)典芯片外圍電路如下圖所示:
HX711模塊給的實(shí)例程序大部分是51單片機(jī)的程序,博主對(duì)此進(jìn)行了翻譯,寫(xiě)出了HX711的Arduino驅(qū)動(dòng)程序,以下為程序內(nèi)容:
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;
}