안녕하세요. 최근 아두이노로 처음 코딩이라는것을 작업하고 있는데
잘 안되는 부분이 있어서 문의드립니다.
아두이노나노
액정 ILI9341 SPI모드
센서 DHT22, CO2(아날로그), CO(아날로그), PMS7003(UART) 붙여서 액정에 나오게 하고있어요.
PMS값이 보이지 않아요.
PMS만 단독으로 시리얼모니터로 동작확인은 되는데
LCD만 붙이면 PMS데이터가 0으로 나와요.
검색해도 찾기가 어려워 문의드립니다.
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include
#include "PMS.h"
#include
SoftwareSerial mySerial(7, 6);
PMS pms(mySerial);
PMS::DATA data;
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
#define DHT22_PIN 5
float _humidity=0;
float _temperature = 0;
int co2=0;
int co=0;
char chHumidity[10];
char chTemperature[10];
uint8_t progress = 0;
//char chco2[10];
dht DHT;
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
void printText(char *str, uint16_t pos_x = 0, uint16_t pos_y = 0, uint16_t color = ILI9341_WHITE, uint16_t sz = 1);
void printValue(float value, uint16_t pos_x = 0, uint16_t pos_y = 0, uint16_t color = ILI9341_WHITE, uint16_t sz = 1);
void delValue();
void setup() {
Serial.begin(115200);
mySerial.begin(9600);
Serial.println("ILI9341 Test!");
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setRotation(1);
// printText("sensor test.", 0, 0, ILI9341_WHITE, 2);
}
void loop(void) {
/* static int CheckFirst=0;
static int pm_add[3][5]={0,};
static int pm_old[3]={0,};
int chksum=0,res=0;;
unsigned char pms[32]={0,};
if(mySerial.available()>=32){
for(int j=0; j<32 ; j++){
pms[j]=mySerial.read();
if(j<30)
chksum+=pms[j];
}
if(pms[30] != (unsigned char)(chksum>>8)
|| pms[31]!= (unsigned char)(chksum) ){
return res;
}
if(pms[0]!=0x42 || pms[1]!=0x4d )
return res;
Serial.print("Dust raw data debugging : ");
Serial.print("1.0ug/m3:");
Serial.print(pms[10]);
Serial.print(pms[11]);
Serial.print(" ");
Serial.print("2.5ug/m3:");
Serial.print(pms[12]);
Serial.print(pms[13]);
Serial.print(" ");
Serial.print("10ug/m3:");
Serial.print(pms[14]);
Serial.println(pms[15]);
} */
//if (pms.read(data))
//{
Serial.print("PM 1.0 (ug/m3): ");
Serial.println(data.PM_AE_UG_1_0);
//Serial.print(" \n");
Serial.print("PM 2.5 (ug/m3): ");
Serial.println(data.PM_AE_UG_2_5);
Serial.print("PM 10.0 (ug/m3): ");
Serial.println(data.PM_AE_UG_10_0);
Serial.println();
//}
DHT.read22(DHT22_PIN);
_humidity = DHT.humidity;
_temperature = DHT.temperature;
// tft.setRotation(1);
// testText();
co2=analogRead(0);
co=analogRead(1);
Serial.println(_humidity);
Serial.println(_temperature);
Serial.println(analogRead(0));
Serial.println(analogRead(1));
/* Serial.println(chHumidity[0]);
Serial.println(chHumidity[1]);
Serial.println(chHumidity[2]);
Serial.println(chHumidity[3]);
Serial.println(chHumidity[4]);
Serial.println(chHumidity[5]);
Serial.println(chHumidity[6]);
Serial.println(chHumidity[7]);
Serial.println(chHumidity[8]);
Serial.println(chHumidity[9]);*/
Serial.println();
printText("Hum: ", 0, 0, ILI9341_YELLOW, 2);
dtostrf(_humidity, 4, 1, chHumidity);
printText(chHumidity, 60, 0, ILI9341_YELLOW, 2);
printText("%", 110, 0, ILI9341_YELLOW, 2);
printText("Temp: ", 0, 25, ILI9341_YELLOW, 2);
dtostrf(_temperature, 4, 1, chTemperature);
printText(chTemperature, 60, 25, ILI9341_YELLOW, 2);
printText("*C", 110, 25, ILI9341_YELLOW, 2);
printText("CO2: ", 0, 50, ILI9341_YELLOW, 2);
printValue(co2, 60, 50, ILI9341_YELLOW, 2);
//dtostrf(co2, 3, 0, chco2);
// printText(chco2, 150, 90, ILI9341_YELLOW, 3);
printText("CO: ", 0, 75, ILI9341_YELLOW, 2);
printValue(co, 60, 75, ILI9341_YELLOW, 2);
delay(1000);
printText(chHumidity, 60, 0, ILI9341_BLACK, 2);
printText(chTemperature, 60, 25, ILI9341_BLACK, 2);
// printText(chco2, 150, 90, ILI9341_BLACK, 3);
printValue(co2, 60, 50, ILI9341_BLACK, 2);
printValue(co, 60, 75, ILI9341_BLACK, 2);
// }
}
void printText(char *str, uint16_t pos_x = 0, uint16_t pos_y = 0, uint16_t color = ILI9341_WHITE, uint16_t sz = 1) {
tft.setCursor(pos_x, pos_y);
tft.setTextColor(color);
tft.setTextSize(sz);
tft.println(str);
}
void printValue(float value, uint16_t pos_x = 0, uint16_t pos_y = 0, uint16_t color = ILI9341_WHITE, uint16_t sz = 1) {
tft.setCursor(pos_x, pos_y);
tft.setTextColor(color);
tft.setTextSize(sz);
tft.println(int(value));
}
도와주시면 감사하겠습니다.
|