---------------------------------------------------------------------------------------------------------------------------
구글 - Nodemcu softwareserial 검색
http://www.instructables.com/id/ESP8266-Two-Serial-Ports-With-SoftwareSerial-Libra/
사이트 내 espsoftwareserial 클릭
https://github.com/plerup/espsoftwareserial 에서
Clone or download 클릭 - Download ZIP으로 다운로드
아두이노 실행 - 스케치 - 라이브러리 포함하기 - ZIP 라이브러리추가 - 다운받은 파일 클릭
스케치 - 라이브러리 포함하기 - SoftwareSerial 클릭
새 아두이노 실행 - 파일 - 예제 - SoftwareSerial - swsertest
---------------------------------------------------------------------------------------------------------------------------
https://github.com/ekyuho/sensors/blob/master/sds011_test.ino
--소스코드--
#include <SoftwareSerial.h> | |
SoftwareSerial swSer(D4, 12, false, 256); | |
void setup() { | |
Serial.begin(115200); | |
swSer.begin(9600); | |
Serial.println("\nSoftware serial test started"); | |
} | |
int stat = 1; | |
int cnt = 0; | |
char buf[10]; | |
void loop() { | |
while (swSer.available() > 0) { | |
char c; | |
c = swSer.read(); | |
//Serial.print("stat="+ String(stat) +", "+ "cnt="+ String(cnt) +" "); | |
//Serial.print(c, HEX); | |
//Serial.println(" "); | |
if (stat == 1) { | |
if (c == 0xAA) stat = 2; | |
} else | |
if (stat == 2) { | |
if (c == 0xC0) stat =3; | |
else stat = 1; | |
} else | |
if (stat == 3) { | |
buf[cnt++] = c; | |
if (cnt == 7) stat = 4; | |
} else | |
if (stat == 4) { | |
if (c == 0xAB) { | |
//check checusum | |
stat = 1; | |
} | |
else { | |
Serial.println("Eh? wrong tailer"); | |
} | |
cnt = 0; | |
int pm25 = buf[0] + 256*buf[1]; | |
int pm10 = buf[2] + 256*buf[3]; | |
Serial.print(String(pm25) +","+ String(pm10)+ " "); | |
for (int i=0; i< pm10/10; i++) | |
Serial.print("X"); | |
Serial.println(); | |
} | |
} | |
} |
'kipfa 필기' 카테고리의 다른 글
skt & kt 통신사꿀팁 (0) | 2017.07.15 |
---|---|
0714_먼지센서에서 측정한 값을 Thingspeach에서 그래프로 확인. (0) | 2017.07.14 |
0713_먼지센서 구동_Sketch에서 실행 (0) | 2017.07.13 |
0713_먼지센서(SDS011 Air Quality Sensor) 이용하기 (0) | 2017.07.13 |
0712_HttpRequest 예제(성공) (0) | 2017.07.12 |