질문게시판 > 아두이노 lcd표시문제

TODAY1,227 TOTAL2,922,663
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 질문게시판 | 아두이노 lcd표시문제

페이지 정보

작성자 아두이노공부해요 작성일2021-12-10 14:38 조회14,036회 댓글4건

본문

	

오픈웨더맵에서 위도경도를 넣고 그 지역의 pm10값이랑 pm25값을 찾아서 수치를 lcd에 나타내야하는데 수치뿐아니라 문자까지 나타내서 숫자만 나타나게 하던가 중간에 짜르는건 어떻게 하나요?

------------------------------------------------------

pm25: (수치) um/m3

pm10: (수치) um/m3

------------------------------------------------------     이렇게 표시하고싶어요

lcd에 표시되는 사진이랑 api로 불러들인 자료사진도 첨부했습니다

코드입니다

#include "WizFi250.h"

#include <SPI.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

 

LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C LCD

 

char ssid[] = "NEXT-2204N PLUS";    // your network SSID (name)

char pass[] = "39853985";          // your network password

int status = WL_IDLE_STATUS;       // the Wifi radio's status

 

//Ubidots information

#define lat     "35.19" //위도

#define ion     "128.1" //경도

#define appid   "564900d0968f0885f60f9b7e68482c74"

 

 

 

//Hardware Pin status

 

char server[] = "api.openweathermap.org";

 

boolean readingVal;

boolean readingVal1;

boolean viewData;

boolean getIsConnected = false;

String pm25;

String pm10;

 

String rcvbuf;

 

 

// Initialize the Ethernet client object

WiFiClient client;

 

void httpRequest();

void printWifiStatus();

 

void setup()

{

  // initialize serial for debugging

  Serial.begin(115200);

  Serial.println(F("\r\nSerial Init"));

  pinMode(7, INPUT_PULLUP);

  pinMode(6, INPUT_PULLUP);

  pinMode(5, OUTPUT);

  

  lcd.init();

  lcd.backlight(); 

  lcd.print(" pm Info System ");

  lcd.setCursor(0, 1);

  lcd.print(" pm10, pm25 ");

 

  WiFi.init();

 

  // check for the presence of the shield

  if (WiFi.status() == WL_NO_SHIELD) {

    Serial.println("WiFi shield not present");

    // don't continue

    while (true);

  }

 

  // attempt to connect to WiFi network

  while ( status != WL_CONNECTED) {

    Serial.print("Attempting to connect to WPA SSID: ");

    Serial.println(ssid);

    // Connect to WPA/WPA2 network

    status = WiFi.begin(ssid, pass);

  }

 

  Serial.println("You're connected to the network");

 

  printWifiStatus();

}

 

void loop() {

  // if there's incoming data from the net connection send it out the serial port

  // this is for debugging purposes only

  while (client.available()) {

    digitalWrite(5,HIGH); //led on

    char c = client.read();

    if ( c != NULL ) {

      if (rcvbuf.length() > 80)

        rcvbuf = "";

      rcvbuf += c;

      Serial.write(c);

       if (rcvbuf.endsWith("\"pm2_5\":")) {

        readingVal = true;

        pm25= "";

      }

      else if (rcvbuf.endsWith("\"pm10\":")) {

        readingVal1 = true;

        pm10= "";

      }

      if (readingVal) 

        dataParser(c, pm25, readingVal);

 

      else if (readingVal1) 

        dataParser(c, pm10, readingVal1);

 

    }

    digitalWrite(5,LOW);  //LED OFF

  }

 

  //if (millis() - lastConnectionTime > postingInterval) {

  if (!digitalRead(7)) {

    httpRequest();

  }

  if (!digitalRead(6)) {

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print(" Daejeon ");

    lcd.setCursor(0, 1);

    lcd.print(" pm25 pm10 info ");

    delay(5000);

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print("pm25:");

    lcd.print(pm25);

    lcd.print("ug/m3 ");

    lcd.setCursor(0, 1);

    lcd.print("pm10:");

    lcd.print(pm10);

    lcd.print("ug/m3 ");

    delay(5000);

  }

  rcvbuf = "";

}

   

 

// this method makes a HTTP connection to the server

void httpRequest() {

  Serial.println();

 

  // close any connection before send a new request

  // this will free the socket on the WiFi shield

  client.stop();

 

  // if there's a successful connection

  if (client.connect(server, 80)) {

    Serial.println("Connecting...");

 

    // send the HTTP PUT request

    client.print(F("GET /data/2.5/air_pollution?lat="));

    client.print(lat);

    client.print(F("&lon="));

    client.print(ion);

    client.print(F("&appid="));

    client.print(appid);

    client.print(F(" HTTP/1.1\r\n"));

    client.print(F("Host: api.openweathermap.org\r\n"));

    client.print(F("Connection: close\r\n"));

    client.print(F("\r\n\r\n"));

 

  }

  else {

    // if you couldn't make a connection

    Serial.println("Connection failed");

  }

}

 

 

void printWifiStatus() {

  // print the SSID of the network you're attached to

  Serial.print("SSID: ");

  Serial.println(WiFi.SSID());

 

  // print your WiFi shield's IP address

  IPAddress ip = WiFi.localIP();

  Serial.print("IP Address: ");

  Serial.println(ip);

 

  // print the received signal strength

  long rssi = WiFi.RSSI();

  Serial.print("Signal strength (RSSI):");

  Serial.print(rssi);

  Serial.println(" dBm");

}

 

void dataParser(char c, String &data, boolean &b) {

  if (c != '<') {

    if (c != '>')

      data += c;

  }

  else {

    b = false;

  }

  

 

}

  • BASIC4MCU 작성글 SNS에 공유하기
  • 페이스북으로 보내기
  • 트위터로 보내기
  • 구글플러스로 보내기

댓글 4

조회수 14,036

master님의 댓글

master 작성일

void parsing() {
  String announce_time; int tm_start= line0.indexOf(F("<tm>")); // "<tm>"문자가 시작되는 인덱스 값('<'의 인덱스)을 반환한다.
  int tm_end= line0.indexOf(F("</tm>"));
  announce_time = line0.substring(tm_start + 4, tm_end); // +4: "<tm>"스트링의 크기 4바이트, 4칸 이동
https://postpop.tistory.com/86
위 링크를 보면 문자열과 문자열 사이의 문자를 파싱하는 예가 있습니다.
만약 컴마 전까지 파싱하고 싶다면
  int tm_end= line0.indexOf(F(","));
이렇게 변경하면 되겠죠

아두이노공부해요님의 댓글

아두이노공부해요 댓글의 댓글 작성일

글을 늦게봐서 답변을 늦게 달았습니다.
블로그도 보고 저 line0 부분을 pm25로 바꾸고 해도 잘되지않아 어떻게 고쳐야 하는지 자세히 알려주실수 있을까요?
void parsing() {
  String pm25; int tm_start= pm25.indexOf(F("\"pm2_5\":"));
  int tm_end= pm25.indexOf(F(","));
  String pm10; int hour_start= pm10.indexOf(F("\"pm10\":"));
  int hour_end= pm10.indexOf(F(",")); }
고치기는 이렇게 고쳐봤습니다만...

master님의 댓글

master 댓글의 댓글 작성일

동일한 경험이 없어서 조언을 드리지 못합니다.
보통 코드를 완전히 이해하면 수정이나 디버깅을 할 수 있게 됩니다.

아두이노공부해요님의 댓글

아두이노공부해요 댓글의 댓글 작성일

알겠습니다 제가 아직 초보라 조금더 천천히 보면서 공부해보겠습니다. 알려주셔서 감사합니다

질문게시판HOME > 질문게시판 목록

MCU, AVR, 아두이노 등 전자공학에 관련된 질문을 무료회원가입 후 작성해주시면 전문가가 답변해드립니다.
ATMEGA128PWMLED초음파
아두이노AVR블루투스LCD
UART모터적외선ATMEGA
전체 스위치 센서
질문게시판 목록
제목 작성자 작성일 조회
질문 LCD에 숫자 표기법을 바꾸고 싶습니댓글[2] Bs드리프터 23-09-19 121
질문 아두이노 lcd 디지털시계 (도와주시면 감사하겠습니다!)댓글[1] 이미지첨부파일 김리 23-06-11 550
질문 아두이노 LCD 글자 출력질문입니다. Tell 23-06-10 475
답변 답변글 답변 : 아두이노 LCD 글자 출력질문입니다. master 23-06-10 436
질문 아두이노 lcd 문자 스크롤디스플레이 wnion 23-05-31 451
답변 답변글 답변 : 아두이노 lcd 문자 스크롤디스플레이댓글[1] master 23-05-31 507
질문 앱인벤터 아두이노 보드 LCD 글씨 나타내기 질문댓글[7] 이미지 당찬병아리 23-05-29 867
질문 토양습도센서 이용시LCD 오류댓글[5] 윤던 23-05-23 990
질문 LCD 부저연결질문입니다.댓글[1] Tell 23-05-19 440
질문 세그먼트 lcd출력질문입니다.댓글[1] Tell 23-05-19 439
질문 lcd 화면에 글자가 안보이네요댓글[7] 이미지 황룡수색 23-05-19 1521
질문 lcd 모니터를 내려서 표기하댓글[5] 수포자 23-04-06 1546
질문 아두이노 a4988 스텝모터 + LCD 모니터 + 미세먼지 센서 (GP2Y1014AU0F) 이미지 JCHJ 22-12-15 1431
답변 답변글 답변 : 아두이노 a4988 스텝모터 + LCD 모니터 + 미세먼지 센서 (GP2Y1014AU0F)댓글[2] master 22-12-15 3061
질문 아두이노 심박센서 및 LCD로 BPM나타내기 질문있습니다.댓글[2] 이미지첨부파일 공백 22-12-12 2589
질문 (MCU) LCD와 인터럭트궁금한 부분이있어 질문드립니다댓글[1] 권철숙 22-12-03 1048
질문 ATMEGA128 가변저항을 이용해 값을 LCD로 받고싶습니다.댓글[1] 납땜마스터 22-12-01 1918
질문 Atmega128 가변저항을 이용해 lcd에 설정값 띄우기 납땜마스터 22-12-01 1612
답변 답변글 답변 : Atmega128 가변저항을 이용해 lcd에 설정값 띄우기 master 22-12-01 1959
질문 USART를 이용한 LCD출력댓글[2] 이름두글자 22-11-29 1956
질문 stm32 tft(LCD) ILI9341 문제점 조언댓글[3] 첨부파일 지산동괴물쥐 22-11-26 3478
질문 LED, LCD, 버튼, 부저 0922tjdus 22-11-24 2442
답변 답변글 답변 : LED, LCD, 버튼, 부저 master 22-11-24 1698
질문 아두이노 우노 압력센서 LCD 코딩 문제댓글[16] 이미지첨부파일 또혀이 22-11-18 29175
답변 답변글 답변 : 아두이노 우노 압력센서 LCD 코딩 문제 이미지 master 22-11-19 1987
질문 인터럽트 활성화시 LCD 오류 발생 마프하나 22-11-16 1846
답변 답변글 답변 : 인터럽트 활성화시 LCD 오류 발생 master 22-11-17 1438
질문 3x4 키패드를 이용한 LCD 계산기 코딩 질문입니다.댓글[1] 첨부파일 LCDnoob 22-11-16 2904
질문 Lcd실드 모듈 연결해서 lcd만 사용할 수 있나요?댓글[2] 이미지첨부파일 떼잉 22-11-13 2651
질문 아두이노 lcd 오류 질문댓글[2] 이미지첨부파일 아두이노진구 22-11-11 3173
게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기