MicroPython on ESP32 with SPIRAM support

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Fri Jul 28, 2017 2:33 pm

:!: Update:
  • Added ymodem module
  • Send or receive files to/from host via same uart on which REPL runs
  • Text or binary files (like images, encoded data, ...) of any size can be sent or received reliably
  • Terminal emulator with support for ymodem protocol must be used (like minicom on Linux or TeraTerm, ExtraPuTTY on Windows)

Code: Select all

>>> import ymodem, uos
>>>
>>> ymodem.recv('image1.bmp')

Receiving file, please start YModem transfer on host ...
(Press "a" to abort)
CCCC
File received, size=230456, original name: "tiger.bmp"

>>> uos.listdir()
['spiffs.info', 'lib', 'boot.py', 'yyy.txt', 'tiger240.jpg', 'tiger.jpg', 'image1.bmp']
>>> uos.stat('image1.bmp')
(32768, 0, 0, 0, 0, 0, 230456, 138, 138, 138)
>>>
>>> ymodem.send('image1.bmp')

Sending file, please start YModem receive on host ...
(Press "a" to abort)
CCC

Transfer complete, 230456 bytes sent
>>>
See GitHub repository for more info.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Tue Aug 01, 2017 12:15 pm

:!: Update:
  • Some changes needed to build with latest esp-idf commits
  • Master esp-idf archive updated (for non-psRAM builds)
  • improvements in _thread module
    • _thread.start_new_thread() now returns thread id which can be used in some methods
    • added methods suspend(th_id), resume(th_id), stop(th_id)
    • inter-thread notifications:
      • _thread.notify(th_id) send notification to the specific thread
      • _thread.getnotification() check if a notification received from within the thread
    • threads are tested with (relatively) complex modules like uftpserver and works wery well
  • Updated uftpserver frozen module to quietly run in thread
  • other small changes and bug fixes
Thread example:

Code: Select all

>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import machine, _thread, time
===
=== bled    = machine.Pin(4, mode=machine.Pin.OUT)
=== gled    = machine.Pin(0, mode=machine.Pin.OUT)
=== rled    = machine.Pin(2, mode=machine.Pin.OUT)
===
=== bled.value(0)
=== gled.value(0)
=== rled.value(0)
===
===
=== def rgbleds(n, x):
===     ledon = 0
===     notif_exit = 4718
===     notif_print = 2
===     while x > 0:
===         if ledon == 0:
===             bled.value(1)
===             gled.value(0)
===             rled.value(0)
===         if ledon == 1:
===             gled.value(1)
===             bled.value(0)
===             rled.value(0)
===         if ledon == 2:
===             rled.value(1)
===             bled.value(0)
===             gled.value(0)
===         ledon = ledon + 1
===         if ledon > 2:
===             ledon = 0
===         time.sleep_ms(n)
===         x = x - 1
===
===         notif = _thread.getnotification()
===         if notif == notif_exit:
===             print("[rgbleds] Exiting")
===             return
===         elif notif == notif_print:
===             print("[rgbleds] I was notified")
===         elif notif != 0:
===             print("[rgbleds] Unknown notification %u" % (notif) )
===
===
=== lth=_thread.start_new_thread(rgbleds, (333,10000))
===
>>>
>>> _thread.notify(lth,7788)
True
>>> [rgbleds] Unknown notification 7788
_thread.notify(lth,2)
True
>>> [rgbleds] I was notified

>>> import uftpserver
>>> ftpth=_thread.start_new_thread(uftpserver.ftpserver, (3600,True))
Starting ftp server. Version 1.2
>>> FTPServer address:  192.168.0.21

>>> _thread.notify(ftpth,7788)
True
>>> [ftpserver] Notification 7788 unknown

>>> _thread.notify(ftpth,7591)
True
>>> [ftpserver] Received QUIT notification, exiting
See GitHub repository for more info.

User avatar
20after4
Posts: 1
Joined: Tue Aug 08, 2017 3:56 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby 20after4 » Tue Aug 08, 2017 5:14 pm

This is really awesome, thank you for making this possible.

:)

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Sun Aug 20, 2017 11:30 am

:!: New modules, improvements, added functionality, bug fixes and more...

During the next week, detailed documentation and examples for all added or changed modules will be pushed to the GitHub repository.

display module

support for SPI TFT displays based on ILI9341, ILI9488 & ST7789V controllers based on my TFT library
  • full set of graphics drawing methods, pixel, line, lineByAngle, triangle, circle, ellipse, rect, roundrect, arc, polygon
  • 9 embeded fonts, including vector 7-segment font and unlimited number of fonts from file
  • flexible text method, displaying text at any angle, transparent or opaque, ...
  • image support, jpg or bmp images with scalling
  • clipping window support
  • touch panel support
  • reading from display memory support
  • and more...
curl module
  • get method, http & https are supported
  • post method, http & https are supported, using multipart/form-data, unlimited number of fields/files can be sent
  • sendmail method, send mail with unlimited number of attachment files, ssl/tls supported, tested with gmail
  • ftp methods, get, put, list
  • more will be added later ...
ssh module
  • get method, download the file using scp protocol
  • put method, upload the file using scp protocol
  • list & llist methods, list files on server using sftp protocol
  • exec method, execute any command/application on server and get the rusult
Neopixel module
  • uses ESP32 RMT peripheral for precise timing
  • custom timings can be set, any RGB chip can be driven (defaults to WS2812)
  • any color order is supported
  • included methods: clear, set, setHSB, get, show, brightness, HSBtoRGB, RGBtoHSB, timings, color_order
hwI2C module
  • uses ESP32 I2C driver
_thread module
  • _thread module is greatly improved and more reliable
  • creating thread returns unique thread id used by various thread methods
  • inter-thread notification support, methods: notify, getnotification
  • inter-thread messaging, threads can exchange data, methods: sendmsg, getmsg
  • helper methods: getReplID, replAcceptMsg, getThreadName, getSelfName, allowsuspend
  • threads can be suspended, resumed and killed, methods: suspend, resume, kill
  • list method, list running/suspended threads to screen or return tuple with threads information
Multiple threads can run smoothly, for example I'm running 5 threads for more than 24h without any problem:

Code: Select all

>>> _thread.list()
ID=1073548004 Name: Neopixel State: running
ID=1073413296 Name: BME280 State: running
ID=1073412568 Name: FTPServer State: running
ID=1073411840 Name: B_Led State: running
ID=1073411360 Name: R_Led State: running
ID=1073454488 Name: MainThread State: running
>>> 
[Message from thread "BME280"] [12:02:24] T=26.92C  P=1004.63hPa  H=55.77%
[Message from thread "BME280"] [12:03:32] T=26.89C  P=1004.62hPa  H=55.11%
>>> _thread.notify(npth,1000)
True
>>> 
[Message from thread "Neopixel"] [Neopixel] Run counter = 888279
>>> 
>>> _thread.suspend(bth)
True
>>> _thread.list()
ID=1073548004 Name: Neopixel State: running
ID=1073413296 Name: BME280 State: running
ID=1073412568 Name: FTPServer State: running
ID=1073411840 Name: B_Led State: suspended
ID=1073411360 Name: R_Led State: running
ID=1073454488 Name: MainThread State: running
>>>
  • B_Led & R_Led blinking leds for 100 ms every second
  • BME280 reading BME280 sensor data using hwI2C and sending inter-thread message to main (repl) thread, accepts notifications for changing/disabling report interval and measure&report on request
  • Neopixel cycling rainbow colors thru 24 WS2812 RGB leds, accepting inter-thread notifications to change brightness and report counter status
  • FTPServer running python FTP server
Repl still runs smoothly, without noticeable effects on other threads even when performing such a task as downloading the file from ftp server.

Check GitHub repository for more info and sources.

patrick.pollet
Posts: 1
Joined: Sun Sep 03, 2017 12:26 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby patrick.pollet » Sun Sep 03, 2017 12:28 pm

@loboris :

Thanks a lot for such great work.

i just tried to clone the repository and did a first call to BUILD.sh :

Code: Select all

patrickpollet@patrickpollet-VirtualBox:~/esp32psram/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD$ ./BUILD.sh menuconfig
unpacking 'esp-idf'
unpacking 'esp-idf_psram'
unpacking 'xtensa-esp32-elf'
unpacking 'xtensa-esp32-elf_psram'

Building MicroPython for ESP32 with esp-idf master branch

DEFCONFIG
/home/patrickpollet/esp32psram/MicroPython_ESP32_psRAM_LoBo/esp-idf/tools/kconfig/conf: 1: /home/patrickpollet/esp32psram/MicroPython_ESP32_psRAM_LoBo/esp-idf/tools/kconfig/conf: Syntax error: ")" unexpected
'make menuconfig' FAILED!


But there was an error, i did a retry and got a different error :

Code: Select all

patrickpollet@patrickpollet-VirtualBox:~/esp32psram/MicroPython_ESP32_psRAM_LoBo/MicroPython_BUILD$ ./BUILD.sh menuconfig

Building MicroPython for ESP32 with esp-idf master branch

MENUCONFIG
/home/patrickpollet/esp32psram/MicroPython_ESP32_psRAM_LoBo/esp-idf/tools/kconfig/mconf: 1: /home/patrickpollet/esp32psram/MicroPython_ESP32_psRAM_LoBo/esp-idf/tools/kconfig/mconf: Syntax error: "(" unexpected
'make menuconfig' FAILED!

I do not know what to do, any help will be really appreciate.

Best regards.

Patrick

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Mon Sep 04, 2017 7:19 am

@patrick.pollet

It looks like it has something to do with running in virtual machine, but I couldn't reproduce it.
Thes same issue was discussed on GitHub.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Wed Sep 13, 2017 2:33 pm

:!: Update
Some modules added and updated, many bugfixes and improvements.

Basic documentation added, it will soon be updated to include more detailed documentation for all added/changed modules and features specific to this port.

New implementation of the FTP server is added, it runs in separate ESP32 task, like Telnet server, check the basic documentation for more info.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Thu Sep 14, 2017 1:29 pm

:!: Update
  • Some bugs in FTP mudule are fixed.
  • New organization of toolchain and esp-idf directories
  • BUILD.sh now checks for toolchain & esp-idf version
  • Building on MacOS is now fully supported, all needed toolchains are included.
    BUILD.sh detects the OS and unpacks the right toolchains for it.
    Tested on MacOS Sierra.

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Wed Sep 20, 2017 11:58 am

:!: Update:

As of Sep 18, 2017 full support for psRAM is included into esp-idf and xtensa toolchain.
Building with special versions of esp-idf and Xtensa toolchain is no longer needed.
  • Updated esp-idf and xtenssa toolchain to the latest version …
  • Building with psRAM support is now included in main branch
  • No psram parameter is needed for BUILD.sh, just configure psram support in menuconfig
  • Updated MicroPython core to the latest version
  • Buxfixes and improvements in display module, support for ST7735 based displays added
  • Some changes to UART module, tx&rx arguments are now mandatory when creating the UART instance
  • Neopixel module improved, unlimited number of pixels is now supported and less memory is used
  • Other minor bugfixes
  • Bilding on Windows is now fully supported, latest xtensa toolchain for Windows is included

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: MicroPython on ESP-WROVER with 4MB of psRAM

Postby loboris » Sat Sep 23, 2017 1:57 pm

:!: Update

One of the features of this port is that you can prepare the file system image on host and flash it to ESP32.
Until now, it was only possible for SPIFFS, as of the latest commit, it is also possible for FatFS (thanks to jkearins for his work on mkfatfs).

For more details visit the documentation page.

Who is online

Users browsing this forum: No registered users and 53 guests