Pi IoT In Python Using GPIO Zero - DC Motors |
Written by Harry Fairhead & Mike James | |||
Monday, 23 November 2020 | |||
Page 2 of 2
Unidirectional Brushed MotorA brushed motor can be powered by simply connecting it to a DC supply. Reversing the DC supply reverses the direction of the motor. The speed is simply proportional to the applied voltage. If all you want is a unidirectional control then all you need is a PWM driver that can supply the necessary current and voltage. A single transistor solution is workable as long as you include a diode to allow the energy stored in the windings to discharge when the motor is rotating, but not under power: This circuit is simple and will work with motor voltages up to 40V and motor currents up to 5A continuous, 8A peak. The only small point to note is that the TIP120 is a Darlington pair, i.e. it is two transistors in the same case, and as such the base voltage drop is twice the usual 0.6V, i.e. 1.2V, and this has to be taken into account when calculating the current-limiting resistor. It is sometimes said that the TIP120 and similar are inefficient power controllers because, comprising two transistors, they have twice the emitter collector voltage you would expect, which means they dissipate more power than necessary. If you are running a motor from a battery you might want to use a MOSFET, but as described earlier 3.3V is low to switch a MOSFET on and off. One solution is to use a BJT to increase the voltage applied to the gate: The BJT connects the gate to 12V. As the IRFZ44NPBF has a threshold voltage between 2V and 4V devices should work at 5V and sometimes at 3.3V without the help of the BJT, but providing 12V ensures that the MOSFET is fully on. One problem with the circuit is that the use of the BJT inverts the signal. When the GPIO line is high the BJT is on and the MOSFET is off and vice versa. In other words, GPIO line high switches the motor off and low switches it on. This MOSFET can work with voltages up to 50V and currents of 40A. The 2N2222 can only work at 30V, or 40V in the case of the 2N2222A. A third approach to controlling a unidirectional motor is to use half an H‑bridge. Why this is so-called, and why you might want to do it, will become apparent in the next section on bidirectional motors. Half an H‑bridge makes use of two complementary devices, either an NPN and a PNP BJT or an N- and P-type MOSFET. For example: If the GPIO line is high then Q1 is on and Q2 off and the motor runs. If the GPIO line is low then Q1 is off and Q2 is on and the motor is braked – it has a resistance to rotating because of the back EMF generated when the rotor turns. You probably need a BJT to feed the MOSFETs as selected. There is no GPIO Zero class to control a unidirectional motor, but it is easy to create one from PWMOutputDevice: class uniMotor(PWMOutputDevice): def __init__(self, pin=None, active_high=True, initial_value=0, We have simply added a speed method. The inherited methods on and off are still useful, but it might be better to block access to pulse and blink. Also notice that if you are using the transistor/MOSFET driver, then setting active_high=False solves the need to provide an inverted pulse. In rest of chapter:
Summary
Raspberry Pi IoT In Python Using GPIO Zero
|
|||
Last Updated ( Monday, 23 November 2020 ) |