안녕하세요
제가 기상관측기기와 관련하여 공개한 소스코드엔 lcd 사용한 경우가 없으며 header 파일을 빼고 공개한적이 없습니다. LCD는 기상관측기기와 무관하므로
아두이노 관련 커뮤니티 사이트나 아두이노 공식페이지에서 찾아보시면 LCD 관련 라이브러리를 다운로드 받으실수 있습니다. 코딩과 관련하여 저희가 도움을 드리지는 못하는점 양해부탁드립니다.
---------- Original Message ----------
저희가 학교에서 프로젝트를 하는데 기상대로 결정해 이번에 구입하여
저희가 풍향 풍속계를 아두이노로 돌려 시리얼모니터로 측정까지는 다 완료했는데
그 풍향 풍속 측정값에서 LCD로 표현할려고하는데 헤더 파일 h가 가 없다고 치명적 오류라고 뜨는데
혹시 헤더파일(h)좀 올려주시면 감사하겠습니다.
우선 아두이노 온습도먼지 기상대 합친파일을 올려놓으테니 확인좀해주세요.
#include
int pin=7;
DHT11 dht11(pin);
#include
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 3000;//sampe 3s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
#define WIND_N 0 //정 북향
#define WIND_NNE 22.5
#define WIND_NE 45
#define WIND_ENE 67.5
#define WIND_E 90 //정 동향
#define WIND_ESE 112.5
#define WIND_SE 135
#define WIND_SSE 157.5
#define WIND_S 180
#define WIND_SSW 202.5
#define WIND_SW 225
#define WIND_WSW 247.5
#define WIND_W 270
#define WIND_WNW 292.5
#define WIND_NW 315
#define WIND_NNW 337.5
// char msg[100] = "";/
int windVanePin = A0; // 아날로그 0번핀에 연결
int winVaneValue = 0; //
float windSpeed = 0;
float rainGauge = 0;
float windDirection = 0;
char windName[4]; // N (North) S South, NS(north south) NNS(north north south)
unsigned long windSpeedTimer;
int windSpeedState = true;
int windSpeedPin = 2;
int windSpeedCounter = 0;
unsigned long rainGaugeTimer;
int rainGaugeState = true;
int rainGaugePin = 3;
int rainGaugeCounter = 0;
void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop() {
int err;
float temp, humi;
if((err=dht11.read(humi, temp))==0)
{
Serial.print("temperature:");
Serial.print(temp);
Serial.print(" humidity:");
Serial.print(humi);
Serial.println();
}
else
{
Serial.println();
Serial.print("Error No :");
Serial.print(err);
Serial.println();
}
lcd.setCursor(0, 0);
lcd.print("Temp = C ");
lcd.setCursor(0, 1); // 첫번째 칸, 두번째 줄
lcd.print("Humi = % ");
lcd.setCursor(8, 0); // 8번째 칸, 첫번째 줄
lcd.print(temp);
lcd.setCursor(8, 1); // 8번째 칸, 두번째 줄
lcd.print(humi);
delay(5000); // DHT11_RETRY_DELAY); //delay for reread
lcd.setCursor(0, 1);
lcd.print(" ");
pin = 8;
Serial.begin(9600);
pinMode(8, INPUT);
starttime = millis();//get the current time;
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy + duration;
//if ((millis() - starttime) > sampletime_ms) //if the sampel time == 30s
{
ratio = lowpulseoccupancy / (sampletime_ms * 10.0); // Integer percentage 0=>100
concentration = 1.1 * pow(ratio, 3) - 3.8 * pow(ratio, 2) + 520 * ratio + 0.62; // using spec sheet curve
Serial.print("concentration = ");
Serial.print(concentration);
Serial.println("pcs/0.01cf");
Serial.println("\n");
lowpulseoccupancy = 0;
starttime = millis();
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
// print the number of seconds since reset:
lcd.print("concentration : ");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(concentration);
lcd.setCursor(6, 1);
lcd.print("pcs/0.01cf");
delay(5000);
//wind speed sensor
pinMode(windSpeedPin, INPUT);
digitalWrite( windSpeedPin, HIGH);
//rain gauge sensor
pinMode(rainGaugePin, INPUT);
digitalWrite( rainGaugePin, HIGH);
}
void printChars(char *msg, int len){
if(len == 0) return;
for(int i=0; i Serial.print( msg[i]);
Serial.println();
}
int f2h( float num){
return int(num);
}
int f2p( float num){
return (num - int(num)) * 100;
}
windSpeedTimer = millis() + 3000; // 10초를 주기로 반복됩니다.
windSpeedCounter = 0;
while( millis() < windSpeedTimer ){
delay(20); //20ms 주기로 센서의 스위칭을 감지합니다.
//wind speed 풍속계 센서 감지부
if( (windSpeedState == true ) && !digitalRead( windSpeedPin) ){
windSpeedCounter++; //스위치 상태가 high에서 low로 떨어지는 순간을 감지합니다.
windSpeedState = false;
}else if( (windSpeedState == false) && digitalRead(windSpeedPin) ){
windSpeedState = true;
}
//rain gauge
if( (rainGaugeState == true ) && !digitalRead( rainGaugePin) ){
rainGaugeCounter++; //스위치 상태가 high에서 low로 떨어지는 순간을 감지합니다.
rainGaugeState = false;
}else if( (rainGaugeState == false) && digitalRead(rainGaugePin) ){
rainGaugeState = true;
}
}
rainGaugeTimer++;
if( rainGaugeTimer > 1){// 10초 * 360 = 3600초(1시간) 지난 1시간동안 누적한 강수계 카운터로 강수량 계산
rainGauge = rainGaugeCounter * 0.2794;
rainGaugeCounter = 0;
rainGaugeTimer = 0;
}
windSpeed = windSpeedCounter * 0.24 ; // 1초당 1회 스위칭시 2.4km/h 속력이며 10초 기간이므로 0.24가 됨
getWindDirection(); // 풍향은 발표시점에 1회만 측정
//char 배열에 정보를 취합(인터넷 전송에 적합한 자료형)
sprintf( msg, "ArtRobot's Weather Bot said => Wind: %s/%d.%d, %d.%d(km/h) Rain %d.%d(mm/h).", windName, f2h(windDirection), f2p(windDirection), f2h(windSpeed), f2p(windSpeed), f2h(rainGauge), f2p(rainGauge) );
printChars( msg, sizeof(msg) ); //PC에서 참고용으로 시리얼전송
//이후 소개할 예제에서 위 자료를 이더넷을 통해 트위터에 포스팅하게됨
}
float getWindDirection(void){
int readValue = analogRead(windVanePin);
// 0~1023 사이의 입력값을 0~5V 기준 값으로 비례변경함.
winVaneValue = map(readValue, 0, 1023, 0, 500);
//이제 winVaneValue는 데이타 시트정보상의 방위별 전압치와 유사한 값이 됩니다.
if( winVaneValue < 35){
//0~0.35V를 동동서 로 인식함
// 112.5 0.32v (31 32) 0~35
windDirection = WIND_ESE;
strcpy(windName ,"ESE");
}else if( winVaneValue < 43 ){
// 67.5 0.41v(40 41) ~42
windDirection = WIND_ENE;
strcpy(windName , "ENE");
}else if( winVaneValue < 50 ){
// 90 0.45v(44 45) ~50
windDirection = WIND_E;
strcpy(windName , "E");
}else if( winVaneValue < 70 ){
// 157.5 0.62v(60 62) ~70
windDirection = WIND_SSE;
strcpy(windName , "SSE");
}else if( winVaneValue < 100 ){
// 135 0.90v(89 90) ~100
windDirection = WIND_SE;
strcpy(windName , "SE");
}else if( winVaneValue < 130 ){
// 202.5 1.19v(119 120) ~130
windDirection = WIND_SSW;
strcpy(windName , "SSW");
}else if( winVaneValue < 170 ){
// 180 1.40v(140 141) ~170
windDirection = WIND_S;
strcpy(windName , "S");
}else if( winVaneValue < 210 ){
// 22.5 1.98v(198 199) ~210
windDirection = WIND_NNE;
strcpy(windName , "NNE");
}else if( winVaneValue < 250 ){
// 45 2.25v(226 227) ~250
windDirection = WIND_NE;
strcpy(windName , "NE");
}else if( winVaneValue < 300 ){
// 247.5 2.93v(293 294) ~300
windDirection = WIND_WSW;
strcpy(windName , "WSW");
}else if( winVaneValue < 320 ){
// 225 3.08v(308 310) ~320
windDirection = WIND_SW;
strcpy(windName , "SW");
}else if( winVaneValue < 360 ){
// 337.5 3.43 (343 345) ~360
windDirection = WIND_NNW;
strcpy(windName , "NNW");
}else if( winVaneValue < 395 ){
// 0 3.84v(384~385) ~395
windDirection = WIND_N;
strcpy(windName , "N");
}else if( winVaneValue < 415 ){
// 292.5 4.04v(405 406) ~415
windDirection = WIND_WNW;
strcpy(windName , "WNW");
}else if( winVaneValue < 450 ){
// 315 4.34(433 434) ~450
windDirection = WIND_NW;
strcpy(windName , "NW");
}else if( winVaneValue < 490 ){
// 270 4.62v(461 463) ~490
windDirection = WIND_W;
strcpy(windName , "W");
}else{
//error 알수없는 값범위
}
lcd.setCursor(0, 0);
lcd.print("wind =");
lcd.setCursor(7, 0);
lcd.print( msg[i]);
delay(5000);
}
회원에게만 댓글 작성 권한이 있습니다.