Raspberry Pi Pico controls stepper motor through serial port commands

Thread Starter

Young2

Joined Dec 7, 2020
34
This project is implemented under Thonny compiler using Raspberry Pi Pico using MicroPython language

The following tasks need to be prepared before starting the project.

Hardware.

1. Raspberry Pi pico board (from: https : //www.raspberrypi.org/products/raspberry -pi-pico/)

2. 28byj-48 stepper motor (from: https://components101.com/motors/2byj-48-stepper-motor)

3. stepper motor driver circuit

4. a serial HMI display (from: https://www.stoneitech.com/)

5. a few connection lines

Compilation and debugging software: Thonny 3.3.5
 
Last edited:

Thread Starter

Young2

Joined Dec 7, 2020
34
Now that the above conditions are ready, let’s start the experiment:

Before connecting, we need to flash the firmware for Pico. The method is to press and hold the bootsel button on the Pico board to connect to the computer through the USB port. At this time, the Pico will be recognized as a removable hard disk. After opening, there are two Files, one of which is the official website link, we click on it.
a3vyv4ponp4ix9h9s9i5afs042pna5qg.png
 

Thread Starter

Young2

Joined Dec 7, 2020
34
Then find the Download UF2 file to download the MicroPython firmware, after downloading it, copy it to the mobile hard disk RPI-RP2, Pico will automatically restart and the mobile hard disk will pop up, which means that the firmware has been successfully flashed, and it is best to reconnect at this time USB cable.
xhsi76c5j9mcudrlzf1oobccutozi0hl.png
 

Thread Starter

Young2

Joined Dec 7, 2020
34
Below we determine the connection of each part according to Pico’s pin diagram:
oxgeks15qq0gkexgpu30cejgk8n42v76.png

I use a five-wire four-phase motor, so I need to connect four gpio lines to the Pico. Here I choose IN1, IN2, IN3, and IN4 of the drive circuit to correspond to GP9, GP10, GP11, and GP12 on the Pico. , And then the drive circuit also needs a voltage of 5-12V, so here I use the VBUS on the Pico board to provide it with a 5v voltage, and then connect the negative pole of the drive circuit to the GND of the Pico, then this part of the connection is finished.

The following is the connection to the serial screen. There are four sets of UART provided on the Pico board. Choose one of them for connection. Connect the serial screen. The TXP of the serial screen is connected to the RX of the Pico, the RXP of the serial screen is connected to the TX of Pico, and the GND is connected to GND.
 

Thread Starter

Young2

Joined Dec 7, 2020
34
Then there is the software debugging part:

Open Thonny and select Raspberry Pi Pico in the lower right corner. When the shell command window prompts as follows, it means that Thonny and Pico are successfully connected:
b7q1g9y8qbt4ffsl1zthxqtmstd4abxr.png
 

Thread Starter

Young2

Joined Dec 7, 2020
34
When the following prompt appears, it usually means that Pico is running a program. You can press Ctrl+C to interrupt the program according to the prompt.
c6rh73iihmqbr4pl1ysjvd7d50dnk33x.png
 

Thread Starter

Young2

Joined Dec 7, 2020
34
The program demonstration effect is: when the switch on the screen is pressed to open, the motor rotates forward, and when it is pressed to close, the motor rotates backward, which can be modified as needed.
Another point to note is that the above process is debugged and run in the Thonny environment. If you want to download the program to the pico board, just use the save button of Thonny to rename the python file to main.py and save it in the internal space of pico.
 
Top