PICO as interface from USB-Serial to Stepper PED Lines

@Manuel_Angel, here is my first take to the converter from USB-Serial to Stepper PED lines (Pulse Enable Direction).

I looked through your code, and here are some of the design parameters:

  • Single character control.
  • 8KHz pulse frequency (used as startup default).
  • 1600 pulses for one turn (used as startup default).
  • Mode to continuously move stepper.
  • Individual controls for Enable, Direction, and LED lines.
  • All lines are active high (from your wiring diagram).

I think that the implementation of continuously moving frames in your code is based on repeating a frame pulse sequence… did not dig deep enough. The implementation in PICO actually provides a continuous mode (basically a pulse generator mode), in addition to the turn one frame command.

The code:

  • Controls 4 IO Outputs in the PICO (Pulse, Enable, Direction, and LED).
  • Allows to set/change the frequency of the pulses to the following discrete outputs: ~8KHz ~7KHz, ~6KHz, 5KHz, 4KHz, ~3KHz, and 2KHz.
  • Allows changes the quantity of pulses for the Turn command to the following discrete values: 200, 400, 800, 1600, 3200, 6400, 12800, 25600, and 51200.

The code for the PICO (in C) will not win any writing contest, but it worked well in the initial testing, and it is quite simple to allow changes/improvements as needed.

PDF documentation provides info on communicating from Raspberry Pi (in Python).

I did not yet implement acceleration/deceleration for the stepper pulses, all the pulses have the same timing… did not want to delay the initial release with the additional testing, can do so at a later update.

Check the PDF in the repository for all the info.

EDIT: In the flash folder of the repository is the compiled/link flash file (EF2 extension) that you can drop directly on the pico.

3 Likes

Hi @PM490,

First of all, thank you for your work and your time.

I’m going to study the code. I have some knowledge of C although I haven’t practiced it since the days of the old DOS.

Actually I think that controlling the lighting and the motor should not present any difficulties. What I see as more complicated to carry out is the RPi 5 - Pico bidirectional communication.

Throughout the week I hope to have a Pico to do the first tests. Instead of purchasing a bare Pico, I thought about purchasing this board that makes prototyping easier.

Best regards

1 Like

You are welcome. Hopefully this post and code will ease the control of single-stepper projects.

The document in the repository provides python sample code (forgot to include the import serial). Communication is one-way (RPi to Pico), except for the startup message to confirm that it is up (PICO to RPi).

That makes it easy to prototype, specially the labels. Keep in mind that labels in at the PICO are in the bottom. There are some cool prototypes with the labels PICO port labels on the side.

If you prefer and/or are looking at doing other projects with PICO, the Board you linked looks a good deal, and more than what you need for the stepper. I saw that there is a version with the PICO on headers (instead of the PICO soldered).
The only minus I saw was that they appear to have the LED also on the pins corresponding to the PICO ADC, but that would be a factor only for ADC projects.

For this test, if you were using dupont-connector wires from the PCB to the RPi, basically only need to move those dupont-connectors from the RPi male-header to the Pico male-header (not even a prototype would be needed).

One item that you do need is a USB-A to USB-micro with data capabilities (not all charging cables pass data). It will connect between the PICO and a RPi USB port. The PICO is powered through the USB cable.

Until you get the tool-chain going, don’t hesitate to ask if you need to make any changes to the code.

2 Likes

… here’s the one I am using. It has terminals as well as indicator LEDs, making it rather easy to connect to external hardware and checking basic IO-operations.

3 Likes

Hi @PM490,

Once all the assembly related to the Pico is working and in order, I have begun testing with the software that you have kindly provided.

I have to say that I have not used it as you sent it.

To avoid making changes to the wiring of my device, I have modified the pin assignments of the Pico. Logically I have recompiled the program.

To flash the Pico I used the .elf file, loading it into the Pico using the SWD interface and the openocd utility.

After restarting the Pico everything worked as expected.

As a terminal I have used the minicom program. The software responds perfectly to the different commands entered from the terminal.

Now I have to adapt it to my own software so that everything works as expected during film digitization.

Thank you very much for all your support.

Best regards.

3 Likes

Congratulations @Manuel_Angel, fantastic progress.

I was going to, and forgot to #define the pins to make it easier to change in one place. I just added the #define to the main.cpp in the repository.

Glad everything worked, and congratulations again!

3 Likes