아두이노(arduino)로 자동차 ODB2를 통해 자동차 속도 표시하기 - (2부 구현편)
최초 구상과는 달리 7세그먼트 대신에 OLED를 사용하기로 했습니다. 그런데 이게 0.96인치 OLED라 화면이 좁쌀만합니다.
7세그먼트를 사용하는것도 괜찮을것 같고 전 1.3인치 OLED를 알리로 주문해 놓았습니다.
2.3인치대의 OLED로 있는데, 이건 가격이 거의 2만원정도해서 너무 거금(?)입니다.
아두이노와 OLED 배선은 아래 사진처럼 하면 됩니다.
출처 : https://startingelectronics.org/tutorials/arduino/modules/OLED-128x64-I2C-display/
ODB2의 차속신호는 13번핀으로 입력을 넣어 주었습니다.
전체적인 배선이 사진처럼 되는대요, 단 사진이 위 그림의 배선과 다른이유는 아두이노 리셋 스위치 옆의 두개 핀이 SDA, CLK 핀이어서 전 여기 꽂았습니다.
아두이노를 뒤집에 보시면 SDA, CLK 핀을 확인하실 수 있습니다.
하드웨어 연결은 이게 끝입니다.
그러면 바로 소스코드를 보도록 하겠습니다.
#include "U8glib.h" U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC unsigned long timeHigh; // pulsein에 high로 들어오는 시간값 unsigned long timeLow; //pulsein에 low로 들어오는 시간값 unsigned long time1Cycle; // 위 두값을 더한 1pulse 시간값 float frequency; // 1 pulse시간값으로 구한 주파수 int carSpeed; // 주파수로 산출한 차량속도 void setup(void) { Serial.begin(9600); pinMode(13, INPUT); // 차속신호를 받기위한 디지털입력 } void loop(void) { String str; Char speed[3]; timeHigh = pulseIn(13, HIGH); timeLow = pulseIn(13, LOW); time1Cycle = timeHigh + timeLow; // 펄스 1개의 전체 시간을 구함 frequency = 1000000 / time1Cycle; // 펄스 1개의 시간값으로 주파수 구하기 carSpeed = round(frequency * 1.47); // 1.47을 곱해서 속도 구한 후 정수값으로 저장 (이건 차량마다 다를수 있음) str = String(carSpeed); // int 속도값을 char[]값으로 형변환 str.toCharArray(speed, 3); u8g.firstPage(); // 액정에 표시 do { u8g.drawStr(0, 20, speed); } while( u8g.nextPage() ); delayMicroseconds(100); } |
소스를 아두이노에 업로드 하고 테스트 주행을 하였습니다.
(영상이 기울여지게 촬영됬네요)
영상에 보시면 큰 숫자는 제가 비교하려고 장착해 놓은 HUD숫자이고 RPM게이지 X1000 숫자 위로 보이는 작은 숫자가 속도신호값을 주파수로 변환하여 표시하고 있는 숫자입니다.
영상을 보면 차이는 있지만 속도와 비례하여 주파수값이 상승하는 것을 볼 수 있습니다.
이 주행하면서 비교를 해보니 차량이 약 100KM로 주행할때 속도신호값의 주파수는 대략 68정도가 나왔습니다.
그러면 주파수 값으로 속도를 산출하려면 대략 1.47을 곱해주면 된다는 결론이 나오게 됩니다. (100/68)
그래서 주파수 값이 1.47을 곱하여 속도값으로 산출 하여 OLED에 뿌려주면 이젠 속도 값으로 표시가 되는 것입니다.
이렇게 해서 기본적인 동작을 완성하였습니다.
그런데 가뜩이나 작은 액정인데 숫자까지 작아서 가독성이 떨어집니다.
숫자를 이미지로 표시하도록 코드를 수정하여 완성하였습니다.
최종 결과물은 영상과 같이 동작하는 속도계가 만들어졌습니다.
핵심 코드는 몇줄 안되는데, OLED에 숫자 표시하는 코드가 들아가니 좀 복잡해 보입니다.
아래는 전체 코드인데, 위에 핵심코드만 이해했다면 아래 이미지 표시부분은 개인의 취향에 따라 보기 좋게 표시하면 될듯합니다.
이미지로 숫자를 표현한 전체 코드는 아래를 참고하세요.
#include "U8glib.h" U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK); // Display which does not send AC unsigned long timeHigh; // pulsein에 high로 들어오는 시간값 unsigned long timeLow; //pulsein에 low로 들어오는 시간값 unsigned long time1Cycle; // 위 두값을 더한 1pulse 시간값 float frequency; // 1 pulse시간값으로 구한 주파수 int carSpeed; // 주파수로 산출한 차량속도 // 여기부터는 0부터 9까지의 숫자 이미지 비트맵 값 const unsigned char digit0[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x03,0xff,0xff,0xff,0xc0, 0x03,0xff,0xff,0xff,0xf0, 0x0f,0xff,0xff,0xff,0xf0, 0x0f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x03,0xf8, 0x1f,0xe0,0x00,0x0f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x0f,0xff,0xff,0xff,0xf0, 0x07,0xff,0xff,0xff,0xf0, 0x07,0xff,0xff,0xff,0xf0, 0x03,0xff,0xff,0xff,0xe0, 0x00,0xff,0xff,0xff,0x80, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit1[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x01,0xff,0xfc,0x00,0x00, 0x03,0xff,0xfe,0x00,0x00, 0x03,0xff,0xff,0x00,0x00, 0x03,0xff,0xff,0x00,0x00, 0x03,0xff,0xff,0x00,0x00, 0x03,0xff,0xff,0x00,0x00, 0x01,0xff,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x00,0x00, 0x00,0x00,0xff,0x80,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x00,0x00,0xff,0xc0,0x00, 0x07,0xff,0xff,0xff,0xf0, 0x0f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x0f,0xff,0xff,0xff,0xf0, 0x07,0xff,0xff,0xff,0xe0, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit2[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x07,0xff,0xff,0xff,0xc0, 0x0f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x0f,0xff,0xff,0xff,0xf8, 0x07,0xff,0xff,0xff,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x01,0xf8, 0x0f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xf0,0x00,0x00,0x00, 0x1f,0xf0,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xff,0xff,0xff,0xfe, 0x1f,0xff,0xff,0xff,0xff, 0x1f,0xff,0xff,0xff,0xff, 0x0f,0xff,0xff,0xff,0xff, 0x0f,0xff,0xff,0xff,0xff, 0x07,0xff,0xff,0xff,0xff, 0x03,0xff,0xff,0xff,0xff, 0x01,0xff,0xff,0xff,0xfc, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit3[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x1f,0xff,0xff,0xff,0x80, 0x3f,0xff,0xff,0xff,0xc0, 0x3f,0xff,0xff,0xff,0xe0, 0x3f,0xff,0xff,0xff,0xe0, 0x3f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x3f,0xff,0xff,0xff,0xf0, 0x3f,0xff,0xff,0xff,0xf0, 0x3f,0xff,0xff,0xff,0xf0, 0x3f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xf8, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xc0, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit4[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x1e,0x00,0x00,0x03,0xe0, 0x3f,0x00,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0x80,0x00,0x07,0xe0, 0x7f,0xff,0xff,0xff,0xe0, 0x7f,0xff,0xff,0xff,0xe0, 0x7f,0xff,0xff,0xff,0xe0, 0x7f,0xff,0xff,0xff,0xe0, 0x7f,0xff,0xff,0xff,0xe0, 0x7f,0xff,0xff,0xff,0xe0, 0x3f,0xff,0xff,0xff,0xe0, 0x1f,0xff,0xff,0xff,0xe0, 0x00,0x00,0x00,0x07,0xe0, 0x00,0x00,0x00,0x07,0xe0, 0x00,0x00,0x00,0x07,0xe0, 0x00,0x00,0x00,0x07,0xe0, 0x00,0x00,0x00,0x07,0xe0, 0x00,0x00,0x00,0x07,0xe0, 0x00,0x00,0x00,0x07,0xe0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xfc, 0x00,0x00,0x00,0x07,0xfc, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x07,0xfe, 0x00,0x00,0x00,0x03,0xfc, 0x00,0x00,0x00,0x01,0xf8, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit5[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x03,0xff,0xff,0xff,0xfe, 0x0f,0xff,0xff,0xff,0xfe, 0x1f,0xff,0xff,0xff,0xff, 0x1f,0xff,0xff,0xff,0xff, 0x1f,0xff,0xff,0xff,0xfe, 0x1f,0xff,0xff,0xff,0xfe, 0x1f,0xff,0xff,0xff,0xfe, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0x80,0x00,0x00,0x00, 0x1f,0x80,0x00,0x00,0x00, 0x1f,0x80,0x00,0x00,0x00, 0x1f,0x80,0x00,0x00,0x00, 0x1f,0x80,0x00,0x00,0x00, 0x1f,0xff,0xff,0xff,0xc0, 0x1f,0xff,0xff,0xff,0xe0, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x0f,0xff,0xff,0xff,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x00,0x00,0x00,0x07,0xf8, 0x0f,0xff,0xff,0xff,0xf8, 0x0f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xe0, 0x1f,0xff,0xff,0xff,0xe0, 0x0f,0xff,0xff,0xff,0xc0, 0x0f,0xff,0xff,0xff,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit6[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x0f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xf8,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xc0,0x00,0x00,0x00, 0x1f,0xc0,0x00,0x00,0x00, 0x1f,0xc0,0x00,0x00,0x00, 0x1f,0xc0,0x00,0x00,0x00, 0x1f,0xc0,0x00,0x00,0x00, 0x1f,0xc0,0x00,0x00,0x00, 0x1f,0xe0,0x00,0x00,0x00, 0x1f,0xff,0xff,0xff,0xc0, 0x1f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xe0,0x00,0x03,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x01,0xfc, 0x1f,0xc0,0x00,0x03,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf0, 0x0f,0xff,0xff,0xff,0xe0, 0x03,0xff,0xff,0xff,0x80, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit7[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x1f,0xff,0xff,0xff,0x00, 0x3f,0xff,0xff,0xff,0xc0, 0x3f,0xff,0xff,0xff,0xe0, 0x3f,0xff,0xff,0xff,0xf0, 0x3f,0xff,0xff,0xff,0xf0, 0x3f,0xff,0xff,0xff,0xf0, 0x1f,0xff,0xff,0xff,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x3f,0xf0, 0x00,0x00,0x00,0x1f,0xf0, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x07,0xf0, 0x00,0x00,0x00,0x03,0xe0, 0x00,0x00,0x00,0x01,0xc0, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit8[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x01,0xff,0xff,0xff,0xf8, 0x03,0xff,0xff,0xff,0xf8, 0x0f,0xff,0xff,0xff,0xf8, 0x0f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xe0,0x00,0x01,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x1f,0xe0,0x00,0x03,0xf8, 0x1f,0xe0,0x00,0x0f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x1f,0xe0,0x00,0x1f,0xf8, 0x3f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xe0,0x00,0x1f,0xf8, 0x7f,0xf0,0x00,0x1f,0xf8, 0x7f,0xff,0xff,0xff,0xf8, 0x7f,0xff,0xff,0xff,0xf8, 0x7f,0xff,0xff,0xff,0xf8, 0x3f,0xff,0xff,0xff,0xf8, 0x3f,0xff,0xff,0xff,0xf8, 0x3f,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xf8, 0x07,0xff,0xff,0xff,0xf0, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit9[] PROGMEM = { 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x03,0xff,0xff,0xff,0xf0, 0x07,0xff,0xff,0xff,0xf8, 0x1f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xc0,0x00,0x03,0xfc, 0x3f,0xe0,0x00,0x03,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x3f,0xff,0xff,0xff,0xfc, 0x1f,0xff,0xff,0xff,0xfc, 0x0f,0xff,0xff,0xff,0xfc, 0x07,0xff,0xff,0xff,0xfc, 0x03,0xff,0xff,0xff,0xfc, 0x00,0x00,0x00,0x07,0xfc, 0x00,0x00,0x00,0x03,0xfc, 0x00,0x00,0x00,0x03,0xfc, 0x00,0x00,0x00,0x03,0xfc, 0x00,0x00,0x00,0x03,0xfc, 0x00,0x00,0x00,0x03,0xfc, 0x00,0x00,0x00,0x03,0xfc, 0x00,0x00,0x00,0x07,0xfc, 0x00,0x00,0x00,0x0f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xfc, 0x00,0x00,0x00,0x1f,0xf8, 0x00,0x00,0x00,0x1f,0xf8, 0x00,0x00,0x00,0x0f,0xf0, 0x00,0x00,0x00,0x0f,0xe0, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; const unsigned char digit10[] PROGMEM = { // 이건 백의자리, 십의자리에 빈화면을 출력하기 위한 그냥 비어있는 이미지 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00 }; void draw(int posit, int digit) { if (posit == 1) { switch (digit) { case 0: u8g.drawBitmapP(0, 0, 5, 64, digit0); break; case 1: u8g.drawBitmapP(0, 0, 5, 64, digit1); break; case 2: u8g.drawBitmapP(0, 0, 5, 64, digit2); break; case 3: u8g.drawBitmapP(0, 0, 5, 64, digit3); break; case 4: u8g.drawBitmapP(0, 0, 5, 64, digit4); break; case 5: u8g.drawBitmapP(0, 0, 5, 64, digit5); break; case 6: u8g.drawBitmapP(0, 0, 5, 64, digit6); break; case 7: u8g.drawBitmapP(0, 0, 5, 64, digit7); break; case 8: u8g.drawBitmapP(0, 0, 5, 64, digit8); break; case 9: u8g.drawBitmapP(0, 0, 5, 64, digit9); break; case 10: u8g.drawBitmapP(0, 0, 5, 64, digit10); break; } } else if (posit == 2) { switch (digit) { case 0: u8g.drawBitmapP(44, 0, 5, 64, digit0); break; case 1: u8g.drawBitmapP(44, 0, 5, 64, digit1); break; case 2: u8g.drawBitmapP(44, 0, 5, 64, digit2); break; case 3: u8g.drawBitmapP(44, 0, 5, 64, digit3); break; case 4: u8g.drawBitmapP(44, 0, 5, 64, digit4); break; case 5: u8g.drawBitmapP(44, 0, 5, 64, digit5); break; case 6: u8g.drawBitmapP(44, 0, 5, 64, digit6); break; case 7: u8g.drawBitmapP(44, 0, 5, 64, digit7); break; case 8: u8g.drawBitmapP(44, 0, 5, 64, digit8); break; case 9: u8g.drawBitmapP(44, 0, 5, 64, digit9); break; case 10: u8g.drawBitmapP(44, 0, 5, 64, digit10); break; } } else if (posit == 3) { switch (digit) { case 0: u8g.drawBitmapP(88, 0, 5, 64, digit0); break; case 1: u8g.drawBitmapP(88, 0, 5, 64, digit1); break; case 2: u8g.drawBitmapP(88, 0, 5, 64, digit2); break; case 3: u8g.drawBitmapP(88, 0, 5, 64, digit3); break; case 4: u8g.drawBitmapP(88, 0, 5, 64, digit4); break; case 5: u8g.drawBitmapP(88, 0, 5, 64, digit5); break; case 6: u8g.drawBitmapP(88, 0, 5, 64, digit6); break; case 7: u8g.drawBitmapP(88, 0, 5, 64, digit7); break; case 8: u8g.drawBitmapP(88, 0, 5, 64, digit8); break; case 9: u8g.drawBitmapP(88, 0, 5, 64, digit9); break; case 10: u8g.drawBitmapP(88, 0, 5, 64, digit10); break; } } } void setup(void) { Serial.begin(9600); pinMode(13, INPUT); // 차속신호를 받기위한 디지털입력 } void loop(void) { int digit1 = 10; int digit2 = 10; int digit3 = 10; timeHigh = pulseIn(13, HIGH); timeLow = pulseIn(13, LOW); time1Cycle = timeHigh + timeLow; frequency = 1000000 / time1Cycle; // 주파수 구하기 if (frequency < 150) // 차량이 정차중일때 파형이 없어 frequency값이 65535가 나오기 때문에 체크하여 0으로 설정 carSpeed = round(frequency * 1.47); //1.47은 주파수와 속도 동기를 위한 상수값 (100km 주행시 주파수가 68이었음) else carSpeed = 0; if (carSpeed >= 100) { digit1 = carSpeed / 100; // 백 자리숫자 구하기 digit2 = (carSpeed - 100) / 10; // 십 자리숫자 구하기 digit3 = (carSpeed - 100) % 10; // 일 자리숫자 구하기 } else if (carSpeed >= 10 && carSpeed <= 99) { digit1 = 10; // 아무 숫자도 표시되지 않게 빈 이미지 출력 digit2 = carSpeed / 10; // 10의 자리숫자 구하기 digit3 = carSpeed % 10; // 1의 자리숫자 구하기 } else { digit1 = 10; digit2 = 10; digit3 = carSpeed; } u8g.firstPage(); do { draw(1, digit1); draw(2, digit2); draw(3, digit3); } while( u8g.nextPage() ); delayMicroseconds(100); } |
참고로 위에 숫자표시에 사용된 이미지는 아래 이미지입니다.
나름 엣지 있는 폰트로 찾아서 사이즈 조정해서 만든 숫자 이미지입니다.
이런방식으로 RPM 게이지도 구현이 가능한데, 그건 나중에 시간나면 함 해보려고 합니다.
그리고 이것을 GPS로 구현하려고도 생각했었습니다.
그러면 배선도 더 간단할 텐데요, GPS로 구현할때 한가지 단점이 있습니다.
터널이나 지하구간을 주행할때 GPS신호를 수신하지 못해 속도가 표시 안된다는 것입니다.
그래서 GPS로는 구현하지 않았습니다.
대신 GPS로 다른것을 만들어보고 있어서 그것도 완성되면 올려보도록 하겠습니다.
'아두이노' 카테고리의 다른 글
아두이노로 자동차 대시보드를 완성하다 - 3편 (10) | 2019.02.09 |
---|---|
아두이노로 자동차 대시보드를 완성하다 - 2편 (5) | 2019.02.09 |
아두이노로 자동차 대시보드를 완성하다 - 1편 (4) | 2019.02.09 |
3축 지자기장(자이로)센서 GY-273 HMC5883L 제대로 작동하지 않는다면 (0) | 2019.01.11 |
아두이노(arduino)로 자동차 ODB2를 통해 자동차 속도 표시하기 - (1부 구상편) (2) | 2018.12.03 |