Here are both code and scheme (last page of the PDF)
It is powered by an AC 220v to AC 12v transformer
The original schematic theory was to use the 50Hz to keep time but it was not working properly, hence the upgrade
On the board there is a step up to 170v DC for the nixies and 5v DC for the PIC/Wemos
Thanks again
Simon
/*
NTP time from here: https://github.com/PaulStoffregen/Time/blob/master/examples/TimeNTP/TimeNTP.ino
*/
#include <ESP8266WiFi.h>
#include <TimeLib.h>
#include <TimeLord.h>
#include <WiFiUdp.h>
#define DEBUG 0
// Arduino pin names for BCD Encoding
#define BCD_A D1 //white
#define BCD_B D2 //grey
#define BCD_C D3 //purple
#define BCD_D D4 //blue
// Arduino pin names for Nixie Enabling
#define Nixie1 D5 //green
#define Nixie2 D6 //yellow
#define Nixie3 D7 //orange
#define Nixie4 D8 //brown
/* Blynk and WiFi operational variables */
char ssid[] = "xxxxx"; // Your WiFi network name.
char pass[] = "xxxxx"; // Your WiFi password.
/* Variables for NTP protocol time sincronization */
char timeServer[] = "time.nist.gov"; // nl.pool.ntp.org maybe also
const int timeZone = 0; // British Time
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
const unsigned long SEVENTY_YEARS = 2208988800UL;
/* network variables */
WiFiUDP Udp;
unsigned int localPort = 8888; // local port to listen for UDP packets
int frequency = 5;
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: "); Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
Serial.print("IP Address: "); Serial.println(WiFi.localIP());
// print the received signal strength:
Serial.print("signal strength (RSSI) dBm: "); Serial.println(WiFi.RSSI());
}
int dstOffset (unsigned long unixTime) {
//Receives unix epoch time and returns seconds of offset for local DST
//Valid thru 2099, Calculations from "http://www.webexhibits.org/daylightsaving/i.html"
//Code idea from jm_wsb @ "http://forum.arduino.cc/index.php/topic,40286.0.html"
//Original code here: http://forum.arduino.cc/index.php?topic=197637.0
//DST update wont be reflected until the next time sync
time_t t = unixTime;
int beginDSTDay = (31 - (4 + year(t) * 5 / 4) % 7);
int beginDSTMonth = 3;
int endDSTDay = (31 - (1 + year(t) * 5 / 4) % 7);
int endDSTMonth = 10;
if (((month(t) > beginDSTMonth) && (month(t) < endDSTMonth))
|| ((month(t) == beginDSTMonth) && (day(t) > beginDSTDay))
|| ((month(t) == beginDSTMonth) && (day(t) == beginDSTDay) && (hour(t) >= 1))
|| ((month(t) == endDSTMonth) && (day(t) < endDSTDay))
|| ((month(t) == endDSTMonth) && (day(t) == endDSTDay) && (hour(t) < 1)))
return (SECS_PER_HOUR); //Add back in one hours worth of seconds - DST in effect
else
return (0); //NonDST
}
// digital clock display of the time. Refer to here: http://playground.arduino.cc/Code/Time
void digitalClockDisplay() {
Serial.print(year()); Serial.print(" "); Serial.print(month()); Serial.print(" "); Serial.print(day()); Serial.print(" ");
Serial.print(hour()); Serial.print(":"); if (minute() < 10) Serial.print('0'); Serial.print(minute()); Serial.print(":"); if (second() < 10) Serial.print('0'); Serial.println(second());
}
void setBCDpins (int digit) {
// D 8
if (digit > 7) {
digitalWrite(BCD_D, HIGH);
} else {
digitalWrite(BCD_D, LOW);
}
// C 4
if (digit > 4 & digit < 8) {
digitalWrite(BCD_C, HIGH);
} else {
digitalWrite(BCD_C, LOW);
}
// B 2
if (digit == 2 | digit == 3 | digit == 6 | digit == 7) {
digitalWrite(BCD_B, HIGH);
} else {
digitalWrite(BCD_B, LOW);
}
// A 1
if (digit % 2 == 1) {
digitalWrite(BCD_A, HIGH);
} else {
digitalWrite(BCD_A, LOW);
}
}
void setup() {
Serial.begin(9600);
/* WiFi initialization and housekeeping */
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500); Serial.print("."); // Wait until connected
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
/* NTP initialization*/
Udp.begin(localPort);
//sendNTPpacket(timeServer);
setSyncInterval(20); // Set seconds between re-sync
#if DEBUG == 1
Serial.println(getNtpTime());
Serial.print("Time Status before setSyncProvider:");
Serial.println(timeStatus());
#endif
setSyncProvider(getNtpTime);
#if DEBUG == 1
Serial.print("Time Status after setSyncProvider:");
Serial.println(timeStatus());
#endif
pinMode(BCD_A, OUTPUT);
pinMode(BCD_B, OUTPUT);
pinMode(BCD_C, OUTPUT);
pinMode(BCD_D, OUTPUT);
pinMode(Nixie1, OUTPUT);
pinMode(Nixie2, OUTPUT);
pinMode(Nixie3, OUTPUT);
pinMode(Nixie4, OUTPUT);
digitalWrite(Nixie1, LOW);
digitalWrite(Nixie2, LOW);
digitalWrite(Nixie3, LOW);
digitalWrite(Nixie4, LOW);
}
void loop() {
//// Write WiFi status
//printWifiStatus();
//Write Time
digitalClockDisplay();
////Wait 10 seconds
//delay(10000);
// Print hours decade
digitalWrite(Nixie1, HIGH);
setBCDpins(hour() / 10 );
delay(frequency); // wait for a bit
digitalWrite(Nixie1, LOW);
// Print hours unit
digitalWrite(Nixie2, HIGH);
setBCDpins(hour() % 10 );
delay(frequency); // wait for a bit
digitalWrite(Nixie2, LOW);
// Print minute decade
digitalWrite(Nixie3, HIGH);
setBCDpins(minute() / 10 );
delay(frequency); // wait for a bit
digitalWrite(Nixie3, LOW);
// Print minute unit
digitalWrite(Nixie4, HIGH);
setBCDpins(minute() % 10);
delay(frequency); // wait for a bit
digitalWrite(Nixie4, LOW);
}
/* NTP functions */
time_t getNtpTime() {
while (Udp.parsePacket() > 0) ; // discard any previously received packets
#if DEBUG == 1
Serial.println("Transmit NTP Request");
#endif
sendNTPpacket(timeServer);
uint32_t beginWait = millis();
while (millis() - beginWait < 1500) {
int size = Udp.parsePacket();
if (size >= NTP_PACKET_SIZE) {
#if DEBUG == 1
Serial.println("Receive NTP Response");
#endif
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
unsigned long secsSince1900;
// convert four bytes starting at location 40 to a long integer
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
return secsSince1900 - SEVENTY_YEARS + timeZone * SECS_PER_HOUR + dstOffset(secsSince1900 - SEVENTY_YEARS );
}
}
#if DEBUG == 1
Serial.println("No NTP Response :-(");
#endif
return 0; // return 0 if unable to get the time
}
// send an NTP request to the time server at the given address
void sendNTPpacket(char* address) {
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
mn17(1).pdf (684 KB)