3d printer firmware based on pyboard

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
brian park
Posts: 3
Joined: Wed Apr 17, 2019 4:43 am

3d printer firmware based on pyboard

Post by brian park » Fri Apr 26, 2019 5:06 am

hello, newbie here~

I am a big fan of the 3d printer. so I want to make a new firmware using micropython. (code name : 3DMP)
so I prepared pyboard and 3d printer stuffs (stepper, thermistor, etc).

now I tested motor, thermistor and endstop working.
maybe... I'll upload source code after testing gcode parser and heating features.
demo clip is here (https://www.youtube.com/watch?v=8k5bCPw3vCM)

If anyone is interested, I would like to develop it together.
because it is my hobby life, please participate without taking burden.
Last edited by brian park on Sun May 05, 2019 2:24 am, edited 1 time in total.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Fri Apr 26, 2019 6:09 am

I have played with stepper motors in both C and micro-python. I have found it difficult to get good step timing due the latency of python but did manage to get good ramp up and ramp down of a single stepper but the work around that I used doesn't allow for different speeds of different motors. see my 5x5x5 rubik's cube solving robot that uses steeper motors u will see smooth ramping and precision turning but any time I spin more than 1 motor at a time I spin them at same speed https://www.youtube.com/watch?v=sD4bG8hPYLQ&t=40s see the code here https://github.com/OutOfTheBots/5x5x5_cube_robot

I based my ramp up and ramp down based upon a doc sent to me by 1 of the contributors to marlin firmware (the most common used 3d printer firmware) see the link for steep ramp up and rampo down here https://www.embedded.com/design/mcus-pr ... -real-time

In C they control multiple steeper at different speeds by using timers. They calculate the time needed for next step and set the timer freq (Auto Reload Register) to that time. Then a hardware interrupt will fire when the ARR is reached and the interrupt routine will pulse the step pin then calculate the next needed step time and update the ARR. They will use a different timer for each steeper motor.

Python call backs can't be used because the latency on starting up a python call back is about 10ms and you will need timing in the us range

User avatar
mattyt
Posts: 410
Joined: Mon Jan 23, 2017 6:39 am

Re: 3d printer firmware based on pyboard

Post by mattyt » Fri Apr 26, 2019 2:06 pm

My hope is that the RMT module would help for this purpose on the ESP32 port; would you agree OutoftheBOTS?

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Fri Apr 26, 2019 9:07 pm

mattyt wrote:
Fri Apr 26, 2019 2:06 pm
My hope is that the RMT module would help for this purpose on the ESP32 port; would you agree OutoftheBOTS?
RMT is certainly probably a much better way to do the steper motors than the shitty wirk around that I used especially since it doesn't block the CPU during transfer

I usually run my steppers in at least 1/4 steps to smooth the motion of the motors and most 3d printers run in 1/16 steps super smooth motion at slow speeds. If your running a 200 step motor in 1/16 then this is 3,200 steps for 1 rotation. What is the max number of pulses the RMT can be setup for in 1 transfer and can it be programed like a double buffer where you can setup the next buffer for transfer before the last 1 has finished so to keep an endless flow of pulses??

Can the RMT module creating different pules on different pins to drive more than 1 motor?

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Fri Apr 26, 2019 9:11 pm

If you where super keen to make a good working 3D printer firmware in MP I think the best way to do it would be create C functions that control the stepping (acceleration, speed and distance stepped) via HW interrupts then wrap them up so that they can called from python.

User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

Re: 3d printer firmware based on pyboard

Post by Meekdai » Sun Apr 28, 2019 7:04 am

Many years ago I transplant the GRBL code to STM32F1 and it works well.
I think micropython can do the same.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: 3d printer firmware based on pyboard

Post by pythoncoder » Sun Apr 28, 2019 8:08 am

The other option is to use a chip such as the STM L6470. As I understand it you pass the chip a target and it handles microstepping and step rate limitations automatically.
Peter Hinch
Index to my micropython libraries.

OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Sun Apr 28, 2019 10:17 pm

Meekdai wrote:
Sun Apr 28, 2019 7:04 am
Many years ago I transplant the GRBL code to STM32F1 and it works well.
I think micropython can do the same.
Any MCU that is capable of running micro-python is capable to driving many steppers at 1 time.

Interpreted Micro-python has advantages and disadvantages compared compiled languages like C. One of the disadvantages of MP is the latency of calling a function. To turn multiple steppers at once requires very fast calling of very short functions which MP isn't capable of doing.

The easiest way to make it work well in MP would be to create a low level function in C that turns the steppers at the correct speed for correct distance e,g void move_stepper(int32_t number_steps, int_32_t max_speed) then wrap it up to be called from python as the rest could easily be written in python.

To see a good explanation of how to use HW interrupts to control 6 steppers smoothly with smooth acceleration on an Ardunio watch this video (the first half explains the problem the second half explains the solution) https://www.youtube.com/watch?v=fHAO7SW-SZI&t=1509s

User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

Re: 3d printer firmware based on pyboard

Post by Meekdai » Mon Apr 29, 2019 1:10 am

@OutoftheBOTS This is really a good idea. But I don't know how to create function in C, I just add the .py file to '../micropython/ports/stm32/modules' and make the micropython firmware. Is there any documentation I missed?

User avatar
Meekdai
Posts: 45
Joined: Mon Jan 29, 2018 12:45 pm

Re: 3d printer firmware based on pyboard

Post by Meekdai » Mon Apr 29, 2019 2:51 am

pythoncoder wrote:
Sun Apr 28, 2019 8:08 am
The other option is to use a chip such as the STM L6470. As I understand it you pass the chip a target and it handles microstepping and step rate limitations automatically.
I read the L6470 datasheet. It is similar to the TMC5130 I am currently using. It is very convenient to control a single stepper motor by SPI .However, if you need to run the interpolation data, for example, when the XY axis moves at the same time, the synchronization of the two motors cannot be guaranteed.

Post Reply