2019 Construction Progress

Rio Grande Southern Matterhorn Section

During the past year, I have begun the construction of my garden railway. After we had cleaned up after snowpocolypse, that is. I decided to start at the top of the yard, because the bottom section is waiting on a retaining wall project. The topography of my land means that this section is elevated about 4 feet off the ground, so I elected to build a “table” for this section.

The table is the portion labeled Matterhorn with the siding. Just after the top end of the table is Bridge 51A, the Trout Lake trestle to be built and installed this year.

Matterhorn Section

I used standard treated wood 2×4 frames covered with hardware cloth and then weed barrier cloth on top of that.

Because this section will be elevated close to eye-level, I thought that hand-laying the track would look nicest.

I was looking at this and thought that it would be great to have some elevated garden boxes along the table so I could plant on this section of the line as well as the filled ground-level sections. So I built a long raised plant box along the back of the table.

It’s surprising just how much dirt and mulch it takes to fill this!
I took my time and built a nice cedar face for this planter, as it will be visible from the upper patio.

I am looking forward to better weather as I have a lot of little projects to finish this section: one turnout and the final curve needs to be finished; all the track needs to be fastened down; the siding area needs to be filled and ballasted; and the garden box filled and planted. Also, a trestle to build and install just off the end of the table.

Not being a glutton for punishment, track laying will then continue apace using PVC ladder roadbed and flex track.

Arduino Multi-function Shield

I recently got exposed to Arduino programming and hardware design at the 2019 National Garden Railway Convention in Portland, OR. Geoff Bunza (Blog: https://model-railroad-hobbyist.com/blog/geoff-bunza YouTube: https://www.youtube.com/channel/UCKzeYLMEPxWGilqZTNuG0JA) held an Introduction to Arduino in Model Railroading clinic. As the Clinic Chairman, I offered to help during the presentations in any way I could. Because I’ve been programming forever (since I was a teen), and have been an electronics hobbyist, none of the topics were foreign to me. I had heard of the Arduino, but had never played with one.

This was really fun, using simple components and software to make blinkenlights and such. There are posts such as this one https://maker.pro/arduino/tutorial/how-to-easily-prototype-with-an-arduino-multi-function-shield about this shield, and other examples using libraries to control the devices.

I’m not sure why, but I couldn’t get the libraries to work. They were overly complex for something as simple as controlling a multiplexed display. I attempted to just update the display during the loop section of the sketch, but I couldn’t get the brightness of each segment to be even. Inevitably, the last segment to be updated was brightest (as it was “on” during the loop code) and the others were dim.

I looked for a more basic example using a timer that wasn’t 20,000 lines of code and obfuscation. I found this example that showed how to set up Timer 1 and provide an interrupt handler: http://www.hobbytronics.co.uk/arduino-timer-interrupts That was more like it!

I extended that code and modified my sketch display code to interface with the ISR, and got everything to work well. I built a simple software count-down timer that uses the buttons to set the time and beeps at the end.

Note: I should probably move the display code to a library or something, rather than have so many lines of code.

Hacker’s Delight

and the Arduino (GCC Compiler)

I got a new (used, but new to me) book about computer coding: Hacker’s Delight by Henry S. Warren Jr. This is one of those books that I will read most of more than once, because the material covered is very technical and delves deeply into the intricacies of programming efficiently.

One algorithm that was particularly interesting, for no reason other than the algorithm is clever. This is a method for counting the 1-bits in a binary word. There is the naïve implementation, of course, but iterating through the bits and counting the ones:

I had to run this code 1 thousand times to get a good count. The Arduino (ATMega 328P chip) is FAST! This code ran in 24.58 microseconds per iteration.

There is a much more clever method in the book, which divided the value up into 2-bit blocks and counted the ones using addition, then added the 2-bit values into 4-bits, then 8-bits and finally adding the two 16-bit blocks to get the final count. So I added the code from the book to compare the times:

This was an impressive optimization, as it ran in zero milliseconds! I increased the loop count to 1 million so I could get a measurable time, and it was still zero milliseconds. WOW! So, I added yet another 1 million iteration loop around the “j” loop. Still zero…

So, 1 trillion iterations in zero milliseconds? That processor is not a super-computer, so something was wrong. I realized the compiler must have been seeing my code as unchanged in each loop and was simply optimizing the loops away.

I added an array with two elements (with identical bit counts) to try to fool the optimizer.

This worked, as I got 8.68 microseconds per execution. This is about 3 times faster than the naïve implementation. Nice.

Now, I may just have a use for that beautiful code someday.

Enhancements

I wanted to display the execution time on a display, so I added the code to a sketch with the test loops in the main loop. Foiled again! The optimized code was, again, optimized away.

I experimented with several changes to fix that. What worked was declaring the array test variable volatile so that the x variable was loaded each iteration:

Garden RGS Construction – Part 4

Hand-laying Track

Straight Stringers

I rip cheap cedar fence boards into ¾” wide pieces, getting four per board. The height of my stringers will be ¾”, so I use the clean-cut sides as the top-bottom. I glue two of these together and cut 1-inch blocks to act as spacers between the straight stringers. (Any stringer scraps can be recycled as spacers.)

I simply glue and clamp these without any nails or screws. The addition of ties and attachment to the baseboard will bond everything together permanently.

Gluing and Nailing Ties

I have a tie-spacing template with ties drawn at 1.2” apart, which gives ten ties per foot. (This is the same as Llagas Creek flex track.) I use small snack-size zipper bags filled with sand as weights for holding the glued ties down while the glue sets. Each bag will cover five ties, so I put them down five at a time.

Once the glue has set, I use a brad nailer to attach each tie to the stringers. Make sure that each nail ends up under the rail by marking gauge lines 45 mm. apart and nailing just outside of those lines. (I thoroughly wet down the ties before I nailed them to help make sure they wouldn’t split.)

Spiking Rail

I start spiking rail down by placing a rail on the ties with a straight-edge and spiking it down in just a few places – say every foot. Then I carefully spike in between those spots, dividing each into halves and so forth until the rail is spiked every two or three ties.

The second rail needs to be spiked in gauge, so I break out my track gauges and put one on each side of the tie I’m spiking. For this rail, I spike the same ties as on the first rail.

At this point I just proceed spiking the remaining ties from one end to the other.

Curved Stringers

I made a curved track jig to use to laminate three pieces per side of bender board or lath cut to ¾” width. I use the same spacers as for the straight stringers. In hindsight, I realized that I could have used fewer spacers on this first curved piece (perhaps using many as construction spacers and not gluing them in place).

I have a curved tie layout template similar to the straight one that I use to get tie spacing consistent.