LDBennett

 

A MicroController Controlled Point to Point Trolley Layout

 

I am working on adding computer control to my little point to point trolley layout. The controller is the Ardunio UNO MicroController board. I have it all worked out for connectivity and just finished bench testing the components and the program. It is going to work!

 

I have four "stations". There are the two end ones that require the trolley to change direction to return and two intermediate stops. The time of each stop is randomly variable between limits with extra time added at the north station. Whether the trolley stops at an intermediate station is random as is the stop times. At every startup the trolley bell module will ring twice.

 

Doing the programming was tough as I did not know C++ and all its wierdness. It is not at all like BASIC which I  know fairly well. But after fixing my code I got it to work on the bench. I used switches to simulate the photo detector circuits I already have installed in the layout and a relay card that will control the track voltage and polarity and provide a switch like closure to the bell module. It was helpful that each relay also has an LED. Testing was easy but fixing the code took a couple of partial days of trial and error. C++ tutorials are not written for the uninformed! But I got it.

 

What is left is to integrate it into the layout. As I plan a major addition adding 150% more track I am considering waiting to do it until I wire up the addition. But I am anxious to prove it works on the layout so I may just add it to the exiting layout. More to come!

 

I would add that this is a DC layout using the Crest Pulse Width Modulator converter and a 15VDC industrial power supply. See my post on An Alternative to DCC for details.

 

LDBennett

Reply 0
UPWilly

What an interesting project

Having been a professional programmer in a wide number of computer languages, this was an interesting read for me.

I might point out that the device you are using has the name Arduino (not Ardunio).

 

Bill D.

egendpic.jpg 

N Scale (1:160), not N Gauge. DC (analog), Stapleton PWM Throttle.

Proto-freelance Southwest U.S. 2nd half 20th Century.

Keep on trackin'

Reply 0
dkaustin

What? No pictures?

How about sharing some pictures or video? Remember a picture is a thousand words! Den

n1910(1).jpg 

     Dennis Austin located in NW Louisiana


 

Reply 0
LDBennett

Response

UPWilly:

I have a mental block every time I type or pronoun Arduino, it seems. I keep misspelling it and mispronouncing it. I'd make a lousy Italian.

I'm retired but worked as a hardware engineer on digital circuit design for decades in aerospace. My programming skills are limited to a good working knowledge of basic and an understanding only of a couple of other languages. The C++ was tough because I could not find a good tutorial for it with enough details to expand beyond the examples provided. It was the details that got me and it took trial and error to uncover my programming mistakes and some basic help from the Arduino forum members. If I had it to do over again I'd program it a bit different. C++ does not like the form you use in Basic and is full of details you must understand and consider. I got it now.

The main reason for this exercise was to learn the Arduino UNO and C++ so I could get the 11 year old grandson into C++. If I didn't learn it I could not help him. He has a Rugeduino (UNO with protection on nearly every pin) coming along with their Gadget Shield. That should keep him busy for awhile. He already knows several versions of Basic and some unique languages for programming games. He is anxious to get started with the C++ exercise. His ultimate dream is to build his own robot. He already built the Parallax robot and made many changes and experiments with the Parallax Stamp board. The UNO is the next step.

 

dkaustin:

There is nothing to see yet. I just finished bench testing the components and the program. I have to get all the components mounted, interconnected, and connected to the layout. It will not be pretty but it is all about how it operates the layout and pictures don't tell that story very well. Sorry. But I will report how well it works soon.

 

LDBennett

Reply 0
proto87stores

Your programmibg grandson may get frustrated

if a trolley stalls. There is no feedback (unless you get inside the controller and detect bemf), to tell the program that it didn't move.

I haven't had time to look up the PWM frequencies used in DCC chips but I vaguely remember something like 4KHz for original chips and may 10-or 20KHz for the "Silent running" (Digitrax name for safer  mode.

The amount of extra heating is really a function of the motor size and construction. Your Crest throttle is probably OK with any RTR commercial motor unless you set it to just creep with a heavy load for long periods. It's the expensive Fulhaber coreless instrument motor types that are the biggest risks.

 

Andy

Reply 0
LDBennett

Further Explanation

Andy Reichert:

​Some one took an oscilloscope picture of the motor voltage for me of a locomotive operating under DCC. It was about 25 KHZ as I remember it. I need to see how Crest did it. I did find the years ago problem of PWM rate mentioned in a post before but the rate was very low (was it 800 HZ?). The problem seemed to be cogging but over heating was mentioned. I can see how slow running could promote the over heating.

My layout is a trolley layout on flat ground (no hills, no elevation changes) running simple little trolleys with a constant load of one. The speed of the trolleys is not controlled by the Micro-Controller. It only controls the trolley's directions, stops and starts, and the ringing of the trolley bell under the bench. That is all handled by relays run by the Microcontroller program. I considered doing the throttle too but could not see the advantage of doing that for such a simple layout. The speed contort will be set with the Crest throttle and not touched again. While the Crest allows extremely slow running, the throttle will be set for the typical scale speed of 25 MPH (by guess) when operated automatically. The slow running will be used to shuttle the various trolleys manually off their storage sidings in order to pick a different one to run the point to point mainline. Each of my six trolleys eventually will have a storage siding of its own under block control and only one at a time will be moved onto the mainline.

Of course I could have done it all differently but this whole project evolved more than was planned. I'm now making additions (like Micro-Computer control and an additional 150% more track) that was never envisioned at the start of this project. I'm fine with its limits.

​I chose DC control over DCC because of the simplicity of the layout and the fact that the number of DCC ready and DCC trolleys is extremely limited. I wanted to match as much as possible the trolleys that ran in my town in my youth. While the ones I ended up with are not exactly the same they all are from about the same classes. If I had a real model railroad layout I most certainly would investigate DCC or even the a Radio Control system but there is no bigger layout in my future.

​My grandson will not do the program I already have done. He'll do his own, first with the Gadget Shield then maybe with a robotic arm or ???. From no programming ability at all six months ago through a one day BASIC tutorial I gave him he seems really to have a knack for programming. I can do programming (obviously) but I don't have the mind set for it. I have worked beside programmers for years and years and can see the differences between my thinking and theirs. My grandson thinks like a programmer not at all like me. He will master C++, I'm sure. He's a smart kid. But he has to learn the formality of the process (flow charts to programs rather than "stream of conciseness" programming). I had programmer that worked for me and the ones that flow charted made my reviews easy. The others were briliiant because they could keep it all in their head but others often need to take over a design and inadequate documentation often time means the new guy has to start over. Formality is important if you have to work for and with others or have to come back to an old program years later.

​LDBennett

Reply 0
LDBennett

The Arduino UNO Micro-Controller works!!!

 

OK...The micro-controller Arduino UNO is integrated and operates the trolleys just fine. I added an attempt to get a more realistic start-up and stop by chattering the stop/start relay at 60HZ for about 100 ms. That seems to help a bit. I tried lower frequencies and they were too visible. This of course will reduce the life span of the relays but there are three spare relays left on the board.

When my addition of about 15 feet of track on a 4 ft x 5 ft table, including a loop, is finished It will be good to see the full effect of the automated operation with then random time stop delays for pasenger loading and random misses of the two intermediate stations.

 

OH....The Crest PWM throttle operates at 13.5 KHZ based on measurement I made and works very well for slow running of the trolleys.

 

On to the addition!!!

 

The grandson now has his own Arduino UNO and is programming away. I have learned so much aobut C++  and will be able to help him if he even needs the help which he may not based on what i have seen him do with it so far.

 

LDBennett

 

 

Reply 0
LDBennett

Refinements for stopping and starting

In trying to make the startup and stops more realistic I had chattered the stop relay off and on at 60HZ to kind get the effect of half throttle. But that is not very good for the life of the stop/start relay in my system. 

So I decided that it needed a true half power during the slow down and start up. My system is using a Crest PWM throttle fed by a switching fixed voltage (15volts DC) power supply. If I could switch in a 8 volt supply for say maybe a 1/2 second or even for a whole second or more (??) during stops and starts then the trolley stops and starts could be much less abrupt. I'll consider still another reduction in addition to the 1/2 power one. The control is easily done with the micro-controller and the three spare relays on my relay card.

The solution for the additional 1/2 power supply is one of the three pin fixed voltage regulators ($0.39) connected to the 15 volt supply, switched in by the micro-controller for stops and starts. These devices generate the fixed voltage at over 1 amp which should be sufficient. I ordered some parts and will check it out soon.

There is a problem with using a programmable micro-controller. The programmer is never satisfied with the code and you have to kill him to ship the product.    

 

LDBennett

Reply 0
coxy

Arduino controlled switching layout

Here's a nice example of using an arduino to control the varous layout functions:

 

 

Reply 0
LDBennett

I didn't invent Arduino UNO for model train control ?

Obviously not!!

Ken, you did a great job and make my efforts look like child's play!

My usage is only crude momentum, auto reversing, random stops at know stations for random times for the stops. The trolley layout operation is automatic with randomizing added.

I can tell you as a non C++ programmer that it was an uphill battle for me, regardless that the end results are simple. I know BASIC pretty well and have been around programming on the fringes for decades but the C++ experience was hard and a lot of trial and error. The problem was the lack of any good programming books that go beyond the basics but not to the level of working C++ programmers. I had to figure it out myself by trial and error. The problem was in the details. I'm on version 10 of my program (OPPs, Sketch), but it runs the trolley from version 8 & up. I'm just tweaking it now, like the addition of a better crude momentum (I chose to not do it with PWM on the Arduino but with the Crest PWM throttle since I had it).

The Crest was a welcome find, by the way. You supply it with a fixed voltage (I chose 15 Volts DC) and it PWM's it for very good slow speed control. For the momentum update I am working on, I will switch it to 8 volts DC derived from a three terminal DC to DC regulator operating off the 15 volt DC power supply using a relay controlled by the Arduino UNO for about one second in startup and stopping. We'll see how that looks in real life shortly.

Anyway, good work Ken!

 

LDBennett

Reply 0
LDBennett

Latest mod failed!

Everything about the micro-controlled trolley layout was working fine except for the stops and starts which were a bit abrupt. I thought that by switching the power supply that feeds the Crest PWM unit from 15 volts to 8 volts during stops and starts for about a second or so that the abruptness would be removed. WELL........... The Crest did not like that at all and it gave erratic running. So I monitored the rails on an Oscilloscope while the trolley was running and boy did the Crest not like it!

I went back to chattering the stop/start relay post Crest at about 60 HZ for several cycles and it helps somewhat and the Crest cares not. I watched it on the o-scope and it all looks OK. 

So forget about switching the power source to the Crest for inertia. It does not work!

LDBennett

Reply 0
proto87stores

you "can"

Configure few of the inexpensive and popular 555 (and 556 dual) timer chips to create a variable PWM signal, and another to electronically ramp the ratio up and down for smooth starts and stops. You could also bypass the Crest completely by amplifying the final timer output with an also common "H bridge" motor control chip. 

OTOH, There are also D to A outputs on many micros that you possible replace the control knob circuitry in the Crest and control the speed setting directly. And PWM outputs that would obviate the need for the 555's .

The AVR specs are on-line for more info about what's in the micro - I think it's a "mega32".

Andy

Reply 0
JRG1951

Motor Speed with PWM

LDBennett,

You may be able to use a transistor or Solid State Relay [SSR] for a speed control. Use one of the Arduino digital outputs to drive the device with Pulse Width Modulation [PWM]. You will then have software control of the trolley speed. You will need a second output for direction control. Wire this output to a mechanical DPDT relay.

http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

http://arduino.cc/playground/Main/DCMotorControl

Regards,

John

*******************************************************************************************************************************************

Not everything that can be counted counts, and not everything that counts can be counted. Albert Einstein

BBA_LOGO.gif 

Reply 0
LDBennett

proto87stores and

proto87stores and JRG1951:

Thank you for you comments.

The Crest already does the pulse width modulation and I do understand that I could do it with the Arduino UNO PWM outputs. I decided to not do it in the UNO or with other components. I have the Crest and it works fine. The problem is really the abrupt stops and starts of my system. By chattering the stop/start relay that the UNO drives I get less of an abrupt change which is really adequate. I was just "polishing the apple" when I tried changing the power source voltage to the Crest to kind of get half throttle for a second during stops and starts. The Crest PWM derives its power from its input and goes crazy on its output with the sudden changes to its source of energy (can easily be seen with the O-scope).

So I decided that I'll just "eat the apple" without the polish. The effect I got with the chattering of the track stop/start relay is actually not that bad and I really don't want to do any more with the UNO. I have "other fish to fry", so to speak.

I documented my failure here so others who might possibly be following this thread will not fall into the same trap as I did. I'm fine with what I have now (chattering stop/start relay).

 

LDBennett

Reply 0
Terry Nathan

Point to Point Trolley Layout

I am incorporating a point-to-point trolley track into a set of T-Trak modules, and I love your implementation to automate the trolley.  I have been struggling with the amount of equipment I would need to replicate that effort with DCC, and the Arduino really simplifies what has to live under the module. 

You have done a great job describing the physical components, and I hear your disclaimers about the code you have for the Arduino.  But I too have no C++ experience, and starting with a working program seems to be a great advantage to a blank sheet of paper.  If you could share your code, I bet there are quite a few of us traction enthusiasts who would love to have your program as a starting point.

Terry@StDave.org

Reply 0
Chris Palermo patentwriter

Microcontroller or PC?

tiny_pc.jpg 

The day is coming when a microcontroller won't be needed. This image depicts a Liva PC that I bought today for $189 for testing at the office. It's an all solid state (no disk), sealed PC running Windows 8. It's mainly intended for POS terminal and other "thin client" applications, but imagine its hobby implications. Here is a complete PC that will fit behind the fascia or anywhere in your benchwork and could be coupled to a DCC system using the normal computer interface. You could have a compact LCD display and slide-out keyboard built into the layout. With these dimensions and price point there is no longer a need to keep your big, old home PC near the layout or spend thousands on a laptop or huge desktop system. You can dedicate a complete PC just to hobby applications.

 

At Large North America Director, 2024-2027 - National Model Railroad Association, Inc.
Reply 0
Pelsea

PC vs microcontroller

Although a mini PC is attractive (I have one), a microcontroller like Arduino is better suited to projects because:

  • Microcontrollers are easier to connect with the outside world-- in fact if you want to use a PC to do anything as simple as turn on lights you will need a microcontroller as the interface. Arduinos and their ilk provide direct pin connections for triggering individual tasks, USB and wi-fi communications, and dedicated inter-chip busses like I2C.
  • Microcontrollers start their program when the power comes on and continue to run reliably as long as necessary. No boot-up, no loading programs from disc.
  • Hacking and viruses are no an issue.
  • They are easy to update if needed, but you control when that happens.
  • A microcontroller will not be nagging you to update to Windows 10.
  • Arduinos cost $9.95, others are even cheaper.

As a railroad room general purpose computer running JMRI the Liva looks like a fine choice.

pqe

Reply 0
Reply