I would like to combine a capability for which native code already exists (with Espressif toolchain)
For example this...
https://github.com/wdim0/esp8266_fast_lcd_driver_hspi
...would be amazing to have access to from Python. It's demonstrated in this video...
https://www.youtube.com/watch?v=X0mwfAqiqkc
1) What are the keywords describing the tools, steps and skills I would need to achieve this, so I can start learning how?
2) Are there worked examples where a new native capability has been added to the Micropython libraries?
3) Is there a way to do this from a pre-existing Arduino example?
I have built my own Micropython img from source, so I have access to the tools at least, but need orientation to begin gaining the knowhow.
Cefn
Combining Native Code with Micropython
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Combining Native Code with Micropython
I take it you want to write a C module to build into the firmware which provides a MicroPython interface. If so, a forum search will provide plenty of guidance. Dave Hylands (@dhylands) in particular has posted a number of guides.
There are also examples of Python display drivers but these are mainly targeted at the Pyboard. Whether the ESP8266 has sufficient RAM to support larger displays is moot, but the device has a built-in frame buffer so it may well be possible, especially with frozen bytecode.
There are also examples of Python display drivers but these are mainly targeted at the Pyboard. Whether the ESP8266 has sufficient RAM to support larger displays is moot, but the device has a built-in frame buffer so it may well be possible, especially with frozen bytecode.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Combining Native Code with Micropython
Thanks for your reply! I'll take a look for the posts you mention. Having that extra info of specific users to track who have provided 'tutorials' is handy as I'm a bit lost in all the detail of discussions between experts otherwise.
For the pixel display project I ended up putting together a simple driver for the st7920 monochrome display, which you can see here...
https://github.com/ShrimpingIt/micropython-st7920
...and some supporting bitfont rendering logic in a generic python-3-compatible bitfont library...
https://github.com/ShrimpingIt/bitfont
For the pixel display project I ended up putting together a simple driver for the st7920 monochrome display, which you can see here...
https://github.com/ShrimpingIt/micropython-st7920
...and some supporting bitfont rendering logic in a generic python-3-compatible bitfont library...
https://github.com/ShrimpingIt/bitfont
Re: Combining Native Code with Micropython
Here's a thread on writing modules in C:
viewtopic.php?f=2&t=1411
The latest code for that sample can be found here:
https://github.com/dhylands/micropython/tree/c-sample2
in this commit:
https://github.com/dhylands/micropython ... 57f5d7281b
@deshpu put together a "Hacking MicroPython" guide, which you can find here:
viewtopic.php?f=3&t=2370&p=13615&hilit=book#p13615
Edit: April 21, 2017 - I rebased the c_sample2 branch to the latest master, and I added a reference to that commit above.
For my own reference, the other conversation which I updated was this one:
viewtopic.php?f=2&t=1411
viewtopic.php?f=2&t=1411
The latest code for that sample can be found here:
https://github.com/dhylands/micropython/tree/c-sample2
in this commit:
https://github.com/dhylands/micropython ... 57f5d7281b
@deshpu put together a "Hacking MicroPython" guide, which you can find here:
viewtopic.php?f=3&t=2370&p=13615&hilit=book#p13615
Edit: April 21, 2017 - I rebased the c_sample2 branch to the latest master, and I added a reference to that commit above.
For my own reference, the other conversation which I updated was this one:
viewtopic.php?f=2&t=1411
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Combining Native Code with Micropython
@cefn Your font rendering logic appears to be dependent on PIL (pillow fork). Did you manage to run this on the ESP8266? If so, how did you do it? From a quick look it seems like a large library.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Combining Native Code with Micropython
The desktop python rendering test case relies on Pillow, but bitfont () simply takes a callback function, which can be provided by anything.
In the case of my current project using my st7920 library (https://github.com/ShrimpingIt/micropython-st7920) on ESP8266, a test case is as follows...
Recent commits provide an untested draw_generator function to render paragraphs which are constructed algorithmically (for example using https://github.com/pfalcon/utemplate ) without any string concatenation.
However, it's looking like I may have to abandon the NodeMCU for my project because of Memory issues - I'm just a few hundred bytes off running everything reliably including mfrc522 and st7920, but heading towards a hard deadline on Thursday. Any suggestions for a reference list of tricks to use to reclaim heap would be invaluable at this stage, (I've used all the tricks I can find so far) to the extent I might need to put a bounty on it, with my fallback being to switch to using the Pi Zero.
I'll post the heap issue in a separate thread.
Code: Select all
plot(x,y)
In the case of my current project using my st7920 library (https://github.com/ShrimpingIt/micropython-st7920) on ESP8266, a test case is as follows...
Code: Select all
from st7920 import Screen
from machine import Pin
screen = Screen(slaveSelectPin=Pin(15))
def plot(x, y):
screen.plot(x, y)
screen.clear()
font.draw_line("Hello World", plot)
screen.redraw()
However, it's looking like I may have to abandon the NodeMCU for my project because of Memory issues - I'm just a few hundred bytes off running everything reliably including mfrc522 and st7920, but heading towards a hard deadline on Thursday. Any suggestions for a reference list of tricks to use to reclaim heap would be invaluable at this stage, (I've used all the tricks I can find so far) to the extent I might need to put a bounty on it, with my fallback being to switch to using the Pi Zero.
I'll post the heap issue in a separate thread.