BASIC4MCU | 질문게시판 | oled 한글 관련 질문
페이지 정보
작성자 iwonder 작성일2021-10-24 20:39 조회2,103회 댓글2건본문
차량에 충격이 가해지면 차량에 충격이 가해졌을 때의 시간을 rtc모듈로, 그때의 위치를 gps모듈로 블루투스 통신으로 전달 받아 어플로 확인하고
차량에 전면부에는 lcd디스플레이를 부착하여 차량번호를 입력하고 후방에는 oled를 부착하여 어플에 입력한 메시지 등을 차량에 남길 수 있도록 하는
앱인벤터로 만든 어플리케이션과 작품을 설계중입니다.
현재 코드를 아래와 같이 작성을 하였고 앱인벤터에서 한글텍스트를 입력하면 후방 oled에 출력할 수 있도록 하는 기능만 남겨놓은 상태입니다.
그런데 앱인벤터에서 한글이 안넘어가는 것인지 oled에서 한글을 인식을 못하는 것인지 잘 이해가 안갑니다.
만약 아두이노 oled에서 한글을 인식을 못하는 것이라면 코드를 어떻게 수정했을 때 입력한 한글값을 이해할 수 있을지 궁금합니다.
현재 oled는 IIC통신을 이용하고 있습니다.
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <core_build_options.h>
#include <swRTC.h>
#include <time.h>
#include<SD.h>
#define SHOCK1 26
#define SHOCK2 28
#define SHOCK3 30
#define SHOCK4 31
#endif
swRTC rtc;
File myFile;
U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int BT_RXD = 10; // 아두이노측 수신부 RXD는 8번핀(HC-06측 송신부 TXD와 연결)
int BT_TXD = 11; // 아두이노측 송신부 TXD는 7번핀(HC-06측 수신부 RXD와 연결)
SoftwareSerial bluetooth(BT_RXD, BT_TXD);
char a = ""; //gps 코드
String str = "";// gpsd 코드
String targetStr = "GPGGA"; // gps 코드
String readString;
String readString1;
char c;
void setup() {
lcd.begin(16,2);
bluetooth.begin(9600);
Serial.begin(9600);
lcd.clear();
u8g2.begin();
u8g2.enableUTF8Print();
pinMode(SHOCK1, INPUT);
pinMode(SHOCK2, INPUT);
pinMode(SHOCK3, INPUT);
pinMode(SHOCK4, INPUT);
rtc.stopRTC();
rtc.setTime(20, 27, 0); //시, 분, 초
rtc.setDate(16, 10, 2021); //일, 월, 년
rtc.startRTC();
Serial3.begin(9600);
}
void loop() {
u8g2.setFont(u8g2_font_unifont_t_korean1);
u8g2.setFontDirection(0);
u8g2.firstPage();
int count = 0;
while(bluetooth.available()){
c = bluetooth.read();
{
readString += c; // 문자인 경우에 더해줌
if(c != 0x23 || c != 0x24)
{
count++;
}
if(count > 16)
{
if(c>=0x20&&c<=0x7F)
{
readString1 += c;
}
}
}
}
if(readString.length()>0){
if(c>='0'&&c<='9')
{
lcd.clear();
lcd.print(readString);
}
if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))
{
do
{
if(count < 17)
{
u8g2.setCursor(0, 15);
u8g2.print(readString);
}
else if(count > 16)
{
u8g2.setCursor(0, 15);
u8g2.print(readString);
u8g2.setCursor(0, 40);
u8g2.print(readString1);
}
} while ( u8g2.nextPage() );
}
if(c == 0x24)
{
myFile = SD.open("shock.txt");
if (myFile) {
delay(3);
while(myFile.available()){
bluetooth.write(myFile.read());
}
}
}
myFile.close();
if(c == 0x23) {
SD.remove("shock.txt");
delay(3);
}
readString="";
readString1="";
}
if (!SD.begin(53)) {
return;
}
/* if(Serial2.available())
{
delay(3);
myFile = SD.open("shock.txt");
if (myFile) {
delay(100);
while(myFile.available()){
Serial2.write(myFile.read());
}
}
myFile.close();
}
*/
if(Serial3.available()) // gps 센서 통신 가능?
{
double LatF;
float LongF;
a=Serial3.read(); // 센서의 값 읽기
if(a == '\n'){ // \n 값인지 구분.
// \n 일시. 지금까지 저장된 str 값이 targetStr과 맞는지 구분
if(targetStr.equals(str.substring(1, 6))){
int first = str.indexOf(",");
int two = str.indexOf(",", first+1);
int three = str.indexOf(",", two+1);
int four = str.indexOf(",", three+1);
int five = str.indexOf(",", four+1);
// Lat과 Long 위치에 있는 값들을 index로 추출
String Lat = str.substring(two+1, three);
String Long = str.substring(four+1, five);
// Lat의 앞값과 뒷값을 구분
String Lat1 = Lat.substring(0, 2);
String Lat2 = Lat.substring(2);
// Long의 앞값과 뒷값을 구분
String Long1 = Long.substring(0, 3);
String Long2 = Long.substring(3);
// 좌표 계산.
LatF = Lat1.toDouble() + Lat2.toDouble()/60;
LongF = Long1.toFloat() + Long2.toFloat()/60;
// 좌표 출력.
// Serial.print("위도 : ");
// Serial.println(LatF, 15);
// Serial.print("경도 : ");
// Serial.println(LongF, 15);
}
// str 값 초기화
str = "";
}else{ // \n 아닐시, str에 문자를 계속 더하기
str += a;
}
if (digitalRead(SHOCK1) == HIGH) {
Serial.println("shock1");
myFile = SD.open("shock.txt",FILE_WRITE);
if(myFile){
myFile.print(rtc.getYear(),DEC);
myFile.print("/");
myFile.print(rtc.getMonth(),DEC);
myFile.print("/");
myFile.print(rtc.getDay(),DEC);
myFile.print("/");
myFile.print(rtc.getHours(),DEC);
myFile.print("/");
myFile.print(rtc.getMinutes(),DEC);
myFile.print("/");
myFile.print(rtc.getSeconds(),DEC);
myFile.print("/");
myFile.println("충격감지1");
myFile.print("위도 : ");
myFile.println(LatF, 15);
myFile.print("경도 : ");
myFile.println(LongF, 15);
myFile.close();
delay(3000);
}
Serial.print(rtc.getYear(),DEC);
Serial.print("/");
Serial.print(rtc.getMonth(),DEC);
Serial.print("/");
Serial.print(rtc.getDay(),DEC);
Serial.print("/");
Serial.print(rtc.getHours(),DEC);
Serial.print("/");
Serial.print(rtc.getMinutes(),DEC);
Serial.print("/");
Serial.print(rtc.getSeconds(),DEC);
Serial.print("/");
Serial.println("충격감지1");
Serial.print("위도 : ");
Serial.println(LatF, 15);
Serial.print("경도 : ");
Serial.println(LongF, 15);
}
else if (digitalRead(SHOCK2) == HIGH) {
Serial.println("shock2");
myFile = SD.open("shock.txt",FILE_WRITE);
if(myFile){
myFile.print(rtc.getYear(),DEC);
myFile.print("/");
myFile.print(rtc.getMonth(),DEC);
myFile.print("/");
myFile.print(rtc.getDay(),DEC);
myFile.print("/");
myFile.print(rtc.getHours(),DEC);
myFile.print("/");
myFile.print(rtc.getMinutes(),DEC);
myFile.print("/");
myFile.print(rtc.getSeconds(),DEC);
myFile.print("/");
myFile.println("충격감지2");
myFile.print("위도 : ");
myFile.println(LatF, 15);
myFile.print("경도 : ");
myFile.println(LongF, 15);
myFile.close();
delay(3000);
}
Serial.print(rtc.getYear(),DEC);
Serial.print("/");
Serial.print(rtc.getMonth(),DEC);
Serial.print("/");
Serial.print(rtc.getDay(),DEC);
Serial.print("/");
Serial.print(rtc.getHours(),DEC);
Serial.print("/");
Serial.print(rtc.getMinutes(),DEC);
Serial.print("/");
Serial.print(rtc.getSeconds(),DEC);
Serial.print("/");
Serial.println("충격감지2");
Serial.print("위도 : ");
Serial.println(LatF, 15);
Serial.print("경도 : ");
Serial.println(LongF, 15);
}
else if (digitalRead(SHOCK3) == HIGH) {
Serial.println("shock3");
myFile = SD.open("shock.txt",FILE_WRITE);
if(myFile){
myFile.println("");
myFile.print(rtc.getYear(),DEC);
myFile.print("/");
myFile.print(rtc.getMonth(),DEC);
myFile.print("/");
myFile.print(rtc.getDay(),DEC);
myFile.print("/");
myFile.print(rtc.getHours(),DEC);
myFile.print("/");
myFile.print(rtc.getMinutes(),DEC);
myFile.print("/");
myFile.print(rtc.getSeconds(),DEC);
myFile.print("/");
myFile.println("충격감지3");
myFile.print("위도 : ");
myFile.println(LatF, 15);
myFile.print("경도 : ");
myFile.println(LongF, 15);
myFile.close();
delay(3000);
}
Serial.print(rtc.getYear(),DEC);
Serial.print("/");
Serial.print(rtc.getMonth(),DEC);
Serial.print("/");
Serial.print(rtc.getDay(),DEC);
Serial.print("/");
Serial.print(rtc.getHours(),DEC);
Serial.print("/");
Serial.print(rtc.getMinutes(),DEC);
Serial.print("/");
Serial.print(rtc.getSeconds(),DEC);
Serial.print("/");
Serial.println("충격감지3");
Serial.print("위도 : ");
Serial.println(LatF, 15);
Serial.print("경도 : ");
Serial.println(LongF, 15);
}
else if (digitalRead(SHOCK4) == HIGH) {
Serial.println("shock4");
myFile = SD.open("shock.txt",FILE_WRITE);
if(myFile){
myFile.print(rtc.getYear(),DEC);
myFile.print("/");
myFile.print(rtc.getMonth(),DEC);
myFile.print("/");
myFile.print(rtc.getDay(),DEC);
myFile.print("/");
myFile.print(rtc.getHours(),DEC);
myFile.print("/");
myFile.print(rtc.getMinutes(),DEC);
myFile.print("/");
myFile.print(rtc.getSeconds(),DEC);
myFile.print("/");
myFile.println("충격감지4");
myFile.print("위도 : ");
myFile.println(LatF, 15);
myFile.print("경도 : ");
myFile.println(LongF, 15);
myFile.close();
delay(3000);
}
Serial.print(rtc.getYear(),DEC);
Serial.print("/");
Serial.print(rtc.getMonth(),DEC);
Serial.print("/");
Serial.print(rtc.getDay(),DEC);
Serial.print("/");
Serial.print(rtc.getHours(),DEC);
Serial.print("/");
Serial.print(rtc.getMinutes(),DEC);
Serial.print("/");
Serial.print(rtc.getSeconds(),DEC);
Serial.print("/");
Serial.println("충격감지4");
Serial.print("위도 : ");
Serial.println(LatF, 15);
Serial.print("경도 : ");
Serial.println(LongF, 15);
}
}
}.
댓글 2
조회수 2,103iwonder님의 댓글
iwonder 작성일
하나만 더 질문 하겠습니다. 이 코드에서 충격이 왔을때의 gps값을 어플로 디스플레이하려고 하는데 gps만 따로 회로에서 떼어내서 측정을 했을때는 문제가 없는데 gps를 회로에 합쳐서 동작했을때는 일정한 값만 뜹니다.
ex )위도 : 2398789.000000
경도 : 0.0000000
gps는 계속 신호를 보내는데 충격이 왔을때 의 gps값만 따려고 해서 문제가 발생한 것일까요??
문제의 원인을 알고 싶습니다.
master님의 댓글
master 작성일
https://www.google.com/search?q=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+OLED+%ED%95%9C%EA%B8%80&oq=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+OLED+%ED%95%9C%EA%B8%80&aqs=chrome..69i57j0i8i30.5488j0j7&sourceid=chrome&ie=UTF-8
한글 예제로 먼저 공부하시고요
GPS값을 읽지 못하면 연속해서 2번 읽어서 2번째 값도 문제가 있는지 체크 해보세요