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.
OutoftheBOTS_
Posts: 847
Joined: Mon Nov 20, 2017 10:18 am

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Mon Apr 29, 2019 5:44 am

Meekdai wrote:
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?
https://micropython-dev-docs.readthedoc ... odule.html

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 » Mon Apr 29, 2019 6:08 am

Meekdai wrote:
Mon Apr 29, 2019 2:51 am
...
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.
Good point, I hadn't thought of that.
Peter Hinch
Index to my micropython libraries.

User avatar
brian park
Posts: 3
Joined: Wed Apr 17, 2019 4:43 am

Re: 3d printer firmware based on pyboard

Post by brian park » Wed May 01, 2019 12:43 am

[quote=OutoftheBOTS_ post_id=36152 time=1556516642 user_id=3423]
[quote=Meekdai post_id=36149 time=1556500245 user_id=3668]
@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?
[/quote]

https://micropython-dev-docs.readthedoc ... odule.html
[/quote]

can I use arduino code in the C code? what I mean.. if I can use Marlin timer code in the C code, I think it's also alternative solution.

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

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Wed May 01, 2019 8:01 am

brian park wrote:
Wed May 01, 2019 12:43 am
OutoftheBOTS_ wrote:
Mon Apr 29, 2019 5:44 am
Meekdai wrote:
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?
https://micropython-dev-docs.readthedoc ... odule.html
can I use arduino code in the C code? what I mean.. if I can use Marlin timer code in the C code, I think it's also alternative solution.
I have used ISR in Ardunio and I have used HW interrupts in C on a STM32 MCU (NVIC_EnableIRQ and _IRQHandler). The Ardunio code uses some higher level code that sits on top of the lower level C code so you will need the lower level C code that like what it is the Marlin firmware. The ardunio video that I linked is really good to explain what is needed but to compile it into the Micro-python firmware you will need C code but the concept of how it works is the same it is just lower level code.

I have never looked at the Marlin firmware but I believe it maybe more complex with how it ramps up and down compared to what I used and what is used in the ardunio video I linked. Botgh mysefl and the video just used linear ramp up and ramp down like the very first part of the doc that I linked but I do believe marlin uses curved ramp up and ramp down like the second part of the doc that I linked before.

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

Re: 3d printer firmware based on pyboard

Post by Meekdai » Wed Jul 03, 2019 12:11 pm

I found an interesting project https://github.com/Nikolay-Kha/PyCNC
Typically there is no way to control stepper motors from Linux runtime environment due to the lack of real time GPIO control. Even kernel based modules can not guarantee precise control of pulses for steppers. However, we can use a separate hardware module, DMA (Direct Memory Access) which provides high precision for GPIO outputs. This module can copy bytes which represent GPIO states from RAM buffer directly to GPIO with some clock based on main chip internal oscillator without using CPU's cores. Using such approach this project generates impulses for moving stepper motors and that is very precise way regardless CPU load and OS time jitter.
This approach also allows to use Python language for this project. Typically, Python is not good choice for real time application, but since project just needs to set up DMA buffers and hardware will do the rest, Python become the perfect choice for easy development of this project.
It uses DMA to solve this problem. Can Micropython use DMA too?

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

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Wed Jul 03, 2019 8:35 pm

Even the DMA workaround on Linux systems isn't written in python but rather the underlying DMA functionality is written in C then wrapped up to be able to be called from python.

Python is a high level language and much better than C for writing the high level application (wrapping low level functionality into a finished usable application), C is is a low level language and great for writing low level functionality (writing the low level building blocks)

They use DMA to drive the step pulses in Linux because Linux isn't real time, Micropython is real-time just too slow in calling a function for the speed needed in step pulses. To create good stepper motor control in Micropython it will just require writing the low level motor pulses in C then wrapping them up to call from python.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: 3d printer firmware based on pyboard

Post by pidou46 » Thu Jul 04, 2019 7:00 am

OutoftheBOTS_ wrote:
Fri Apr 26, 2019 9:07 pm
mattyt wrote:
Fri Apr 26, 2019 2:06 pm
What is the max number of pulses the RMT can be setup for
From espressif RMT doc: https://docs.espressif.com/projects/esp ... s/rmt.html
Selection of the clock source, note that currently one clock source is supported, the APB clock which is 80Mhz - rmt_set_source_clk()
That mean a fairly high theorical motor speed: 25000RPM

I'm definetly thinking that a decent way to drive steppers with MP is a must have.

RMT would be a good solution for me because I'm a ESP32 user, but it is not portable to other platform, maybe C function would be more portable ? idealy it would be build into the firmware (it seems to but really lightweight), unfortunatly it a unreachable goal for me.

Still, I'm interested in that subject and will follow it closely.
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

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

Re: 3d printer firmware based on pyboard

Post by OutoftheBOTS_ » Thu Jul 04, 2019 9:35 pm

I'm definetly thinking that a decent way to drive steppers with MP is a must have.

RMT would be a good solution for me because I'm a ESP32 user, but it is not portable to other platform, maybe C function would be more portable ? idealy it would be build into the firmware (it seems to but really lightweight), unfortunatly it a unreachable goal for me.

Still, I'm interested in that subject and will follow it closely.
The RMT peripheral hasn't yet been implemented in python either so it needs the underlying C code to be written then wrapped up to be called from python.

3D printers and other CNC machines as well as steppers are not new and methods fro driving them have been worked out that work very well. I don't think it needs reinventing the wheel. STM32 is one of the most common MCUs used on 3Dprinter controller boards see this search https://www.aliexpress.com/wholesale?ca ... trol+board there is a few old school Ardunio controllers but most are STM32

This is a 45min video it details the problems with stepper acceleration and generating the step pulses and the solution https://www.youtube.com/watch?v=fHAO7SW-SZI It is using an Ardunio but the principle for STM32 is exactly the same :)

If people really want to be able to have proper stepper motor control in Micro-Python it will require writing the underlying step pulse generation using a HW interrupt in C the wrap it up for python to call.

Post Reply