This is only a preview of the May 2023 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Electronic Building Blocks
By Julian Edgar
Quick and easy construction
Great results on a low budget
Controlling RC servos with the Pololu Micro Maestro
Quick and simple programming for automatic servo movements, or manual
control with a pot or switch
I
n previous articles, we’ve looked
at selecting actuators (PE, October/
November 2022); controlling stepper
motors using an eBay pushbutton-programmable standalone module (PE,
December 2021); and controlling linear
actuators using the Pololu Jrk 21v3
PC-programmable module (PE, June/
July 2022). In both the linear actuator and
stepper motor articles, set-up and wiring
were straightforward, putting control of
these actuators into the hands of people
who may not want to learn to code.
This month, we look at the Pololu
Micro Maestro board, a PC programmable
device than can simultaneously control
up to six RC servos. Again, we’re going
to take the simplest approach: using a
pot (a manual control knob) or a switch
to control servo position. However, in
addition, we’re also going to look at how
a sequence of instructions can be used to
automatically cycle the servos through a
series of movements.
Pololu Micro Maestro
The Pololu Micro Maestro is a tiny (just
28 x 22mm), light weight (3g) board that
packs a lot of capability into a small
footprint. All connections are by header
pins – there are no screw terminals. It
costs around £40 and is available from
a wide range of sources.
Part of a family of different Maestro
servo motors controllers, the Maestro
has six channels (other Maestros
have up to 24 channels). They’re
called ‘channels’ rather than ‘outputs’
because each channel on the Micro
can be used as an RC servo drive or
as an analogue input channel. The
channel function is selected in the PC
configuration software – more on the
software in a moment.
Each servo control channel can be set
for maximum speed and acceleration,
and if an error is detected, channels can
be configured to go to a specified servo
position or turn off. The servo(s) can be
controlled from a PC via a USB cable,
by a serial connection or by an internal
program (called a script) that also
allows user control via external pots or
switches. It’s the ‘script’ approach that
we will be covering here.
the board can be powered by the USB
connection and the servos powered by
a power supply (or batteries, of course).
The servo power supply connection
(power and ground) makes available
power to all the servo channels, so only
one pair of connections is needed. See
Fig.1 for these connections.
With 4.8-6V connected to the module’s
servo power feed, the next step is to
connect a servo itself. The three-pin
female plug provided on RC servos
plugs straight into the board header
pins at any of the six channel positions
(labelled 0-5). However – and this is
important – the servo must be connected
with the correct polarity. Servo wiring
is typically:
Ground
black
brown
black
Power
red
red
red
Signal
white
orange
blue
Initial set-up and testing
The Pololu Micro Maestro board is a tiny
– just 28 x 22mm and weighing 3g – but
it can control up to 6 RC servos. The
included software gives full control over
servo position, and maximum servo speed
and acceleration.
Practical Electronics | May | 2023
To get the Micro Maestro up and running,
you will need a USB mini-B cable (not
included), an RC servo and a power
supply suitable for the operating voltage
of the servo (4.8 – 6V). The power supply
connection for the servos is separate to
the power supply for the Micro Maestro,
but since the Maestro can work on 5-16V,
the servo power supply can also supply
power to the board. Alternatively,
RC servos are versatile controllable
actuators that are ideal for operating arms
and legs in hobby robots, moving items
in animated model layouts, opening and
closing vents and many other uses. They’re
low in cost and widely available.
63
+5V regulated
Servo power
+V
+V
–V
–V
Channels 0-5
USB
connector
+V
–V
Board power
5-16V
Signal +V
–V
Channels
Fig.1. These are the connections that you’ll need to make to do all
that is covered in this article. The two-pin header for the regulated
5V supply and associated ground connection will need to be
provided and soldered into place – it’s not included.
The table is read from left to right – that is, one common plug
is black-red-white, for example. See Fig.1 or the underside
of the Maestro for these servo connections.
The next step is to load the Windows drivers and software
on to the PC. This is best done by clicking on the download
link in the excellent Micro Maestro PDF user’s guide. (The
guide is also downloadable from Pololu and its dealers.)
There is a large section in the manual on installing the
software, but with Windows 10 Pro, I just followed the onscreen prompts and had no difficulties.
Now it’s time to control the servo. With the Maestro
connected to the PC, servo power switched on and the
servo connected, open the software. Software connection
with the module is established in the Connected to pulldown. Once the PC is talking to the Maestro, you can then
tick the box to Enable the channel to which you wired the
servo. Then, without doing anything further, when you move
the relevant on-screen slider back and forth, the servo will
rotate accordingly – see: Fig.2.
Note that quick movements of the slider will give equally
quick movements of the servo. To produce smoother
movements, change the value in the Speed box. For example,
setting this to ‘5’ meant it took the test servo about 8 seconds
to go from one extreme of movement to the other. In addition
to maximum speed, you can also set maximum acceleration.
Fig.2. The Status tab allows you to easily control the movement of the servo by dragging the slider back and forth. Five different servos
can be controlled but here only one output channel has been activated.
Fig.3. In Channel Settings the speed, acceleration, minimum and maximum positions of each servo can be set. Each channel can also
be named (not done here).
64
Practical Electronics | May | 2023
Fig.4. In the Sequence tab, the use of frames (think of them as movement steps) allows a sequence of movements to be developed
and then uploaded to the module. It’s a quick and easy process, especially for repetitive movements (like making a robot walk).
10kΩ
+5V
0V
Fig.5. Using the regulated 5V and ground connections, a pot can
be energised and its variable voltage output connected to a channel
input. This allows manual control over the servo position.
By using a combination of these controls, you can have the
servo smoothly accelerate to a set maximum speed, and
then just as smoothly decelerate to a stop at the setpoint.
These effects can be judged not only from the action of the
observed servo, but also from watching the on-screen slider,
where the setpoint is shown by a marker and the actual
servo position by a dot.
Now open the Channel Settings tab. For each connected
servo, the minimum and maximum rotational positions
can be set. In this tab you can also set the servo behaviour
on start-up or when an error is detected – off, ignore or go
to, with the latter allowing the position to be specified.
In this tab you can also see the Speed and Acceleration
settings you’ve already configured, and you can name
each channel as you wish. Note that any changes need to
be uploaded to the Maestro by pressing Apply Settings –
further details in Fig.3
You might be wondering what units are used for the servo
position. These are in microseconds (µs) pulse width –
something that sounds odd until you realise that it is the
pulse width of the signal that controls servo position. (See
the breakout box for how an RC servo works.)
Fig.6. Here, Channel 5 has been altered in function to become an input. Rotation of the added pot moves the Input slider, so that it’s
easy to checking that the pot input is working.
Practical Electronics | May | 2023
65
Fig.7. This very simple
program allows the
external pot to control
the movement of the
servo. A switch can
also be used with
this program to give
full servo movement
(for example, to open/
shut a vent).
Now that we have the PC controlling the servo, let’s
program some sequences of movements.
Automatic sequential movements using frames
The Pololu software can be used to program a sequence of
movements, called ‘frames’. The software can then be used
to test and (if necessary) edit that sequence, before uploading
the collection of frames (called a script) to the Maestro. If
the script is configured to operate as a loop after switch-on,
the Maestro will then act as a standalone controller (no PC
connection needed), the sequence of servo events repeating
until power is cut.
To achieve this programmed movement, go to the Sequence
tab. The Frame name box will be empty at this stage, but
you will be able to see that there are various editing tools
and other controls available for manipulating the frames. To
create the frames, go back to the Status tab – the one with
the sliders. Set the position of the servo(s) for the first of the
sequences of movement, then press Save Frame 0. Change
the servo position and then press the Save Frame button
again. Continue with this process until you have all your
movements saved in a sequence of frames. Now return to the
Sequence tab and you’ll find the new frames listed there in
order. Press Apply Settings and then when you press Play
Sequence, the servo will make appropriate movements. If
you tick Play in loop, the sequence will run continuously.
RC servos
RC (radio control) servos were
developed for use in, not surprisingly,
radio-controlled models. However, their
versatility, low price and wide availability means that they’re now used
in a broad range of hobby activities.
Mechanically, a servo comprises
a small DC motor connected to a
geartrain, with the output shaft
splined to take various levers
and disks to which other linkages
can be connected. A servo is a
‘smart’ device – it contains control
electronics. An internal pot is used
as a position sensor, and the motor
rotates until the shaft reaches the
required angular position. This
position is then held – if the shaft
is mechanically rotated from its set
position, it actively resists.
66
However, you might notice that some movements don’t
have enough time to be completed before the next one
starts. To fix this, highlight a frame and then click on Frame
properties. The time available for each frame can then
be changed, with this time expressed in milliseconds, as
shown in Fig.4.
Pressing Copy sequence to script and then, in the Script
tab, Apply Settings lets you both see the code you’ve just
created and upload it to the Maestro, respectively. This
sequence of servo movements is now programmed into the
module and can run continuously once power is applied,
even without a PC connection. (Note: the speed and
acceleration of all the movements in the sequence can be
adjusted in Channel Settings.)
For sequences of movement, especially those that are
repetitive like making a robot walk, this approach is fast
and easy. But what if you don’t want a pre-programmed
movement sequence? Then you can use an external pot or
switch to control the servo rotation.
External manual control
Let’s now add a pot to give manual control over the servo
position. First, a 2-pin header needs to be soldered into the
GND and 5V out PCB holes. These then provide the two end
connections to a 10kΩ pot, while the wiper connects to the input
of one of the free channels (we will use Channel 5) – see Fig.5.
Servos use three connections –
power, ground and signal. The control
signal comprises a pulse train with
a varying pulse width ‘on’ time. It
is not a PWM system with varying
duty cycle, because the frequency
of the pulses can vary over a wide
range without affecting the servo’s
behaviour. (Standard frequency is
about 50Hz – a 20ms period.)
The pulse width determines
the servo’s position, with 1.5ms
corresponding to the servo’s neutral
point. That is, shorter pulse widths
than 1.5ms causes the servo to rotate
one way, and pulse widths longer
than 1.5ms cause the servo to rotate
the other way. The normal pulse
width range is 1.0ms to 2.0ms, which
corresponds to an output shaft rotation
of up to 180° degrees (maximum – but
in practice, often less than this).
Centre
position
VCC
0V
1.5ms
pulse
width
20ms period
VCC
0V
2ms
pulse
width
20ms period
VCC
0V
+90°
–90°
1ms
pulse
width
20ms period
Servo control signals use pulse width to control
servo position. 1.5ms is the neutral position;
shorter pulse widths rotate the servo in one
direction and longer ones rotate it in the other
direction. The full range is typically 1-2ms. The
frequency of the pulse train can vary but is
typically around 50Hz (a 20ms period).
Practical Electronics | May | 2023
Go to the Channel Settings tab and change the function
of Channel 5 from Servo to Input. Now back on the Status
tab, when you turn the pot, you should see the slider for
Channel 5 moving to show the changing input signal (Fig.6).
To make the system use the pot to control the position of
the servo, some scripting code is needed. However, this is
just a few lines as shown below and in Fig.7:
1 – 100kΩ
+5V
0V
Switch
begin
5 get_position
4 times 4000 plus
0 servo
repeat
Type this directly into the Script tab, tick Run script on
startup, run the script and then press Apply Settings and
the servo should move as directed by the external pot –
and continue to do so, even when disconnected from the
PC. Incidentally, if you wish to better understand the code,
the PDF manual has a good explanation. For example, if
you change the endpoints of the servo movement, you can
change the pot scaling to suit, so that there’s no dead travel
in the pot’s movement.
Even when controlled by a pot in this way, the maximum
speed and acceleration of the servo can still be set by the
previously described controls. It’s therefore easy to give a
progressive and smooth servo movement, even if the pot is
turned quickly and/or jerkily.
To move over its full rotation, a switch can replace the
pot. Pull the input up to 5V via a 1-100kΩ resistor and
then use the switch to pull the input to ground – see Fig.8.
Operation of the switch will now cause the servo to rotate
from one extreme to the other – perfect for things that need
to be open or closed, such as a vent. Again, this movement
GET T
LATES HE
T CO
OF OU PY
R
TEACH
-IN SE
RIES
AVAILA
BL
NOW! E
Fig.8. A switch allowing the servo to be set to two positions. The
input is pulled up to 5V via the resistor when the switch is open;
the input is pulled to ground when the switch is closed.
can be made to occur smoothly by using the Acceleration
and Speed controls.
Conclusion
The Pololu Micro Maestro has a lot more capability than
has been covered here (the manual is over 100-pages long).
However, in this article I have been aiming at giving you fast
and practical ways of controlling servos – methods than can
be put into immediate effect. Whether that’s opening and
closing household vents, building a walking robot or even
operating active aerodynamics on a car, the Micro Maestro
and RC servos can help achieve all that.
Order direct from
Electron Publishing
PRICE £8.99
(includes P&P to UK if ordered direct from us)
EE
FR -ROM
CD
ELECTRONICS
TEACH-IN 9
£8.99
FROM THE PUBLISHERS OF
GET TESTING!
Electronic test equipment and measuring
techniques, plus eight projects to build
FREE
CD-ROM
TWO TEACH
-INs
FOR THE PRICE
OF ONE
• Multimeters and a multimeter checker
• Oscilloscopes plus a scope calibrator
• AC Millivoltmeters with a range extender
• Digital measurements plus a logic probe
• Frequency measurements and a signal generator
• Component measurements plus a semiconductor
junction tester
PIC n’ Mix
Including Practical Digital Signal Processing
PLUS...
YOUR GUIDE TO THE BBC MICROBIT
Teach-In 9 – Get Testing!
Teach-In 9
A LOW-COST ARM-BASED SINGLE-BOARD
COMPUTER
Get Testing
Three Microchip
PICkit 4 Debugger
Guides
Files for:
PIC n’ Mix
PLUS
Teach-In 2 -Using
PIC Microcontrollers.
In PDF format
This series of articles provides a broad-based introduction to choosing and using a wide range
of test gear, how to get the best out of each item and the pitfalls to avoid. It provides hints
and tips on using, and – just as importantly – interpreting the results that you get. The series
deals with familiar test gear as well as equipment designed for more specialised applications.
The articles have been designed to have the broadest possible appeal and are applicable to all branches of electronics.
The series crosses the boundaries of analogue and digital electronics with applications that span the full range of
electronics – from a single-stage transistor amplifier to the most sophisticated microcontroller system. There really is
something for everyone!
Each part includes a simple but useful practical test gear project that will build into a handy gadget that will either
extend the features, ranges and usability of an existing item of test equipment or that will serve as a stand-alone
instrument. We’ve kept the cost of these projects as low as possible, and most of them can be built for less than £10
(including components, enclosure and circuit board).
© 2018 Wimborne Publishing Ltd.
www.epemag.com
Teach In 9 Cover.indd 1
01/08/2018 19:56
PLUS! You will receive the software for the PIC n’ Mix series of articles and the full Teach-In 2 book – Using PIC
Microcontrollers – A practical introduction – in PDF format. Also included are Microchip’s MPLAB ICD 4 In-Circuit Debugger User’s Guide; MPLAB PICkit 4 In-Circuit Debugger Quick Start Guide; and MPLAB PICkit4 Debugger User’s Guide.
ORDER YOUR COPY TODAY: www.electronpublishing.com
Practical Electronics | May | 2023
67
|