With this project we will manage a Stepper Motor 28BYJ-48, using the FTDI FT232H development board (of which there is a dedicated page on this site). The Stepper Motor must be connected to a control board based on STMicroelectronics ULN2003 chipset.
This Stepper Motor must be connected to the ULN2003 board, while the latter must be connected to the FTDI FT232H development board. The connection connectors are listed below:
Image | Board FT232H | ULN2003 board |
---|---|---|
AD0 | IN1 | |
AD1 | IN2 | |
AD2 | IN3 | |
AD3 | IN4 | |
+5V | VCC | |
GND | GND |
To manage this Stepper Motor, the presence of the "PyFTDI" library is required.
The following Python code example firstly runs the Stepper Motor fast, then slowly:
from os import environ from pyftdi.gpio import GpioAsyncController import time clockwise = [[0b1000], [0b0100], [0b0010], [0b0001]] def MotorCW(time_s, speed): counts = int(time_s /speed/16) for i in range(counts): for i in range(4): _gpio.write(clockwise[i]) time.sleep(speed) _gpio.write(0) def MotorCCW(time_s, speed): counts = int(time_s /speed/16) for i in range(counts): for i in reversed(range(4)): _gpio.write(clockwise[i]) time.sleep(speed) _gpio.write(0) _ctrl = GpioAsyncController() url = environ.get('FTDI_DEVICE', 'ftdi:///1') _ctrl.configure(url, direction=0b0, frequency=None, initial=0b0) _gpio = _ctrl.get_gpio() _gpio.set_direction(0b1111, 0b1111) try: print("\nFast Clockwise...") MotorCW(20, 0.0020) time.sleep(0.5) print("\nFast Counterclockwise...") MotorCCW(20, 0.0020) time.sleep(0.5) print("\nSlow Clockwise...") MotorCW(20, 0.010) time.sleep(0.5) print("\nSlow Counterclockwise...") MotorCCW(20, 0.010) except KeyboardInterrupt: # Capture keyboard ^C to exit the program print('\nYou terminated the program. The program ends!') _gpio.write(0)