Pi IoT In Python Using GPIO Zero - DC Motors
Written by Harry Fairhead & Mike James   
Monday, 23 November 2020
Article Index
Pi IoT In Python Using GPIO Zero - DC Motors
Unidirectional Brushed Motor

Motors are a central part of the IoT but they are often taken for granted. In this extract from a new book on using GPIO Zero on the Pi in Python we look at basic DC Motors.

Raspberry Pi IoT In Python Using GPIO Zero
Second Edition

By Harry Fairhead & Mike James

GPIOZero2E360

Buy from Amazon.

Contents

  1. Why Pi for IoT?
  2. Getting Started With Python And GPIO Zero
  3. Introduction to the GPIO
  4. Python - Class and Object
  5. Simple On/Off Devices
      Extract 1: On/Off Devices *
  6. Pins And Pin Factories
      Extract 1: Pins 
  7. Some Electronics
  8. Simple Input
      Extract 1:Getting Input ***NEW!!
  9. Complex Input Devices
      Extract 1: Complex Input *
  10. Pulse Width Modulation
      Extract 1:  PWM*
  11. Controlling Motors And Servos
      Extract 1: DC Motors *
  12. Working With Compound Devices
      Extract 1: Compound Devices*
  13. The SPI Bus
  14. Custom SPI Devices
  15. Using The Lgpio Library
  16. Appendix Visual Studio Code Remote Python
    *Extracts from first edition - will be updated.

 <ASIN:1871962870>

Motors form an important class of output devices and they are fairly easy to use, but it is important to understand the different types of motor that you can use.

The simplest division among types of motor are AC and DC. AC motors are generally large and powerful and run from mains voltage. As they are more difficult to work with, and they work at mains voltages, these aren’t used much in IoT applications. DC motors generally work on lower voltage and are much more suitable for the IoT. In this chapter we will only look at DC motors and how they work thanks to pulse width modulation.

DC Motor

There are two big classes of DC motor – brushed and brushless. All motors work by using a set of fixed magnets, the stator, and a set of rotating magnets, the rotor. The important idea is that a motor generates a “push” that rotates the shaft by the forces between the magnet that makes up the stator and the magnet that makes up the rotor. The stronger these magnets are, the stronger the push and the more torque (turning force) the motor can produced. To keep the motor turning, one of the two magnetic fields has to change to keep the rotor being attracted to a new position.

DC motors differ in how they create the magnetism in each component, either using a permanent magnet or an electromagnet. This means there are four possible arrangements:

 

1

2

3

4

Stator Permanent Permanent Electromagnet Electromagnet
Rotor Permanent Electromagnet Permanent Electromagnet
Type Can’t work Brushed DC Brushless DC Series or shunt

Arrangement 1 can’t produce a motor because there is no easy way of changing the magnetic field. Arrangement 4 produces the biggest and most powerful DC motors used in trains, cars and so on. Arrangement 2, Brushed DC, is the most commonly encountered form of “small” DC motor. However, arrangement 3, brushless DC, is becoming increasingly popular.

Different arrangements produce motors which have different torque characteristic – i.e. how hard they are to stop at any given speed. Some types of motor are typically low torque at any speed, i.e. they spin fast but are easy to stop.

Low torque motors are often used with gearboxes which reduce the speed and increase the torque. The big problem with gearboxes, apart from extra cost, is backlash. The gears don’t mesh perfectly and this looseness means that you can turn the input shaft and at first the output shaft won’t move. Only when the slack in the gears has been taken up will the output shaft move. This makes a geared motor less useful for precise positioning, although there are ways to improve on this using feedback and clever programming.

Brushed Motors

To energize the electromagnets, a brushed motor supplies current to the armature via a split ring or commutator and brushes. As the rotor rotates, the current in the coil is reversed and it is always attracted to the other pole of the magnet.

The only problem with this arrangement is that, as the brushes rub on the slip ring as the armature rotates, they wear out and cause sparks and hence RF interference. The quality of a brushed motor depends very much on the design of the brushes and the commutator.

brushed

Very small, cheap, brushed DC motors, of the sort in the picture below, tend to not have brushes that can be changed and when they wear out the motor has to be replaced. They also tend to have very low torque and high speed. This usually means that they have to be used with a gearbox. If you overload a brushed motors then the tendency is to demagnetize the stator magnets. The cheapest devices are basically toys.

motor1

Higher quality brushed motors are available and they also come in a variety of form factors. For example, the 775 motor is 66.7x42mm with a 5mm shaft:

motor2

Even these motors tend not to have user serviceable brushes, but they tend to last a long time due to better construction.



Last Updated ( Monday, 23 November 2020 )