BASIC4MCU | 아두이노 | 아두이노 | 아두이노 HX711 - LCD
페이지 정보
작성자 master 작성일2018-03-12 22:14 조회6,245회 댓글0건본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-03-12 오후 10:15:33// by Ok-Hyun Park/*sample for digital weight scale of hx711,display with a HD44780 liquid crtstal monitor*hardware design: syyyd*available at http: //syyyd.taobao.com*library design: Weihong Guan(@aguegu)http: //aguegu.net*library host on https: //github.com/aguegu/Arduino*/// LCD.RS-pin 12// LCD.En-pin 11// LCD.D4-pin 5// LCD.D5-pin 4// LCD.D6-pin 3// LCD.D7-pin 2//// Hx711.DIN-pin#A1// Hx711.SCK-pin#A0//#include <LiquidCrystal.h>//LiquidCrystal lcd(12,11,5,4,3,2);//#define U08 unsigned char#define U32 unsigned long//#define SCK A0#define DIN A1//long offset=0;float scale=742.0;//U32 getValue(){U08 i,j,data[3];while(digitalRead(DIN)); // wait for Readyfor(j=3; j--;){for(i=8; i--;){ digitalWrite(SCK,1); bitWrite(data[j],i,digitalRead(DIN)); digitalWrite(SCK,0); }}digitalWrite(SCK,1); digitalWrite(SCK,0); // 25클럭 // Next Conversion:CH.A,Gain: 128//digitalWrite(SCK,1); digitalWrite(SCK,0); // 26클럭 // Next Conversion:CH.B,Gain: 32//digitalWrite(SCK,1); digitalWrite(SCK,0); // 27클럭 // Next Conversion:CH.B,Gain: 64data[2]^=0x80;return((U32)data[2]<<16)|((U32)data[1]<<8)|(U32)data[0];}//void setOffset(){ offset=getValue(); }void setScale(float s){ scale=s; }//float getGram(U08 times){long val,sum=0; U08 i;for(i=0; i<times; i++)sum+=getValue();sum/=times;val=sum-offset;return(float)val/scale;}//void HX711init(){pinMode(DIN,INPUT);pinMode(SCK,OUTPUT);digitalWrite(SCK,1); delayMicroseconds(100); digitalWrite(SCK,0); // 60us 이상 POWER DOWN 후 Nomal ModesetOffset(); setOffset(); // 2번째 변환 결과로 Offset 적용}//void setup(){lcd.begin(16,2);HX711init();}//void loop(){lcd.setCursor(0,0);lcd.print(getGram(32),1); lcd.print(" g "); // 32번 읽어서 평균 // 소숫점이하 자릿수=1delay(200);}
HX711 라이브러리를 벗겨내서 만들었습니다.
댓글 0
조회수 6,245등록된 댓글이 없습니다.