gss:cozir:blink:모드_설정_및_co2_값_읽기
모드 설정 및 CO2 값 읽기
모드
Mode | Command | Description | Response |
Command | K 0\r | 명령어 기다리는 상태 | K 00000\r |
Streaming | K 1\r | 연속적으로 값 측정 | K 00001\r |
Polling | K 2\r | 센서 값 요청 시 에만 응답 | K 00002\r |
소스 코드
- 예제 코드는 Test 용도로 사용하길 권장합니다
Streaming mode에서 CO2 값 읽기
- Streaming mode.cpp
#include <SoftwareSerial.h> SoftwareSerial mySerial(12, 13); //Uno Rx Tx (12 13) = SoftwareSerial const char* Streaming_mode = "K 1\r\n"; const char* CO2_read = "Z\r\n"; String str; void setup() { Serial.begin(9600); //시리얼 통신 초기화 delay(140); // POWER ON then Control Interface Setup Time mySerial.begin(9600); Serial.println("GSS Gas sensor read"); mySerial.println(""); // dummy data send mySerial.print(Streaming_mode); delay(100); // Streaming_mode에서 다른 command 전송 시 최대 100ms 필요 mySerial.println("M 4"); // send Mode for Z(filter value) } void loop() { // co2 값 읽기 if(mySerial.available()>=10) { str = ""; str = mySerial.readStringUntil('\n'); Serial.println(str); } }
Polling mode에서 CO2값 읽기
- polling_mode.cpp
#include <SoftwareSerial.h> SoftwareSerial mySerial(12, 13); //Uno Rx Tx (12 13) = SoftwareSerial const char* Polling_mode = "K 2\r\n"; const char* CO2_read = "Z\r\n"; String str; void setup() { Serial.begin(9600); //시리얼 통신 초기화 delay(140); // POWER ON then Control Interface Setup Time mySerial.begin(9600); Serial.println("GSS Gas sensor read"); mySerial.println(""); // dummy data send mySerial.print(Polling_mode); delay(100); mySerial.println("M 4"); // send Mode for Z(filter value) } void loop() { mySerial.print(CO2_read); delay(1000); // co2 값 읽기 if(mySerial.available()>=10) { str = ""; str = mySerial.readStringUntil('\n'); Serial.println(str); } }
gss/cozir/blink/모드_설정_및_co2_값_읽기.txt · 마지막으로 수정됨: 2023/04/03 06:34 저자 mjbang