End Presentation


TWiki Slide Show
Next
Stepping Motors

Lecture 9

Uli Raich

UCC semester 2017/2018

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 1 of 31





















TWiki Slide Show
Next
The 27BJY-48 stepper motor and its ULN-2803 driver module
stepping.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 2 of 31





















TWiki Slide Show
Next
A lecture on youtube
There is an excellent tutorial describing the usage of exactly our stepper motor setup on youtube

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 3 of 31





















TWiki Slide Show
Next
Stepping Motors versus DC Motors
While DC motors simply spin when they are powered,

stepping motors can be moved in defined steps and thus positioned very precisely.

They contain 2 coils which can be powered in positive or negative

direction making the current flow in normal or reverse direction

and thus creating magnetic fields of opposite polarity

The rotor has a series of magnets (16 in case of the 28BYJ-48 which we are using)

with alternating opposite polarization.

A north pole followed by a south pole followed by a north pole and so on.

The motor base has 2*16 teeth which can be polarized as

north or south poles depending on the direction of the coil current.

Here is the data sheet of the 28BYJ-48

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 4 of 31





















TWiki Slide Show
Next
The Driver Card
The maximum current that a GPIO pin on the Raspberry Pi can deliver is 60 mA

which is insufficient to power the motor coils.

We therefore need a driver circuit (Darlington stage) to amplify

this current. In our case we use the ULN-2803 chip

The little PCB has 4 LEDs on it to show which of the 2 coils is

powered and in which direction. This is very useful to demonstrate which signals

are sent to the motor and it illustrates nicely the functioning of the motor.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 5 of 31





















TWiki Slide Show
Next
Connecting the Driver to the Motor
connections.png

We can see from the connections that when powering the pink line

the coil current is flowing in one direction while when

powering the orange line it is flowing in the opposite direction

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 6 of 31





















TWiki Slide Show
Next
Motor Movement (Single Step Forward)
First we power the first coil in such a way that the first tooth has a

south pole and the second one a north pole, which

makes the rotor (whose north magnet is considered) moves to the first tooth.

Then we switch off the first coil and power the second coil such that

the first tooth of the lower row has a south pole.

This makes the rotor move to this tooth.

Now switch off the second coil and switch the first one on again,

however this time with reverse current. The second tooth of the

upper row now has the south pole

(the poles are inversed with respect to the first step).

Now we switch on only the second coil with inverse current to make

the rotor move to the forth tooth. From now on the whole cycle repeats.

step1.png step2.png step3.png

step4.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 7 of 31





















TWiki Slide Show
Next
Signal Table for Single Phase Forward
We have seen in the last slide how we have to power the coils to

make the stepping motor move by 1 cycle, which is 4 steps in case of

Single Phase Forward stepping

How does this translate into a program?

We connect the 4 phases (coil 1 forward, coil 2 backward, coil 1 backward, coil 2 forward)

to 4 GPIO pins on the Raspberry Pi cobbler

Then we create the following signal table, which is a 2-dimensional array of booleans:

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 8 of 31





















TWiki Slide Show
Next
Other modes of operation
Single Step forward (and backward) works fine but we can do better.

Up to now we have always powered only one coil at a time.

It is however possible to power both coils at the same time.

This will draw of course more current but the motor will get

a higher torque and can therefore handle bigger loads.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 9 of 31





















TWiki Slide Show
Next
Movement Double Phase Forward
doubleStep1.png doubleStep2.png doubleStep3.png doubleStep4.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 10 of 31





















TWiki Slide Show
Next
Double Step Forward Table
Of course our signal table must change correspondingly,

our program to send out the signals for one full cycle stays the same however.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 11 of 31





















TWiki Slide Show
Next
Programming double step forward mode
For this, nothing much is to be said:

We change the table, but since the program is independent

from the contents of the stepping table, the code stays strictly the same

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 12 of 31





















TWiki Slide Show
Next
Position of rotor in doubleStepForward mode
An important point to note is that the rotor moves half a step

further than in single Step Forward because its north pole

is now attracted by the top and the bottom south poles.

By first powering only the upper coil, then powering both coils

then powering again only one pole of the lower coil it should

be possible to move the motor by half steps only

and by doing so increase its resolution.

This is what we call half step mode and it is a combination

of single and double step forward modes.

The torque of the motor is less than in double step forward

and the speed is only about half because now we need 8 steps for a full cycle.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 13 of 31





















TWiki Slide Show
Next
Movement Half Step Forward
step1.png doubleStep1.png step2.png doubleStep2.png
step3.png doubleStep3.png step4.png doubleStep4.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 14 of 31





















TWiki Slide Show
Next
Half Step Forward Table

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 15 of 31





















TWiki Slide Show
Next
Programming Half Step Mode
Again, apart from the fact that we must now pass through

a table of 8 entries instead of 4 the program does not change.

If we use the signature of all bits being zero

as end of table indicator then no change at all is required.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 16 of 31





















TWiki Slide Show
Next
The pigpio library
Up to now we always used wiringPi to access our GPIO pins.

I explained in the first lecture on the Raspberry Pi

that there are 2 independent libraries available:

  • wiringPi
  • pigpio
Why would we be interested to use a different library?

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 17 of 31





















TWiki Slide Show
Next
Advantages of pigpio
The pigpio library comes in 2 versions:

  • The standard one where calls to the library code
    results in direct access to the hardware
  • The daemon version where first a daemon (pigpiod)
    is started and then the hardware access is only made in this daemon

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 18 of 31





















TWiki Slide Show
Next
Accessing the daemon
The daamon is started once before we make any hardware access:

sudo pigpiod

After this all hardware access can be make by a normal user

The program communicates with the deamon through library calls

which connect to the daemon through

  • pipes (when running on the Raspberry Pi) or

  • through sockets when running on a remote system
    like our Ubuntu PC
There is a library version that runs on the PC

We can write C programs on the PC with hardware access

to our devices on the bread board through pigpio calls to the

PC version of the library which communicates

with the pigpio daemon on the Raspberry Pi

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 19 of 31





















TWiki Slide Show
Next
Documentation of pigpio
The WEB page of pigpio can be found here

pigpioPage.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 20 of 31





















TWiki Slide Show
Next
Types of functions in pigpio
Going through all the function in pigpio during the lecture is impossible.
I have not used the all neither!

  • There are functions to
  • Initialize the library and close it
  • Control gpio lines and read from or write to them
  • Get a call-back when a gpio state changes
  • Access routines to the I2C bus
  • Access routines to the SPI interface
  • PWM functions
  • Functions for use of a serial device

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 21 of 31





















TWiki Slide Show
Next
Features of pigpio
features.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 22 of 31





















TWiki Slide Show
Next
This is how to use the library
usage.png

Please convert this to what will be required in your source code.

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 23 of 31





















TWiki Slide Show
Next
Initializing pigpio
You must include
#include <pigpiod_if2.h>

… and then you can happily use pigpio functions

stepperMain.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 24 of 31





















TWiki Slide Show
Next
Sending the pulses to the hardware
Now all we have to do is to go through this table and, for each step,

send a high level to the GPIO pin to which we connected the coils.

stepTable.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 25 of 31





















TWiki Slide Show
Next
Going through one step cycle
oneCycle.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 26 of 31





















TWiki Slide Show
Next
A typical Makefile with pigpio
stepperMake.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 27 of 31





















TWiki Slide Show
Next
Reading command line arguments
You say: This we have seen before and you are right.

However, some commands use very complex command line arguments

and the system provides a parser for it.

Have a look at getopt_long, which helps you in figuring out what the used wants.

The stepper motor program had these options:

stepperUsage.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 28 of 31





















TWiki Slide Show
Next
Using getopt_long
First we include <getopt.h>
Then we create a table of options (last entry must be all zeros:

getOpts.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 29 of 31





















TWiki Slide Show
Next
Call getopt and interpret
callGetOpt.png

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 30 of 31





















TWiki Slide Show
Next
Write the stepper program
With this information you should be able to write a program where the user can

  • Select the movement mode
  • Select the movement speed
  • Select if you turn clockwise or counter clock wise
  • Select how have to move of to which angle

First slide Previous Next Last slide
COPYRIGHT © 2024 by the contributing authors
Slide 31 of 31





















First slide Previous End Presentation






























-- Uli Raich - 2017-10-16

Comments

The youtube video on stepping motors has been taken out of the lecture slides (lecture_9_upload.odt) because it would make the file too big for upload and I am not sure about copyright issues. However, you have the link to the video in the slides on this page.

-- Uli Raich - 2017-11-01

I Attachment History Action Size Date Who Comment
PNGpng callGetOpt.png r1 manage 39.1 K 2017-11-03 - 07:46 UnknownUser  
PNGpng connections.png r1 manage 29.9 K 2017-10-16 - 13:58 UnknownUser  
PNGpng daemon.png r1 manage 17.0 K 2017-10-26 - 13:43 UnknownUser  
PNGpng doubleStep1.png r1 manage 5.3 K 2017-10-17 - 09:20 UnknownUser  
PNGpng doubleStep2.png r1 manage 5.6 K 2017-10-17 - 09:20 UnknownUser  
PNGpng doubleStep3.png r1 manage 5.2 K 2017-10-17 - 09:20 UnknownUser  
PNGpng doubleStep4.png r1 manage 5.5 K 2017-10-17 - 09:20 UnknownUser  
PNGpng features.png r1 manage 40.2 K 2017-10-26 - 13:43 UnknownUser  
PNGpng getOpts.png r1 manage 16.6 K 2017-11-01 - 12:50 UnknownUser  
PNGpng gpioI2C.png r1 manage 76.7 K 2017-10-26 - 13:43 UnknownUser  
Unknown file formatodp lecture_9_upload.odp r1 manage 695.0 K 2017-11-01 - 09:29 UnknownUser  
PNGpng oneCycle.png r1 manage 18.6 K 2017-10-17 - 09:20 UnknownUser  
PNGpng pigpioCalls.png r1 manage 65.6 K 2017-10-26 - 13:43 UnknownUser  
PNGpng pigpioLib.png r1 manage 60.9 K 2017-10-26 - 13:43 UnknownUser  
PNGpng pigpioPage.png r1 manage 228.8 K 2017-10-26 - 13:43 UnknownUser  
PNGpng pigpioVariants.png r1 manage 20.7 K 2017-10-26 - 13:43 UnknownUser  
PNGpng step1.png r1 manage 4.8 K 2017-10-16 - 13:41 UnknownUser  
PNGpng step2.png r1 manage 4.7 K 2017-10-16 - 13:41 UnknownUser  
PNGpng step3.png r1 manage 4.8 K 2017-10-16 - 13:41 UnknownUser  
PNGpng step4.png r1 manage 4.6 K 2017-10-16 - 13:41 UnknownUser  
PNGpng stepTable.png r1 manage 18.3 K 2017-10-17 - 09:20 UnknownUser  
PNGpng stepperMain.png r1 manage 24.7 K 2017-11-01 - 12:02 UnknownUser  
PNGpng stepperMake.png r1 manage 48.5 K 2017-11-01 - 14:19 UnknownUser  
PNGpng stepperUsage.png r1 manage 37.5 K 2017-10-26 - 14:38 UnknownUser  
PNGpng stepping.png r1 manage 182.9 K 2017-10-16 - 12:46 UnknownUser  
PNGpng usage.png r1 manage 16.9 K 2017-10-26 - 14:38 UnknownUser  

This topic: Embedded_Systems > WebHome > LectureSlides > Lecture9:SteppingMotors
Topic revision: r8 - 2017-11-03 - uli
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback