An Adjustable Speed Model Railway Fast Clock which integrates with the DCC-EX Command Station
This project is based on a project originally written by Jim Gifford (Hallet Cove Southern) in June 2017. His project used a 32 x 8 LED matrix to display the time and was controlled by a number of pushbuttons. See Jim's Original Project here.
I felt that this project was ripe for an update and decided to convert Jim's code to operate using a cheap TFT/LCD touch screen to run on my own layout. This project is the result. Much of the code has been rewritten into smaller functions with additional features added, but the time clock calculations are the originals.
This project has now been extended to add the capability of integrating the clock to the DCC-EX Command Station and more specifically the EXRAIL automation feature which now allows time based control. This feature is optional and can be controlled by the config.h file.
In order to fit the code comfortablly into the available RAM on a arduino the code has now been significantly updated from that written by Jim Gifford.
The project uses only two components:
The completed project is shown in the accompanying photograph:
The FastClock communicates with the Command Station using either I2C or Serial.
Given that the MCUFREIND style shield is a shield and uses the A4 pin as LCD_RST it is necessary to make a modification to enable the I2C communication. This involces cutting the A4 pin and soldering a jumper from LCD_RST on the backof the TFT board to the pin that aligns with the UNO RST pin. However if one is intending to configure the clock as a serial device then this modification is not required.
This modification allow the A4 & A5 to operate correctly as I2C and was suggested by David Prentice who wrote the MCUFRIEND.kbv library that this project uses. A discussion on this modification can be found here.
If using Serial communication no modification is required. Pins 0 & 1 (TX/RX) are unused on the LCD PCB therefore wires may be soldered to the Arduino PCB to run to Serial connections on the CS.
The MCUFRIEND style shield used in this project is usually a cheap(ish) import from China. These come with a variety of processor chips and various tolerances on the touch screen. As such before use it is necessary to carry out a calibration routine. Details of how to carry this out are provided here.
Once the calibration has been carried out plug the shield into the UNO and you are ready to install the software. If you need assistance see the instructions here.
The FastClock can either operate in one of three modes:
To indicate which mode is in use it is necessary to edit the config.h file.
Serial Mode. To communicatein Serial mode it is necessary to edit the config.h file and uncomment the following line:
`//#define SEND_VIA_SERIAL true`
This will load the appropriate code including the Wire library.
I2C mode To operate in I2C mode edit the config.h file and uncomment the following lines:
//#define I2CAddress 0x55 // default I2C address
//#define SEND_VIA_I2C true
In this mode the CS will poll the FastClock to obtain the time. It is necessary to set the same I2C address here as used in the myHal.cpp file within the CS. This is set to a default of 0x55 (decimal 85) but can be set to some other value if this conflicts with othere I2C devices on your setup.
By default the top of the clock screen displays the name of my own layout. To inset your layout name then change the following line.
char header[HDDR_SIZE] = {"Nantyderry Junction"};
Finally insert the output of the touchscreen configuration program into the file in place of the following two lines.
const byte XP = 7, XM = A1, YP = A2, YM = 6;
const int TS_LEFT=899,TS_RT=122,TS_TOP=100,TS_BOT=898;
At startup the clock will calculate a start time based on either a) a coded start time (currently 6:00 a.m.) or b) a run time stored in the EEPROM (see item 2) below.
The clock will start in a paused state and will display the speed rate factor (default = x 4). Once any adjustemts have been made the clock can be started. The usage of the six buttons are as below:
In Serial Mode, at startup the initial clock time will be sent to the Command Station but when in a paused state no further time commands are sent until the START buttoon is pressed.
In I2C mode the Command Station polls the FastClock at intervals.