Sunday, January 18, 2026

More Control Panel Progress

So I have been having fun with my control panel coding and incorporating an LCD display panel into the mix.  Basically I started by writing code to test the LCD display.  I then moved to adding a series of text outputs that follows the testing of the LED lights on the panel.  All the LEDs get exercised to ensure that they all work and their wires are all connected.  I have also incorporated a self-test switch on the control panel to be run during startup of the Panel and Arduino.  When the switch is set, the Arduino advises what addresses are readable on the I2C bus, and then it does the exercising of all the LEDs on the panel.  When the self-test switch is not set, the Arduino just sets the Control Panel to its initial state and then it starts running the layout.

Late on Monday night, I was having some issues with some panel switches not working correctly.  So I went back testing the various point control switches, did some re-wiring, and the control panel switch and hold switches all work perfectly.  I found a couple of typos during the testing, when the logic says set yellow signal, then I go and set the green signal, Doh!.  Some people are just dumb!  I then copied that code in a couple of places, so I had to change those snippets as well.

I was having issues with the operation of the UP 2 signal and its Shunt Ahead aspect and the two routes to other tracks - the DOWN track and the BRANCH.  So I bit the bullet and rewrote that whole section of code.  It worked so much betterer.  Hehehe!  There was an issue that the train coming out of the siding, and one going into the siding would reset the signals after the code cancelled them (set them to stop) once the train exited the track.  But I soon fixed that logic error.  Next test was for me trying to get the train from the UP track to shunt to the DOWN track and go to the BRANCH.  I realised that I had commented out the code for the Down and Branch logic while just testing the UP logic.. So I uncommented that out and got stuck in.  I did a few more tests, changed the location of some delays in the code, removed a couple of boolean flags from the logic, and I think the UP code is now 99.5% accurate.  I’m sure I will find a bug somewhere in the future, but every test I threw at it, seemed to work.  So the focus now turns to the DOWN trains and their code.

As work on the panel logic progresses, I again realised that the UP code does not match the DOWN code.  So I upgraded the DOWN code by copying the UP code and changing names to protect the innocent.  I think I have DOWN signals 1, 3 and 4 all ironed out and identical between the UP and DOWN sides.  I will take a bit of break and get back to DOWN signal 2 in a while.  I have ordered some more Arduino stuff online and so I need for this to arrive in the post over the next week or two.  One of the issues that I think I am about to hit is that after adding the next 4 IR detectors (for my DOWN Signals), it appears that I am potentially stressing the power limit output of the Arduino MEGA.  My research suggested that an IR detector would pull about 20ma each.   I measured one and got a figure of 38ma for just one when using the 5V supply pin.  I switched this to the 3.3V pin and got about 18ma.  So the thinking was to offload the control of the IR detectors to a number of slave Arduino input boards on the I2C bus.  However, I could not find anything suitable.  I went looking and found out that I could just have say 10 IR detectors controlled from one Arduino UNO and the other 11 IR detectors controlled by another Arduino UNO.  NO need for special input boards.  I can then give these Arduinos an address on my I2C bus, like 2 and 3, and they will power up the IR detectors.  If this is still too much power for a UNO to supply, I will further break the bus down into UP, DOWN, BRANCH + SIDING and Dual Gauge offload Arduinos.  My Arduino MEGA will link to the Arduino UNOs on the I2C bus with a common GND reference.  The MEGA will poll the UNOs for their IR detector statuses and send that to the Master MEGA.  The MEGA will then take action and light the various White detection LEDs on the control panel.  In theory this is all child’s play.  In practice, it may not be.

While going through all these tests, opening up the panel and closing it again, I worked out that my self-test feature is not testing the 16 panel mounted switches.  I’m thinking that I need to verify that every panel switch is working in one direction, then ask the operator to change each switch to its opposite position and I will test again.  I will then ask that the switches be returned to their normal start up positions.  If I can’t read a different result from the two switch positions for each switch, then I have an issue with one of those switches.  Some of the issues I am having with the control panel is that a wire comes off a switch and my sensors are not reporting things correctly, and thus will not work as expected.  I then have to do through the consol log to verify various values of some variables.

This arvo while reading some stuff online, I realised that I think I can implement a SPAD feature on the control panel logic.  I will think about this a bit more and report back in the future.

No comments:

Post a Comment