標(biāo)題: arduino小型體重稱hx711程序 [打印本頁]

作者: 怎末回事    時(shí)間: 2020-2-16 15:57
標(biāo)題: arduino小型體重稱hx711程序
ardino制作,簡單體重計(jì),使用壓力傳感器,通過公式轉(zhuǎn)換,串口顯示數(shù)據(jù)。
  1. #include "hx711.h"

  2. #define ValueGap 630
  3. //該數(shù)值可用砝碼校準(zhǔn)

  4. long HX711_Buffer = 0;
  5. long Weight_Maopi = 0,Weight_Shiwu = 0;

  6. //****************************************************
  7. //初始化HX711
  8. //****************************************************
  9. void Init_Hx711()
  10. {
  11.         pinMode(HX711_SCK, OUTPUT);       
  12.         pinMode(HX711_DT, INPUT);
  13. }


  14. //****************************************************
  15. //獲取毛皮重量
  16. //****************************************************
  17. void Get_Maopi()
  18. {
  19.         Weight_Maopi = HX711_Read();               
  20. }

  21. //****************************************************
  22. //稱重
  23. //****************************************************
  24. unsigned int Get_Weight()
  25. {
  26.         HX711_Buffer = HX711_Read();

  27.         Weight_Shiwu = HX711_Buffer;
  28.         Weight_Shiwu = Weight_Shiwu - Weight_Maopi;                                //獲取實(shí)物的AD采樣數(shù)值。
  29.        
  30.         Weight_Shiwu = (int)((float)Weight_Shiwu/ValueGap+0.05);        

  31.         return Weight_Shiwu;
  32. }

  33. //****************************************************
  34. //讀取HX711
  35. //****************************************************
  36. unsigned long HX711_Read(void)        //增益128
  37. {
  38.         unsigned long count;
  39.         unsigned char i;
  40.         bool Flag = 0;

  41.         digitalWrite(HX711_DT, HIGH);
  42.         delayMicroseconds(1);

  43.         digitalWrite(HX711_SCK, LOW);
  44.         delayMicroseconds(1);

  45.           count=0;
  46.           while(digitalRead(HX711_DT));
  47.           for(i=0;i<24;i++)
  48.         {
  49.                   digitalWrite(HX711_SCK, HIGH);
  50.                 delayMicroseconds(1);
  51.                   count=count<<1;
  52.                 digitalWrite(HX711_SCK, LOW);
  53.                 delayMicroseconds(1);
  54.                   if(digitalRead(HX711_DT))
  55.                         count++;
  56.         }
  57.         digitalWrite(HX711_SCK, HIGH);
  58.         delayMicroseconds(1);
  59.         digitalWrite(HX711_SCK, LOW);
  60.         delayMicroseconds(1);
  61.         count ^= 0x800000;
  62.         return(count);
  63. }
復(fù)制代碼


體重秤.zip

4.28 KB, 下載次數(shù): 18, 下載積分: 黑幣 -5


作者: 畫地為牢qy    時(shí)間: 2020-5-11 20:26
怎么校準(zhǔn)




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1