charlie512621
Posts: 3
Joined: Thu Oct 06, 2016 3:54 am

stepper motor

Thu Oct 06, 2016 4:05 am

Im just wondering if someone could help we with a question about the pi and stepper motor control? I was hoping there is a way to do point to point stepper control without having to home it everytime you power it on or after each move? I want it to control a turn table for my model RR. I would like to have it set for a group of buttons to move table to a specific location each time. Im fairly Certin this can be accomplished i just need some input. Thank you in advance any input is useful.

User avatar
joan
Posts: 15083
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: stepper motor

Thu Oct 06, 2016 7:46 am

A stepper motor can be told to move x steps clockwise or y steps counterclockwise. A stepper has no idea of its current position.

For that reason you generally have an external switch which triggers when the steppers shaft moves a lever to an end point.

Your software could assume that the stepper always starts off in a particular position. That will be prone to error when things get out of sync (e.g. if the software crashes or the stepper isn't powered).

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: stepper motor

Thu Oct 06, 2016 8:34 am

As Joan says, steppers have no idea of their absolute position. I think you'll need at least one micro switch to allow you to reset to the home position if needs be.

Thereafter, you can keep count of the number of steps away from the home position and calculate the number of steps required to move to any turntable position on your model railroad. If you regularly store the position in a file, and load that position info on first run after reboot, you won't need to re-home every time.

If you see that the turntable isn't aligning with the tracks, you can make use of a reset button to realign the position to the home micro switch.

BMS Doug
Posts: 3872
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: stepper motor

Thu Oct 06, 2016 9:10 am

As I read it you will be turning with the turntable in one of a selection of fixed locations?

If you fit a magnet to the edge of the turntable you could have one reed switch at each of the locations so your Pi will be able to know the turntable is whenever it turns on (or turns) and have precise alignment.

The same could be achieved with standard microswitches and a slight raised edge on the turntable.

(Effectively making every valid location of the turntable a "home" location).
Doug.
Building Management Systems Engineer.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: stepper motor

Thu Oct 06, 2016 10:38 am

If you are going to employ switches at every turntable position, you may as well use a brushed dc motor in place of a stepper.

User avatar
Gavinmc42
Posts: 4817
Joined: Wed Aug 28, 2013 3:31 am

Re: stepper motor

Thu Oct 06, 2016 11:27 am

You only need one switch, it is called the home switch.
Almost all CNC/3D machines use them.

Once you drive a stepper in reverse to home, you then can repeatably count steps to then line the tracks up.

To get more precision you could drive the turntable with a belt and pulley.
Gears have backlash, so avoid them unless you really know what you are doing.
Alternatively you could use a pot and an ADC to read it.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

ewaller
Posts: 32
Joined: Tue Oct 04, 2016 5:24 pm

Re: stepper motor

Thu Oct 06, 2016 4:02 pm

... Or an absolute shaft encoder.

https://en.wikipedia.org/wiki/Rotary_encoder

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: stepper motor

Thu Oct 06, 2016 5:17 pm

BMS Doug wrote:If you fit a magnet to the edge of the turntable you could have one reed switch at each of the locations so your Pi will be able to know the turntable is whenever it turns on (or turns) and have precise alignment.
An optical scheme that just had one reader and marks on the turn table that defined specific positions, I think, should be simpler. Maybe design those marks and print them on a laser printer, cut out and glue around the turntable. In software, adjust for any difference between where the start is on the printed paper and the actual start should be with regards to the turntable matching with the required railroad tracks.

If your optical reader can read more than binary true/false, I mean can read levels of light being reflected from the paper, essentially telling you the width of the line, you could have data like this: - - - - - | which might let you concisely state where on the circle you were and exactly where your next correct stop point is, well, plus or minus the software defined offset. So you can get this from both directions, perhaps the data is duplicated before and after the stop line: - - - - - | - - - - -

charlie512621
Posts: 3
Joined: Thu Oct 06, 2016 3:54 am

Re: stepper motor

Fri Oct 07, 2016 11:58 pm

Thank you all. This was very helpful. I figured the home switch was a mandatory. The apsolute postion encoder sounds amazing, im just wondering how i would use this with a pi. Research ahead of me i see.

Unknownpug
Posts: 5
Joined: Tue Aug 02, 2016 11:23 am

Re: stepper motor

Sat Oct 08, 2016 9:31 am

What about a servo? I dont know much about model rail roads, but i imagine this could be done with a servo. Servos are position aware, so you can place it on the exact location with out limit switches... They are really cheap but i don't know much about controling one with a pi.

charlie512621
Posts: 3
Joined: Thu Oct 06, 2016 3:54 am

Re: stepper motor

Mon Oct 10, 2016 2:12 am

The only issue i see with a servo is they cannot rotate 360 degrees.

Return to “Beginners”