さあ始まりました第一回コピペで作ろう簡単Arduino企画!
今回の目標
GPSモジュール+LCDモジュール+Arduinoで"ほぼ正確な"時計・速度計・高度計を作ること
使用するパーツ
半田付け必須の模様です。
配 線
Arduino---I2Cモジュール--[はんだ付け]--1602A LCD
5V(3.3V)---VCC
GND---GND
SCL---SDA
A5---SCL
Arduino---NEO6M
5V(3.3V)---VCC
GND---GND
D2---TX
D3---RX
スケッチ(ライブラリー等は予めインストールお願いします)
static const int RXPin = 2, TXPin = 3; //NEO 6Mstatic const uint32_t SerialSpeed = 9600;static const uint32_t GPSSpeed = 9600;int GPSdelay(1000);int year, month, day, hour, minute, second;#include <TinyGPS++.h>TinyGPSPlus gps;#include <SoftwareSerial.h>SoftwareSerial ss(RXPin, TXPin);#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x27, 16 , 2); // 0x27のアドレス,16列2行のLCDを使用void setup(){ Serial.begin(SerialSpeed); ss.begin(GPSSpeed); lcd.init(); // LCDの初期化 lcd.backlight(); // LCDバックライトの点灯 lcd.setCursor(0, 0); // カーソルの位置を指定 lcd.print("GPS Start"); // 文字の表示 lcd.setCursor(1, 1); // カーソルの位置を指定 lcd.print("With Arduino."); delay(500); /* How to Connection Arduino---I2C 1602A LCD 5V(3.3V)---VCC GND---GND SCL---SDA A5---SCL Arduino---NEO6M 5V(3.3V)---VCC GND---GND D2---TX D3---RX */}void loop(){ lcd.setCursor(0, 0); showtime(); lcd.setCursor(0, 1); showkmph(); showaltitude(); smartDelay(GPSdelay);}void showtime() //時刻表示{ lcd.clear(); // get date and time year = gps.date.year() - 2000; month = gps.date.month(); day = gps.date.day(); hour = gps.time.hour(); minute = gps.time.minute(); second = gps.time.second(); hour += 9;// GUTC+9h=JST if (hour >= 24) { day += hour / 24; hour = hour % 24; } lcd.setCursor(0, 0); lcd.print(year); lcd.print("/"); lcd.print(month); lcd.print("/"); lcd.print(day); lcd.print(" "); lcd.print(hour); lcd.print(":"); lcd.print(minute); lcd.print(":"); lcd.print(second);}void showkmph() //進行速度表示{ lcd.print((int)gps.speed.kmph()); lcd.print("km/h ");}void showaltitude() //高度表示{ lcd.print(gps.altitude.meters()); lcd.print("m");}static void smartDelay(unsigned long ms){ unsigned long start = millis(); do { while (ss.available()) gps.encode(ss.read()); } while (millis() - start < ms);}
まとめ
I2Cモジュールのバックライトジャンパーピンを抵抗に置き換えればバックライトの調整が効くのではないかと思います。