Model Train Forum banner

Arduino Mega and Servo Shield

4K views 47 replies 7 participants last post by  Rabman 
#1 ·
I have put together an Arduino Mega 2560 with a 16 channel x 12 bit Servo PCM shield to power my 12 Turnouts which include a double slip turnout and a 3-Way turnout.

I am nearing the completion of the control box.

I am using one momentary push button switch per turnout and 3 switches for the 3-Way (1 per destination track) and two for the Double Slip.

In the end I am going to install one LED per switch, but not right now.

The program is written for the Arduino to operate the servos. It is a work in progress but I think it’s 95% complete.

I purchased SG90 servos from Amazon with all the other electronic equipment. The bracket for the servos are made of 1/2” aluminum c-channel. The prototype assemblies mount the servos with Gorilla double sided tape. I am going to reinforce it with Gorilla single sided duct tape around the bracket and servo. I will see the longevity of this system but anticipate it will be good. The photo shows a previous attempt with latex chaulk as the adhesive but it wasn’t strong enough.

I have one installed and am playing with some software parameters to get the turnout throw just right.

Here are some photos.
 

Attachments

See less See more
4
#5 ·
You are right, the holes are a little large. If I was to do it again I would probably make them a little smaller. I would also have centred the holes better. In the end of the day, adjusting the software variables I was able to make about 8 of them work so far. Including a double slip turnout. I did need to put some extreme values to make a few work.

Typically I use MIN Limit of 700, Max limit of 2300, one angle of 30 and the other 135. YMMV depending on a multitude of factors. I install a servo, Align it best I can, then play with the variables.

I will post the sketch in coming days and you can look at the variables I used.
 
#7 ·
i've been wondering about the positions of a servo used to control a turnout. It seems awkward to have to program each servo for each turnout.

would using a thinner wire that could bend more and moving a servo to extremes (+/- 90 degress) work. The thinner wire would apply a constant pressure to the switchpoint and require no adjustment.

Maybe tortoise switch machine could be used as a model for the geometry and travel distance. looks like the the tortoise is adjustable, the pivot can be moved

This link offers 0.037 replacement for the 0.022 wire that comes with a tortoise

 
#8 ·
It wasn’t really a lot of work calibrating each. I think you need to adjust the Tam Valley ones as well. Not sure about the tortoise ones.

It seems that a lot of people change the thinner wire to thicker. The tortoise come with 0.032” I think. Could be wrong. The thickness I selected is pretty good I think. Still has some flex. I don’t think you will get away without Calibration unless you spend a lot of time ensuring everything is perfect on the location and fabrication. The servos will always have some variation between then.

I am not saying how I made things is perfect, but it seems to be working. YMMV.
 
#11 ·
Attached is the sketch I have put together.

I have enhanced the code to have the servos now go at a reduced speed. More prototypical. Also, I turn off the servos after the movement to eliminate buzzing servos.

What I have learned is and is readily apparent by the variables is that I didn’t take enough care is setting the physical location of the servos or pay enough attention to the construction of the servo brackets (i.e. off centre wire holes). I needed to do some extreme values to get them to work. They all work well with the exception of the double slip turnout. It works, but because of the angles of the piano wire, it is wearing the point throw bar where the wire goes through. Not something you want to happen on an expensive turnout.

Learn from my mistake and align the servos better.

Also, keep your servos to +/- 30 degrees at the most from top-center if possible, to prevent up and down movement of the piano wire through the turnouts throw bar. It can have quite a height extreme if you go to +/- 90 degrees.

Due to the size I could not attached the Sketch as the size was too large.

Here is a Google Drive link to the sketch:

https://drive.google.com/open?id=1WpPfQt924PaQcwXtcA-7WTpZFB8yaZ7a

Sorry about that!
 
#19 ·
What I have learned is and is readily apparent by the variables is that I didn’t take enough care is setting the physical location of the servos or pay enough attention to the construction of the servo brackets (i.e. off centre wire holes). I needed to do some extreme values to get them to work. They all work well with the exception of the double slip turnout. It works, but because of the angles of the piano wire, it is wearing the point throw bar where the wire goes through.
thanks for the thread and posting your experiences.

below is a linkage that pivot (ignore spring and pushrod). Couldn't post image of servo mounted flat (shoe goo) with arm moving in vertical plane moving linkage arm (attached to spring in image).

I'm curious if there's a method that uses a fixed amount of rotation for any turnout.

 
#15 ·
Yes, a few even.
Print out good looking panel on paper, place behind clear Plexiglas panel, drill holes for LEDs and buttons. Can be made out of leftovers without any tools above saw, hand drill , something to scratch plexiglass with and some sand paper: https://public.fotki.com/tankist/ho-1/controlpanel/



If you insist on white outline on black background - use black construction paper and cut the outline to show white background. Or if your printer is good on toner just print it white on black. Again place behind Plexiglas. You also can laminate.

Consider making double panel to hide the awefuly looking mounting nuts. Does not require special machinery . Or at least use buttons that screw from the back.


Personally for all my future control panels I will be sticking to laser engraved paneling like below. I understand that modelers mostly focus on functionality instead making the pabel very presentable, but in my opinion a presentable panel is integral to a good presentable layout .

Good luck!

PS, normally I would offer my services to fabricate professional engraved panel, but at the moment im not taking orders - laser tube is out of gas.



 
#13 ·
I have found and 3D printed servo holders from Thingiverse, saves on having to cut a bunch of brackets.

One of the neat ways I've seen to finish off a control box is by putting the pinstriping on the back side of a piece of plexiglass (in reverse), then painting over it. So like if you put down black stripes then you would paint the rest with white. The front side of the plexi is left clear and provides a barrier so your paint doesn't get scratched over the years.
 
#21 ·
From a mechanical perspective, this mechanism will introduce longitudinal pressure on the tie bar through its travel. You would have to check out the geometry to see how much.

My bench work is made of 5/8” plywood, 1” foam and cork roadbed. I am not sure of the distance from the servo horn hole to the pivot but it’s probably about 1”.

I was thinking less would not provide enough mechanical advantage. I could be wrong, never did any calculations.

I think my issue is truly installation misalignment.
 
#26 ·
i'll suggest you drill three holes from above
- one for the wire thru the switch point tie
- and two others centered between the rails and between the ties to use to align the bracket (these can be small and covered with ballast. These can at least be used to draw a center line for the bracket


any motivation to try to remount the servo for turnout 6?
 
#29 ·
I like that method. Drilling is easy. Perfect way for doing the track alignment. That will work I think. I will probably end up remounting all the servos. And making the brackets again. No real issue as the channel was only $5. The main one I need to work on is the double slip turnout.
 
#28 ·
Not only could , but should. connection from servo to the switch absolutely must be a flexible one regardless of servo orientation. Servo has to have a full range of motion so in case of software glitch or user error no physical damage is done.

I've yet to review your code Rabman and I understand it might be WIP, but I think the way to handle is to have a discrete function that will accept turnout number and a binary parameter for turnout position. Also in my opinion servos need to be deenrgized as soon as operation complete.

Before I start asking further questions, do you have a roadmap of additional features for your sketch? What else are you looking to incorporate in it but n the future?
 
#32 ·
I'd take note of Anton's comment about the servo's running away. As one that has used these in a few applications, I've seen them suddenly go to the limits when I had a software glitch or a noise hit that caused the uP to reboot. If you use the cheap ones with plastic gears, and they hit too much resistance, they normally strip some gears. The more expensive servos with metal gears can exert a lot of torque after all the gearing, something to consider.
 
#34 ·
Greg, you'd be astonished at the amount of torque they can exert, even at reduced voltages. I suspect by the time you reduce the voltage enough to prevent damage, the electronics would start to get confused. I just tested one, at 3.6 volts it stopped functioning. At around 3.8 volts, it still had PLENTY of torque! This is a really small servo, the 9G model I took out I couldn't stop it with the short arm with 4V on it.

I also think running these at stall for a long period of time is a pretty bad idea. I think I'd make provisions to allow the flex in the linkage and not depend on the servo for protecting the switch and linkage.
 
#35 ·
First let me say that the below is just my thoughts on matter, it's the general line I will attempt to follow. So feel free to disagree or disregard.

Gregc, I Can't agree on reduced voltage idea. To not strip gears the complete mechanism should be designed to not have those kind of stresses.

Rabman,
Yep, I did notice separate values for switches, hence my comment that this shouldn't be happening. Think tortoise machine, it's either closed or thrown. Likewise the position of a servo should be from one extreme to another and have a flexible linkage that compensates and keeps reasonable ammount of tension for the point rail against the stock rail. Not sure if you planning on expanding your layout at sone point but even if you don't i can forsee these custom setting causing maintenance challenges down the road.

The reason I asked about the the future plans is to find if you plan to simply cover your needs or present (in that case 54 IOpins of AMega is everything you need) or present community with configurable solution.

In either case here is my outline of arduino-like device (not specifically AMega) requirements:
#Servos for switch machines with 2-3 second transition
#Input from pair of limit sensing microswitches , to detect "closed" and "thrown" switch states (enabling detectionof "in transition" state)
# connected via Loconet interface for scalability. Essentially the device is a custom stationary decoder.
#! posibility for switch transition sound playback (via pwm pin) something to toy with )

Note: this board will not be driving signals or reading input from block occupancy sensors and buttons from physical panel. For that there will be dedicated input and dedicated LED driving boards sitting on same Lnet bus. JMRI LogiX rules will determine signal aspects based on o cupancy and switch state

Just my .02 cents worth. There is still time before I sit down to code this )
Regards.
 
#37 ·
First let me say that the below is just my thoughts on matter, it's the general line I will attempt to follow. So feel free to disagree or disregard.

Gregc, I Can't agree on reduced voltage idea. To not strip gears the complete mechanism should be designed to not have those kind of stresses.
I think that varying the voltage is not possible very easily.

Rabman,
Yep, I did notice separate values for switches, hence my comment that this shouldn't be happening. Think tortoise machine, it's either closed or thrown.
The Tortoise switch machines have their values calibrated with a separate addon. I imagine the remote, adjusts values in the controller. My method is a bit more of challenge, but not much.

Likewise the position of a servo should be from one extreme to another and have a flexible linkage that compensates and keeps reasonable ammount of tension for the point rail against the stock rail.
One of the reasons I went with the stiffer piano wire was based on comments from a number of people saying the wire provided with the Tortoise was too thin. Also, I left the springs in the PECO turnouts that would have been problematic with the thinner wire. Since then, I have removed the springs in the PECOs. That said, I am not sure if the thinner wire is a good idea or not. YMMV.

Not sure if you planning on expanding your layout at sone point but even if you don't i can forsee these custom setting causing maintenance challenges down the road.
I am not sure they will be a major maintenance issue or not. Time will tell. I think with proper alignment, it should be minimized.

The reason I asked about the the future plans is to find if you plan to simply cover your needs or present (in that case 54 IOpins of AMega is everything you need)
I think the intent is to provide the community with something that they can tailor. I don't think I intend to bring occupancy or signals into the equation at this time because my layout is quite small compare to other users. I think I want to be able to control the turnouts through DCC, but I built the panel because I think that for a layout my size, it is more convenient that scrolling through option screens on a computer. I am wondering what protocol or interface the Tam Valley DCC Add-on for the Octopus III uses to see if I can interface it with the Arduino.

#Servos for switch machines with 2-3 second transition
Already implemented.

#Input from pair of limit sensing microswitches , to detect "closed" and "thrown" switch states (enabling detectionof "in transition" state)
What is the importance of this if you have LED indication? The LED can start flashing at the start of the servo movement and stop flashing at the end. This is obviously not as positive feedback as if there is a microswitch. Though the servo horn can break, piano wire break, turnout points, etc. So nothing is foolproof.

# connected via Loconet interface for scalability. Essentially the device is a custom stationary decoder.
See comment regarding Tam Valley.

#! posibility for switch transition sound playback (via pwm pin) something to toy with )
Definitely possible with the existing setup with some extra shields.

Note: this board will not be driving signals or reading input from block occupancy sensors and buttons from physical panel. For that there will be dedicated input and dedicated LED driving boards sitting on same Lnet bus. JMRI LogiX rules will determine signal aspects based on o cupancy and switch state
Not my intent at this moment to do occupancy sensors or some of the other stuff you mentioned...so of which I don't even know what it is at the moment. LOL

Keep in mind, the intent of my journey are as follows:

- Control the turnouts at a reasonable cost without fancy tools. I would say the cost will be less than half the cost of what Tortoise switch machines would cost and much less that Tam Valley.

- Not be a complete replacement of some of the equipment and systems out there but a low cost alternative.

- Learn a new technology and software language.

- Do some fabrication and engineering.

- Pass my experiences and learning on to others.
 
#39 ·
There are a few modifications you can make if you would like positive protection of a servo going crazy similar to what the smart guy did. He used a servo horn with an extension on the top and bottom. Over travel would result in the horn hitting the bracket.

He also mounted a microswitch on the size for an electrical contact.

 

Attachments

#42 ·
I have been operating the servos for a while now. They seem to be behaving well.

The linkages above seem fairly complicated.

What I have learned is:
1) Make sure the pivot hole is centered.
2) Make sure the bracket is parallel to the tracks.
3) Make sure the swing of the servo is centered.
4) Don't worry too much about the variable numbers as long as the physical travel of the servo is what you want.
5) The gorilla two sided tape (between the aluminum channel and servo) and gorilla duct tape (around the servo to the bracket) work fairly well but may not be long lasting. Time will tell.
 
#44 ·
So the two way gorilla tape and gorilla duct tape is a bust holding the servo to the aluminum channel. The servos keep pulling away from the channel. So don’t use this method! It take weeks for them to fail, but that is too soon.

I am going the think about using epoxy to glue them together.
 

Attachments

This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top