// GPS Clock with MAX7219 8x8 display 2019/06/12 << My Spice Cabinet >>
#include <TinyGPS++.h> // Include the TinyGPS++ library
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
TinyGPSPlus tinyGPS; // Create a TinyGPSPlus object
#define GPSBaud 9600 // GPS module baud rate. defaults to 9600
#define ARDUINO_GPS_RX 4 // GPS TX, Arduino RX pin
#define ARDUINO_GPS_TX 3 // GPS RX, Arduino TX pin
SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX);
#define gpsPort ssGPS // Alternatively, use Serial1 on the Leonardo
#define SerialMonitor Serial
const byte PIN_CLK = 13; // define CLK pin (any digital pin)
const byte PIN_DIO = 11; // define DIO pin (any digital pin)
int pinCS = 10; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI )
int numberOfHorizontalDisplays = 4;
int numberOfVerticalDisplays = 1;
int wait = 70; // In milliseconds
int spacer = 1;
int Y0 = 0; // if Y0=0 then
int jpt;
int width = 5 + spacer; // The font width is 5 pixels
char time_value[20];
String s;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);
void setup()
{
gpsPort.begin(GPSBaud);
SerialMonitor.begin(115200);
matrix.setIntensity(10); // Use a value between 0 and 15 for brightness
matrix.setPosition( 0, 3, 0) ; // The first display is at <0, 0>
matrix.setPosition( 1, 2, 0) ; // The second display is at <1, 0>
matrix.setPosition( 2, 1, 0) ; // The third display is at <2, 0>
matrix.setPosition( 3, 0, 0) ; // The fourth display is at <3, 0>
matrix.setRotation(0, 1); // The first display is position upside down
matrix.setRotation(1, 1); // The first display is position upside down
matrix.setRotation(2, 1); // The first display is position upside down
matrix.setRotation(3, 1); // The first display is position upside down
delay(1000);
}
void loop()
{
// print position, altitude, speed, time/date, and satellites:
displayInfo();
// "Smart delay" looks for GPS data while the Arduino's not doing anything else
smartDelay(1000);
}
void displayInfo()
{
// Print latitude, longitude, altitude in feet, course, speed, date, time,
// and the number of visible satellites.
SerialMonitor.print("Lat: "); SerialMonitor.println(tinyGPS.location.lat(), 6);
SerialMonitor.print("Long: "); SerialMonitor.println(tinyGPS.location.lng(), 6);
SerialMonitor.print("Alt: "); SerialMonitor.println(tinyGPS.altitude.feet());
SerialMonitor.print("Course: "); SerialMonitor.println(tinyGPS.course.deg());
SerialMonitor.print("Speed: "); SerialMonitor.println(tinyGPS.speed.mph());
SerialMonitor.print("Date: "); displayDate();
SerialMonitor.print("Time: "); displayTime();
SerialMonitor.print("Sats: "); SerialMonitor.println(tinyGPS.satellites.value());
SerialMonitor.println();
jpt = tinyGPS.time.hour() + 9;
if( jpt >= 24 ) jpt = jpt - 24;
s=String(jpt);
if( s.length() == 1 )
{
s = " " + s;
time_value[0]= s.charAt(0);
time_value[1]= s.charAt(1);
}
else
{
time_value[0]= s.charAt(0);
time_value[1]= s.charAt(1);
}
s=String(tinyGPS.time.minute() );
if( s.length() == 1 )
{
s = "0" + s;
time_value[3]= s.charAt(0);
time_value[4]= s.charAt(1);
}
else
{
time_value[3]= s.charAt(0);
time_value[4]= s.charAt(1);
}
matrix.fillScreen(LOW);
matrix.drawChar( 2, Y0, time_value[0], HIGH,LOW,1);
matrix.drawChar( 8, Y0, time_value[1], HIGH,LOW,1);
// matrix.drawChar(14, Y0, 58, HIGH,LOW,1); // Fixed 58(ASCII Code) = ":"
matrix.drawChar(20, Y0, time_value[3], HIGH,LOW,1);
matrix.drawChar(26, Y0, time_value[4], HIGH,LOW,1);
matrix.write(); // Send bitmap to display
delay(1000);
matrix.drawChar(14,0, 58, HIGH,LOW,1); // blinking 58(ASCII Code) = ":"
matrix.write(); // Send bitmap to display
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
// If data has come in from the GPS module
while (gpsPort.available())
tinyGPS.encode(gpsPort.read()); // Send it to the encode function
// tinyGPS.encode(char) continues to "load" the tinGPS object with new
// data coming in from the GPS module. As full NMEA strings begin to come in
// the tinyGPS library will be able to start parsing them for pertinent info
} while (millis() - start < ms);
}
// printDate() formats the date into dd/mm/yy.
void displayDate()
{
SerialMonitor.print(tinyGPS.date.day());
SerialMonitor.print("/");
SerialMonitor.print(tinyGPS.date.month());
SerialMonitor.print("/");
SerialMonitor.println(tinyGPS.date.year());
}
// printTime() formats the time into "hh:mm:ss", and prints leading 0's
// where they're called for.
void displayTime()
{
SerialMonitor.print(tinyGPS.time.hour()+9);
SerialMonitor.print(":");
if (tinyGPS.time.minute() < 10) SerialMonitor.print('0');
SerialMonitor.print(tinyGPS.time.minute());
SerialMonitor.print(":");
if (tinyGPS.time.second() < 10) SerialMonitor.print('0');
SerialMonitor.println(tinyGPS.time.second());
}
Recent Comments