Raspberry Pico based motor stage

Hi everyone, I designed motor stage hat for Raspberry based on Raspberry Pico instead of an arduino. I also ported sngaboard firmware so it works on pico.
It uses serial on GPIO header instead of an USB cable which makes everything smaller.
It needs a litle configuration, but works fine.

https://oshwlab.com/alte/openflexure-board_copy
I hope it will be usefull.

Thera are two things which needs to be done to say it’s compleated:

  • I dont have LED grid so it’s not tested.
  • LED is powered via PIN capable of PWM. It would be nice to have possibility to control brightness directly from app. To do this an extension is needed for the Openflexure app but unfortunatelly this beyond my programming skills so it will take some time. The other thing which needs to be done is to add a new function to the Pico firmware but that will be easy.
2 Likes

That is great work @Pepa. I was not able to see the ported firmware in your link above, only the hardware design. Looking at the board design around the camera cable slot there is only ground plane on top and bottom layers. That means that it is possible to extend the slot to the edge of the board, which makes it a bit easier to fit and remove the board and cable.

Open slot is a great idea, I have updated the PCB according to your suggestion. I will add u2f file for Pico today.
I’am working on some changes in code:

  • PWM for motor control to lower motor current when motors don’t move. This will keep motors cooler without fear of losing position
  • LED PWM

Because of that source code is a little bit messy at this point. I will upload it when i’am done

1 Like

I have updated firmware for Pico so now LED PWM works. Somehow I figured out (with the help of existing extensions and documentation) how to make my own extension. So now I can control the LED directly from the Openflexure app. The only problem is that I don’t know why extension icon doesnt appear.
The last thing to do is to reduce the current of the motors at idle.

1 Like

Everything done, all files updated. Motors idle current can be reduced, value can be set by serial port and saved in EEPROM. Initial value is about 50% of working current. In my case motors are much cooler.

1 Like

Amazing work @Pepa! I recently made a new Sangaboard based on the RP2040 microcontroller with integrated illumination control. The new Sangaboard firmware supports the pico and has partial support implemented for LED control (on/off only, the plan is to PWM it at high frequency to avoid flickering), the source is at Files Β· sangaboard-v5 Β· Filip Ayazi / sangaboard-firmware Β· GitLab (the master branch also works on the pico), just adjust boards.h with your wiring.

PWM motor current control sounds awesome! Is the source for your firmware available somewhere?

1 Like

I have uploaded arduino sketch. Be aware that my sketch works only with arduino core from earlephilhower. I didn’t uploaded it before because I still need to clean it and do some changes. For this moment I just wanted to chceck if everything works fine.
In my case PWMs are set to 50kHz so there is no flickering.

1 Like

I’ve tried to download files from the web site, but it isn’t possible! One gets into a circular loop with being told you have to login to download, logging in, then being told again that you have to log in. Are the files really available for download?

Yes files are available for download. I tried downloading them and everything worked fine.

Well, I tried again, using both Firefox and Chrome, with the same result. Oh well.

The site does seem to require login for downloading the files. If you were able to post the files somewhere without a login it would be of wider availability to the community, or is there a setting you can make in OSHWlab to not need login for the files? You should be able to post the files here, unless it hits a file size limit or put them into an issue or merge request in the OpenFlexure / openflexure-microscope-extra section of the project on Gitlab.

I am interested in using a spare Pi Pico I have and have printed out everything (master stand and electronic drawer along with the nano conversion board that has the Pico seat and then some custom mounts for a different stepper motor board layout) but am not sure what the status of this is. Is there a good description on how to connect everything when using the RPi Pico vice the nano in the non-sanga board variants?

In the main project, the Sangaboard V0.5 is based on the same microcontroller as the Pi Pico, but there is not yet a documented way to set up an actual Pico as a motor controller for Openflexure. There are some design decisions in the Sangaboard V0.5 that unfortunately use pins that are not available on the Pico. There are enough Sangaboard V0.5 in circulation that the pin choices are unfortunately locked in. The main motor functions are all on available pins, but extended functions use pins that are reserved on the Pico. This means that there should be a modified firmware used on a Pico to give only the main functions, to avoid any unexpected behaviours.

None of this is yet implemented. The fact that the Pico is 3.3V logic means that it is in principle also possible to use the serial port on the Pi instead of the USB, which frees the USB on the Pico as a power input for the motors. Again this is not documented because there is not yet a suitable firmware version.

I was looking at the current version of the Filip Ayazi / sangaboard-firmware Β· GitLab repository. I have built the Pico firmware by setting the following defines in the config.h file:

    #define MCU_PICO
    #define BOARD_CUSTOM_PICO

and have seen the default pinout config for the pico in the boards.h file.

#elif defined(BOARD_CUSTOM_PICO)
    #define BOARD_STRING "Custom Pico board"
    #define WIRING_MOTOR_X 2, 3, 4, 5
    #define WIRING_MOTOR_Y 6, 7, 8, 9
    #define WIRING_MOTOR_Z 10, 11, 12, 13
    #define ENDSTOPS_INVERT false
    #define ENDSTOPS_PULLUPS true
    #define WIRING_ENDSTOPS_MIN {A0,A1,A2}
    #define WIRING_ENDSTOPS_MAX {A3,A4,A5}
    #define ADDITIONAL_STEPPERS 1
    #define WIRING_ADDITIONAL_STEPPER 0, 1, 22, 23
    #define WIRING_STEPSTICK {13,14,15} //enable, step, dir todo: move to boards.h
    #define PRIMARY_SERIAL_PORT Serial
    #define SECONDARY_SERIAL_PORT Serial2
    #define PWM_NUM 0
    #define WIRING_PWM_LEDS {}
    #define SUPPORT_EEPROM
    #define STAGE_MAX_MOTORS 4

So, my question is, some of the pinouts are specified as a number and some as an identifier (eg. A0, A1, A2). Is PIN number the PIN number on the board or a GPIO number?

Secondly, I see that the PWM_NUM is set to 0, so that does that mean that is disabled? (I know there was some discussion that the PI Pico does not export all of the same pins as the Sangaboard.)

Also, I see there are elements here about end stops, I have not seen a build which factors in safety devices such as end stops. Is this a special variant?

It’s the GPIO number, I think the A* numbers are a leftover from when the config was copied from an arduino based board, and since the endstops module is normally disabled it didn’t matter.

PWM_NUM is set to 0 because using it (at least with a more powerful LED) requires additional electronics (a mosfet and a resistor), there should be no issues with enabling it on any available pico PWM pin.

I added support for endstops built into the microscope feet many years ago, there is an endstop module and if it is enabled in config.h it will check endstop status while moving and add homing support, but this is only implemented on the lowest levels of the stack (firmware, pysangaboard). As far as I know no one has used this in years, so consider it experimental.

Great! Thanks for the info.

I have a follow-on question on the pins. AFAIK, Serial is GP0 and GP1 but there there is the definition for the WIRING_ADDITIONAL_STEPPER which is set to use GPIOs 0, 1, 22, and 23. This seems to step on the default Serial definition. I have just disabled that stepper by setting the STAGE_MAX_MOTORS to 3. Is this a correct approach.

As for powering the Pico, I plan to run a 5V off the RPi to the VBUS pin on the Pico and then run a 5V from a wall wart to power the motors and tie all of the grounds together.

The LED is running off the 5V line on the Raspberry Pi 4 as well.

Does all of this sound good to go for right now?

1 Like

Sounds good to me, those are the default pins for Serial but they can be changed somewhat and there are 2 UARTs available if I remember correctly, the Sangaboard uses serial via pins 8 and 9 so pin 0 was available for the extra stepper (WIRING_SERIAL_* defines in boards.h). There’s certainly no harm in disabling the extra stepper if you are not using it.

Unless you have some space restrictions I think it might be easier to use a USB connection between the pico and the pi, it should work out of the box and it avoids the need for separate pico power. However, using a direct serial connection to the Pi’s serial should work too.

This is my current progress. Not my best, but I think it might work.

All I need to do now is connect the 12 wires for the steppers and I should be making good progress.

2 Likes

Well, I am not having the best of luck here. I have enabled the serial port and through the raspberry pi configuration routines (disabled the serial console but enabled the serial hardware) and have wired Pico GPIO pins 0 and 1 to the Raspberry Pi V4 GPIO 14 and 15 (with Tx β†’ Rx and vice versa). I have done the ofm update and off upgrade, as well as the ofm activate and pip install sangaboard commands as suggested in other threads. I have also switch to git server by doing a ofm develop. Nothing seems to work. I keep getting this in my log files:

Jan 11 11:35:46 microscope python[507]: INFO:root:Trying port /dev/ttyAMA0 with settings {'baudrate': 115200, 'bytesize': 8, 'parity': 'N', 'stopbits': 1}
Jan 11 11:35:46 microscope python[507]: INFO:root:Creating serial.Serial instance...
Jan 11 11:35:46 microscope python[507]: WARNING:root:The serial port didn't close cleanly: 'Sangaboard' object has no attribute '_ser'
Jan 11 11:35:46 microscope python[507]: INFO:root:Trying port /dev/ttyAMA0 with settings {'baudrate': 115200, 'bytesize': 8, 'parity': 'N', 'stopbits': 1}
Jan 11 11:35:46 microscope python[507]: INFO:root:Creating serial.Serial instance...
Jan 11 11:35:46 microscope python[507]: WARNING:root:The serial port didn't close cleanly: 'Sangaboard' object has no attribute '_ser'
Jan 11 11:35:46 microscope python[507]: INFO:root:Trying port /dev/ttyS0 with settings {'baudrate': 115200, 'bytesize': 8, 'parity': 'N', 'stopbits': 1}
Jan 11 11:35:46 microscope python[507]: INFO:root:Creating serial.Serial instance...
Jan 11 11:35:46 microscope python[507]: INFO:root:Created Serial<id=0xb3a83690, open=True>(port='/dev/ttyS0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
Jan 11 11:35:46 microscope python[507]: INFO:root:Testing communication to SangaBoard
Jan 11 11:35:46 microscope python[507]: INFO:root:Running firmware checks...
Jan 11 11:35:46 microscope python[507]: INFO:root:Trying port /dev/ttyS0 with settings {'baudrate': 115200, 'bytesize': 8, 'parity': 'N', 'stopbits': 1}
Jan 11 11:35:46 microscope python[507]: INFO:root:Creating serial.Serial instance...
Jan 11 11:35:46 microscope python[507]: INFO:root:Created Serial<id=0xb3c76f50, open=True>(port='/dev/ttyS0', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False)
Jan 11 11:35:46 microscope python[507]: INFO:root:Testing communication to SangaBoard
Jan 11 11:35:46 microscope python[507]: INFO:root:Running firmware checks...
Jan 11 11:35:46 microscope python[507]: ERROR:root:We don't have a serial port to open, meaning you didn't specify a valid port.  Are you sure the instrument is connected?

Edit: I should add that I get the following when trying to access the Pico from the Pi directly:

sudo miniterm /dev/ttyAMA0 115200
--- Miniterm on /dev/ttyAMA0  115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
B␀␀␕␀␀␑␀␀
␀ED␀
␀␀␀���␒␀␀␂␀␀␀␒␕"␔␀␑␀E␀␀␀���␒␀␑␀␀␀␀␀␀␀␀␀␀␀␀␀␕␀␀␀␀␀␀␀���␒␀␀␀RHH␀␀��␒␀␀␀HH␀␀␀␀␀	␀␑␀␀␀␀␀␀␀␀␀"	␑␀␀␀␀␀	␀	␀␑␀␂���␒␀␀␀RHH␀␔$␀␀␂���␒␀␀␀␑␀␀␀␀␀HH"␀␀␀␀R␀␀␂␀␀␀␀␀␀␀␀HHHH␀␀␀␀D␀␀␀␀␀␀␀␀␀RHH␀␀␀HH␀␀(οΏ½
)(␄�UE␅␀␀␀␀␀␀HH"��␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀�␀␀!␀␀U!D␀␀ ␀␀␀␀␀␀␔␀␀␀␀␀␀␀␀␀␀RHH␀␀␔␀␕␀␀␀␀␀␀␀�␀␂␀␀␀␑␀␀␒␑␀␀D␀␂␀␀␀␀␀␀␀␀␀␑␀␀␀���␒␀␑␒␀␀␀J
οΏ½
␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀␀
--- exit ---

Hmm, have you changed SECONDARY_SERIAL_PORT in boards.h to be Serial1?