Ways of Connecting Stepper Motor With Raspberry Pi

by Mark Liu in Circuits > Software

24 Views, 0 Favorites, 0 Comments

Ways of Connecting Stepper Motor With Raspberry Pi

E110EFA2-CA97-46f6-BCC0-0249374A1281.png

Raspberry Pi Raspberry Pi is the first embedded Linux board that became popular in various circles. It is essentially a small computer about the size of a credit card. the Raspberry Pi is widely used in various projects. Among them, using the Raspberry Pi to control the rotation of the stepper motor is a common task. In this article, you will learn how to use the Python programming language and the GPIO library to implement this function, and introduce the corresponding wiring methods.

Supplies

Required materials

1 ) Raspberry Pi (Raspberry Pi 3B+ or a newer version is recommended)

2) Stepper motor (e.g. model NEMA 17)

3) Motor driver board (e.g. DRV8825 or A4988)

4) Several DuPont leads

5) 12V DC power adapter

6) Breadboard (optional)

Wiring Method

1 ) Connect the four wires of the stepper motor to the A1, A2, B1 and B2 interfaces of the motor driver board.

2) Connect the positive pole of the power supply to the VMOT interface of the motor driver board, and connect the negative pole to the GND interface

3) Connect the 5V pin of the Raspberry Pi (such as GPIO 2) to the VCC interface of the motor driver board, and connect the GND pin of the Raspberry Pi (such as GPIO 6) to the GND interface of the motor driver board.

4) Connect the GPIO pins of the Raspberry Pi (such as GPIO 17, 18, 27 and 22) to the DIR, STEP, MS1 and MS2 interfaces of the motor driver board respectively.

Python Code Implementation

F6ACD176-F256-4d1f-B576-5635E2FA8604.png

Firstly, install the Raspberry Pi GPIO library. Enter the following command in the terminal:

Create a Python File Named Stepper_motor

E110EFA2-CA97-46f6-BCC0-0249374A1281.png

Secondly, create a Python file named stepper_motor.py and enter the following code

Save the File and Run in Terminal

7B087451-1C82-4f38-A997-655BE59E14F2.png

Lastly, save the file and run in terminal.

 Please adjust the parameters in the code according to actual needs to meet your project requirements.