This project controls the points/turnouts of a model train layout. There are 6 control panels where the user can request one of the various track options.
A block diagram is shown below. The six control panels are given names corresponding to where they are located on the model train layout
On each panel there are 4 buttons to request possible routes. Note due to the physical payout of the track, specifically the "wye" connection there are only 4 possible options on each panel and the 4 options on each board will be different.
On each panel there are four buttons to select the required routes
This project develops a class/library that reads the 4 buttons on each panel and returns the requested route.
The basic circuit of the controller and one control panel is shown. The 164 device drives the 4 LEDs to indicate the chosen point selection and is the subject of the page Wye Contrel Leds
The 165 device is wired to pin D4 (load), D8 (clock) and A0 (data in) The remaining boards use the same load and clock signals but the data is wired to pins A1 through A5.
Features of the implementation code include.
#include "Wye_Buttons.h"
Wye_Buttons but(4,8,A0,A1,A2,A3,A4,A5);
void setup() {
but.begin( );
pinMode(12,OUTPUT);
}
void loop() {
int static save_req;
digitalWrite(12,HIGH);
int request = but.read_buttons();
if ((request)&&(request != save_req)) {
Serial.println(request,HEX);
save_req = request;
}
digitalWrite(12,LOW);
delay(100);
}
The client code will
1.Create an object of the type Wye_Buttons.
This object specifies how the object is wired. That is the load, clock and the serial out of the 6 panels.
2, Calls the begin method to initialise the object
For observation with a mixed signal oscilloscope pin 12 is set as an output.
3. Requests the button reading and displays the result.
To observe the timings pin 12 is set high before and low after the read_buttons operations. This is known as the Activity signal in the following trace.
The above trace shows the signals to/from the buttons. The first channel gives the load signal that transfers the button state into the parallel to serial shift converter or shift register.
This is followed by 8 clock pulses to ripple the data from the shift register into the microcontroller (Serial In)
For the final trace a microcontroller pin was set high before reading the buttons and low when the operation was complete. By setting the cursors this may be read as 367 uSec.
Note the waveforms have captured a number of glitches. These appear to be related to the Serial In line going high and could possibly be eliminated by adding a small capacitance to the line.
The Wye_Butons can be added to the Arduino as a library.
Currently the *.h and *.cpp files (and *.ino) will be under the user work directory in a sub folder Wye_Buttons. (This happens by default when a new *.ino file is created.
To generate a library:
1. In the sub folder Wye_Buttons use a program such as Windows Explorer to create a *.zip file of the *.h and *.cpp files.
2. In the Arduino IDE under sketch --> Include Library --> Add .zip Library
3. Browse your files and select Wye_Buttons.zip
The operation will, if necessary create another sub folder "libraries". Under the libraries folder will be a folder Wye_Buttons where there will be the Wye_Buttons.cpp and Wye_Buttons.h files. Further libraries will be created under the same libraries folder.**
Notes (i) .if the two files are copied across the Arduino would need to be restarted for the updates to take affect.
ii. The original client code (*.ino file) included the library using #include "Wye_Buttons.h" with quotes. To use the files in the libraries folder the #include uses < ..>.
4. For other project to use the library (i) in the Arduino IDE under sketch-->Include Library and (ii) in the list of contributed libraries select Wye_Buttons.
For other users if the *.zip file is available start at step 2.
** This is a different location to libraries included as part of the Arduino IDE. In my case they were at C:\\Program Files(x86)\Arduino\Arduino\libraries. With the "< >" directive the compiler will search in both locations for the given file.
In a model railway system this module will be part of three that control points and hence the train routes.
(i) Wye_Control_Buttons where a button of microswitch is used to select a chosen route
(ii) Wye_Points_Control that uses the button request to generate a macro for the NCE Controller
(iii) Wye_Control_Leds (this project) that displays the chosen route
To create the library, see the section in the page Arduino IDE