Raspberry Pi Pico controls stepper motor through serial port commands

  • This project is implemented by using Raspberry Pi Pico under Thonny compiler with MicroPython language

    The work that needs to be prepared before the start of the project is as follows:


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

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

    3. A stepping motor drive circuit

    4. STONE serial port HMI display (Customized Arduino 7-inch display)

    5. Several connecting lines

    Compile and debug software: Thonny 3.3.5

    Edited once, last by Apollo ().

  • 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.

  • Below we determine the connection of each part according to Pico’s pin diagram:

    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.

  • Finally, attach the program code:

    from machine import UART, Pin

    import time

  • 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.