Newb in need of help trying to control bipolar stepper

Dr Jekyll

New Member
Hi Guys

This is my first post so please go easy on me.

I’m new to Picaxe and loving the possibilities, I’m also fairly new to electronics so incorporating them into projects is also new to me - I am a quick learner though. I’ve started working my way through the manuals and tutorials and built the LED flasher with the starter kit. What I ultimately want to do though is control this bipolar stepper:

http://www.ebay.co.uk/itm/Longer-Micro-Stepper-Motor-with-Screw-and-Fitting-for-Linear-Motion/281927848834?hash=item41a4359382:m:me_kYm54UGKI0hSrnnS4pEw

I’m looking for a bit of help and guidance in understanding the code. I’ve also just purchased the PICAXE-08 Motor Driver Board and am hoping it’s going to be suitable to control this stepper.

http://www.picaxestore.com/index.php/en_gb/picaxe/project-boards/axe023.html

I want to be able to move the stepper in one direction, pause 5 seconds and then move it back to the original position. Looking at the sample code in manual 3, I just don’t understand the structure and variable stuff and then it all gets a bit ‘binary’ and I’m completely lost! Can anyone start me off with something a bit more simple?

In addition to the above, I was also wondering if anyone has experience of triggering Picaxe chips using an RF remote like the one below?

http://www.ebay.co.uk/itm/315Mhz-Wireless-Remote-Control-RF-DC-5V-Transmitter-Receiver-Module-for-Arduino/231418644091?hash=item35e1a0467b:g:7QkAAOSw7ThUiWty

To put it in context, the stepper is being used in an animatronic project, which will be activated by a momentary press of a keyfob remote. I’ve used these little receivers before and when you press a button on the remote the corresponding pin goes high for the length of time you keep it pressed – can I use this to trigger the chip to do it’s thing and control the stepper?

Hope that’s enough info, any help greatly appreciated.

Cheers!
 

goom

Senior Member
Welcome to the Forum. It's a great source of helpful and cordial information.
Have you considered a hobby servo as an alternative to a stepper motor? Very easy to drive to a given position using the servo / servopos commands.
The remote receiver that you referenced provides a +5V signal on the channel corresponding to the button pressed on the transmitter. Easy enough to program the Picaxe to read this in a loop or by using an interrupt. You will likely need a pulldown resistor of perhaps 10K ohms to ensure that the output is assured to be 0V when the output is off. Be sure to have a common connection of the -ve of the power supply with the receiver and the Picaxe. If the Picaxe is powered by <5V then you will need to have a voltage divider to lower the receiver signal to no more than the Picaxe supply voltage.
 

Dr Jekyll

New Member
Welcome to the Forum. It's a great source of helpful and cordial information.
Have you considered a hobby servo as an alternative to a stepper motor? Very easy to drive to a given position using the servo / servopos commands.
The remote receiver that you referenced provides a +5V signal on the channel corresponding to the button pressed on the transmitter. Easy enough to program the Picaxe to read this in a loop or by using an interrupt. You will likely need a pulldown resistor of perhaps 10K ohms to ensure that the output is assured to be 0V when the output is off. Be sure to have a common connection of the -ve of the power supply with the receiver and the Picaxe. If the Picaxe is powered by <5V then you will need to have a voltage divider to lower the receiver signal to no more than the Picaxe supply voltage.
Hi there, many thanks for your reply - very helpful. Yes, I did consider a servo at first but I'm limited in height to approx 18mm, also I need at least 50mm of linear movement.

Thanks
 

AllyCat

Senior Member
Hi,

Yes, welcome to the forum. As said above a "servo" is potentially much easier to drive than a stepper, but what you have proposed does look "possible". Generally, servos are better for "power" driving applications and steppers for "precision". It appears from the ebay listing that that stepper may require 3300 steps, which should give plenty of torque, but don't expect things to happen quickly!

Unfortunately, driving stepper motors is not easy, There are various threads on the forum, but my first advice is to avoid (for now) any that use interrupts. Also the exact "phase" of the cable connections is important, so post as much detail and trial program code (within [ code ] tags) as you can. Note that at the (required) 0.5 Amp coil current, the switches on the PICaxe (L293d) driver board may each "lose" up to about 1.5 volts, so you might need a separate (higher) supply voltage (than the PICaxe) to drive the stepper coils.

The linked keyfob transmitter/receiver is intended for the American market (315 MHz) and strictly you should use a 434 MHz version in the UK. But it does appear to include encoder/decoder chips, so it should be easy to interface with a PICaxe chip. Alternatively, there are many RF transmitter/ receiver module pairs that can use the PICaxe RFOUT and RFIN commands (but I don't believe these are supported with the 08M2).

Cheers, Alan.
 

Dr Jekyll

New Member
Hi,

Yes, welcome to the forum. As said above a "servo" is potentially much easier to drive than a stepper, but what you have proposed does look "possible". Generally, servos are better for "power" driving applications and steppers for "precision". It appears from the ebay listing that that stepper may require 3300 steps, which should give plenty of torque, but don't expect things to happen quickly!

Unfortunately, driving stepper motors is not easy, There are various threads on the forum, but my first advice is to avoid (for now) any that use interrupts. Also the exact "phase" of the cable connections is important, so post as much detail and trial program code (within [ code ] tags) as you can. Note that at the (required) 0.5 Amp coil current, the switches on the PICaxe (L293d) driver board may each "lose" up to about 1.5 volts, so you might need a separate (higher) supply voltage (than the PICaxe) to drive the stepper coils.

The linked keyfob transmitter/receiver is intended for the American market (315 MHz) and strictly you should use a 434 MHz version in the UK. But it does appear to include encoder/decoder chips, so it should be easy to interface with a PICaxe chip. Alternatively, there are many RF transmitter/ receiver module pairs that can use the PICaxe RFOUT and RFIN commands (but I don't believe these are supported with the 08M2).

Cheers, Alan.
Hi Alan, thanks for your help. All good stuff. I wanted to use the stepper as it provides a lot of linear movement and it's cheap! Those Actuonix servos are cool but hellishly expensive.

My mistake on the transmitter/receiver - I am using the 433 MHz units. So all i need to do is connect the pin from the receiver to one of the pins on the Picaxe using a pulldown resistor and then use a loop command is that correct?

Thanks
Nick
 

AllyCat

Senior Member
Hi, Nick,

So all i need to do is connect the pin from the receiver to one of the pins on the Picaxe using a pulldown resistor and then use a loop command is that correct?
Basically yes. With the four output-capable pins used to drive the stepper, you will need to use Port.pin 3 (Leg 4). Then "Poll" the input status (level) within a program loop. Or, because that pin is interrupt-capable, you could set up an interrupt to allow the PICaxe to be doing something else (like driving the stepper coils) most of the time. You probably don't even need a pull-down resistor, but it shouldn't do any harm. The Serial (Programming) input could be used for a second switch input (with a few slight complications) or even three input signals detected by using a few external diodes and those two input pins.

As for driving the motor, I suggest starting as simply as possible and then move to some of the more "advanced" methods later. First you need to identify the connections to the two separate coils in the motor, call then A1, A2, B1 and B2 and connect them to the motor-driver board accordingly. The simplest (and most powerful) method is to reverse the current in each coil alternately as follows (not thoroughly checked or tested), but beware that this will draw quite a lot of power from the supply (battery), perhaps one Amp, and the driver (and the stepper motor) might get quite hot (so keep the supply voltage moderately low).

Code:
;other symbol declarations here
symbol DELAY = 2   ; milliseconds

for b1 = 0 to 500
  High A1     
  Low A2    ; Forward current in coil A
  pause DELAY
  High B1
  Low B2    ; Forward current in coil B
  pause DELAY
  Low A1
  High A2   ; Backward current in coil A
  pause DELAY
  Low B1 
  High B2   ; Backward current in coil B
  pause DELAY
next
  Low A2    ; Or use "input A2" etc. to switch off the outputs completely 
  Low B2
A lower power method is to drive only one coil at a time, for example:

Code:
  Low A2
  Low B2
for b1 = 1 to 500
  High A1    ; Forward current
  pause DELAY
  Low A1    ; Current off
  High B1    ; Forward current
  pause DELAY
  Low B1    ; Current off
  High A2    ; Backward current
  pause DELAY
  Low A2    ; Current off
  High B2    ;  Backward current
 pause DELAY
  Low B2    ; Current off
next
  input A1    ; etc...
Then there are other timing sequences that can be tried, for example a small overlap of currents in the two coils, or introducing a second delay time between the High/Low commands above, or several pins can be changed at the same time with the PINS command.

The direction of rotation can be changed by effectively reversing the direction of current flow through one of the coils.

Cheers, Alan.
 

WHITEKNUCKLES

New Member
Greetings Nick,

Your first link shows an optional Easy Driver which could reduce the control signals to the stepper to ~~
One Picaxe output to power the stepper one step, perhaps with the Pulsout command.
One Picaxe output to control the direction of the stepper using the High command for one direction and the Low command for the other.

The Picaxe 08 Project board kit would be a good first choice as it is a single sided PCB which allows almost unlimited de-soldering for many many changes and further projects.

There are many stepper driver boards that could be suitable and cheaper, the same holds for the stepper.

Dave
 

AllyCat

Senior Member
Hi,

Yes, of course a custom driver chip/board could make the programming much easier; and using the PWM output (pin c.2) for the step pulses makes it almost a background task. There's more detail about the "Easydriver" board on the sparkfun site (where it's even more expensive), which uses the Allegro A3967 driver chip.

But before we proceed too far, do you have any particular plans/requirements for the power supply, and is the "animatronics" going to place a significant mechanical load on the motor? It seems that stepper motors (and their drivers) often need a considerably higher supply voltage than the motor specification would suggest. The Easydriver chip has a bipolar, darlington output stage that "loses" (drops) around 2 volts, which might be a problem if you are hoping to use a typical PICaxe power supply of 4 - 5 volts. The Easydriver (output driver stage) is rated from 6 to 30 volts, so the board includes a voltage regulator to feed a typical microcontroller/logic circuit with 5 volts.

You might find the discussion in this thread of some relevance. The PAM8403 does appear to be quite a useful low voltage "poor man's H-bridge", so eventually I hope to add some more hardware and software details to that thread. It needs only one PICaxe pin per H-bridge (two outputs) by driving the PICaxe output pins either High, Low or "off" (input mode), so driving two steppers from a single 08M2 (and two 20p modules) is a real possibility. ;)

Cheers, Alan.
 

AllyCat

Senior Member
Hi,

I’ve also just purchased the PICAXE-08 Motor Driver Board and am hoping it’s going to be suitable to control this stepper.
IMHO there's a reasonable chance that it's suitable, but you may need to use a separate (higher) voltage for the coils/output stage. One of the Youtube "Easydriver" videos shows that motor running from two AA cells, but they are Lithium Poly cells marked 3.7 volts (each). So it's running with around a 7.5 volts supply rail, but no indication how much "push" the arm might actually be able to deliver.

All the output drivers discussed in the above posts appear to use similar compound/darlington, bipolar transistor output stages, so around 2 volts gets "lost" before it reaches the coils. The L293D (on the PICaxe board) looks to lose nearer a nominal 2,6 volts (!.4 + 1.2 volts) at 600mA, or more than half of a typical PICaxe/logic supply rail. That's also why the chips are "expected" to get hot! :(

L293d-darlingtons.pngL293d-outputs.png

There's a little more data for that stepper motor in the ebay listing for the version which isn't "longer". It has 20 steps per revolution, so the reference to needing thousands of step pulses must be because the Easydriver has been set to microstepping mode. A hundred or two loops of my code in #7 should be sufficient, and for the speed in the Youtube videos, I'd guess the pulse width (Pause DELAY) would be around 5+ ms.

Cheers, Alan.
 

Dr Jekyll

New Member
Hi,



IMHO there's a reasonable chance that it's suitable, but you may need to use a separate (higher) voltage for the coils/output stage. One of the Youtube "Easydriver" videos shows that motor running from two AA cells, but they are Lithium Poly cells marked 3.7 volts (each). So it's running with around a 7.5 volts supply rail, but no indication how much "push" the arm might actually be able to deliver.

All the output drivers discussed in the above posts appear to use similar compound/darlington, bipolar transistor output stages, so around 2 volts gets "lost" before it reaches the coils. The L293D (on the PICaxe board) looks to lose nearer a nominal 2,6 volts (!.4 + 1.2 volts) at 600mA, or more than half of a typical PICaxe/logic supply rail. That's also why the chips are "expected" to get hot! :(

View attachment 21637View attachment 21638

There's a little more data for that stepper motor in the ebay listing for the version which isn't "longer". It has 20 steps per revolution, so the reference to needing thousands of step pulses must be because the Easydriver has been set to microstepping mode. A hundred or two loops of my code in #7 should be sufficient, and for the speed in the Youtube videos, I'd guess the pulse width (Pause DELAY) would be around 5+ ms.

Cheers, Alan.
Hi Alan

Many thanks for taking the time to look at my little project and your suggestions which have been invaluable. Sorry for the lateness of the reply but I've recently bought a new MacBook Pro and trying to get the driver to work has been a challenge to say the least.

Having considered all the replies and my knowledge to date I've decided to ditch the stepper in favour of a a servo. I've just bought a couple of small servos and am going to give them a try. I'll come back shortly with my attempt at a programme to run the project so you can pick holes in it. Once again many thanks for your input thus far.

Cheers, Nick
 

Dr Jekyll

New Member
Hi Guys

Abandoned the idea of a stepper in favour of a servo for this project. I've written a programme, tested it and it seems to work okay although there does seem to be a bit of a delay before it resets itself. It may be this an idiosyncracy of the various servos (I bought a few different ones to test). I'm using a 434 MHz RF transmitter / receiver module, which is a momentary device, the output on the receiver is connected to the input pin on the Picaxe via a small diode (to reduce voltage from 6v). I wondered if someone could take a quick look at my programme and see if there are any schoolboy errors:

'// Box animatronics //

Output C.4
Input C.3

init: Servo C.4,75 ; initialise servo

Main: ; make a label called &#8216;Main&#8217;

Pause 10 ; in case of switch bounce

If PinC.3 = 0 Then Goto Main ; else loop back around
If pinC.3 = 1 Then Moveser ; jump if the input is on

Moveser: ; make a label called 'Movser&#8217;
Servopos C.4,75 ; move servo to one end
Pause 5000 ; wait 5 seconds
Servopos C.4,225 ; move servo to other end
Pause 5000 ; wait 5 seconds
Goto Main ; loop back to start


Also, I'm thinking it would be nice to programme it so the first press of the remote moves the servo to 225 then ends. Another press of the remote then moves it to 75. Anyone have any ideas how to code this?

Once again any help and guidance for this newb greatly appreciated - I'm learning I think!

Cheers!
 

lbenson

Senior Member
There are many ways to do this. One is to use a variable to keep track of the current position. Here's one way to do it.
Code:
'// Box animatronics //

 Output C.4
 Input C.3
 symbol position=b3

 init: 
   position = 75
   Servo C.4,position ; initialise servo

 Main: ; make a label called &#8216;Main&#8217;

  Pause 10 ; in case of switch bounce 

  If PinC.3 = 0 Then Goto Main ; else loop back around
  if position = 75 then
    position = 225
  else
    position = 75
  endif
  Servopos C.4,position ; move servo to one end
  do : loop while PinC.3 = 1
  Goto Main ; loop back to start
Note that after "IF PinC.3 = 0", you don't need the "IF PinC.3 = 1"--it must be if it (as an input) is not 0.
You may or may not want the next to last line: "do : loop while PinC.3 = 1"
It prevents the servo from just going back and forth if the button is held down without being released. If you want that behavior, comment that line out.

When you post code, it is best to enclose it with the "code" tags, "[ code]" and "[ /code]" (without the space after "["). There are several ways to do this, but I use by habit the oldest way we had available--just typing in the tags.

Once you see how this works, you can use the "position" variable to move to other positions--perhaps in response to a potentiometer setting which you read with READADC (and then adjust to your servo ranges).
 
Last edited:

Dr Jekyll

New Member
Hi Ibenson

Many thanks for your input it's much appreciated. Will give this a try.

Just a quick question. You mention that the line "IF PinC.3 = 1" isn't needed - do you mean it's not needed in the code you kindly provided or it's not needed in the code I posted either?

Cheers!
 

lbenson

Senior Member
,,, You mention that the line "IF PinC.3 = 1" isn't needed - do you mean it's not needed in the code you kindly provided or it's not needed in the code I posted either?
It's not needed in either. If an input pin is not zero, then it must be one (barring its having switched in the fraction of a millisecond between the two instructions--I doubt there's a need to take that possibility into account).

You can run the code I posted in the simulator.
 
Top