Having a spare Spark Core doing nothing, it struck me that it would be very easy to pair it up with a large 4 digit 7 segment I2C Adafruit display that I had and make a clock. What's more, because the Spark Core is connected to the Internet via my home network it can get its time from a time server and always be accurate.
To make this build, you will need:
Hardware
To make this build, you will need:
- A Particle Photon or Spark Core
- I2C backpack LED display (Adafruit product ID 878 or 1270)
- Half breadboard
- 2 x 4.7k resistors
- 5 x male to male jumper wires
I used Adafruit's large display (1270) which has an extra pin to the left of the + pin that supplies power for the control logic, separate to the LED power. The breadboard layout below will work for the large display and the smaller display, just make sure that whichever display you use, the yellow lead goes to the C connection of the display.
The displays are also available in other colors if you check Adafruit's website
Software
Go to http://particle.io and select the BUILD option to open the web IDE.
Create a new 'App' and call it Clock.
This project requires the SPARKTIME and ADAFRUIT-LED-BACKPACK LIBRARIES, so click on the libraries button, find each of these libraries in turn and click USE THIS LIBRARY selecting your new Clock app when asked to select the app.
Now you can paste the following code into your App. Note that the includes should already be there if the libraries have been imported correctly.
You will need to change your time zone offset on the last line of setup.
That's it - the display should start as soon as the Photon or Core resets.
#include "SparkTime/SparkTime.h"
#include "adafruit-led-backpack/adafruit-led-backpack.h"
Adafruit_7segment matrix = Adafruit_7segment();
UDP UDPClient;
SparkTime rtc;
unsigned long currentTime;
unsigned long lastTime = 0UL;
String timeStr;
int colon = false;
void setup() {
matrix.begin(0x70);
matrix.setBrightness(15);
rtc.begin(&UDPClient, "north-america.pool.ntp.org");
rtc.setTimeZone(0); // gmt offset
}
void loop() {
currentTime = rtc.now();
int min = rtc.minute(currentTime);
int hour = rtc.hour(currentTime);
matrix.print(hour * 100 + min, DEC);
colon = ! colon;
matrix.drawColon(colon);
matrix.writeDisplay();
delay(500);
}
If you enjoyed making this project, and want to learn more about programming and using the Photon, check out my book on the Photon.
No comments:
Post a Comment