[SOLVED] micropython-nano-gui on esp8266

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
skylin008
Posts: 74
Joined: Wed Mar 11, 2015 6:21 am

[SOLVED] micropython-nano-gui on esp8266

Post by skylin008 » Thu Oct 01, 2020 7:11 am

Hello, everyone! If micropython-nano-gui from peterhinch. The web site is: https://github.com/peterhinch/micropython-nano-gui, If it suit porting to esp8266 chip. How much ram is needed? Thanks!

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

Re: micropython-nano-gui to esp8266

Post by pythoncoder » Thu Oct 01, 2020 7:28 am

I never tried this. I seriously doubt it could be made to work, owing to the limited RAM available on ESP8266. The GUI supports display drivers subclassed from Framebuf. This means that a frame buffer adequate to support the display must be created in RAM. There is then a significant amount of code. You would undoubtedly need to use frozen bytecode to store code and fonts.

If you try this and achieve success, please do report it.

Testing was on ESP32 and Pyboards.
Peter Hinch

skylin008
Posts: 74
Joined: Wed Mar 11, 2015 6:21 am

Re: micropython-nano-gui to esp8266

Post by skylin008 » Thu Oct 01, 2020 7:37 am

Thanks for your kindly answer. Yes, I want to put the code and font to firmware. I will be try.

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

Re: micropython-nano-gui to esp8266

Post by pythoncoder » Thu Oct 01, 2020 7:45 am

I would advise investing a small number of $$ in an ESP32 as a backup plan...
Peter Hinch

skylin008
Posts: 74
Joined: Wed Mar 11, 2015 6:21 am

Re: micropython-nano-gui to esp8266

Post by skylin008 » Mon Oct 05, 2020 4:03 am

Hello pythoncoder, I had added the nanogui.py to fronzen byte code build the firmware in esp8266 ,but anything error as show:

GEN build-GENERIC/frozen_content.c
CC build-GENERIC/frozen_content.c
build-GENERIC/frozen_content.c:15136:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__conj_0 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)1};
^
build-GENERIC/frozen_content.c:15136:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:15136:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__conj_0') [-Werror]
build-GENERIC/frozen_content.c:15136:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:15136:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__conj_0') [-Werror]
build-GENERIC/frozen_content.c:15136:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:15136:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__conj_0') [-Werror]
build-GENERIC/frozen_content.c:15136:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:15136:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__conj_0') [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__arrow_0 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)0};
^
build-GENERIC/frozen_content.c:15300:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__arrow_0') [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__arrow_0') [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__arrow_0') [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:15300:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__arrow_0') [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__Pointer___init___0 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)0};
^
build-GENERIC/frozen_content.c:17411:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Pointer___init___0') [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Pointer___init___0') [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Pointer___init___0') [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17411:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Pointer___init___0') [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__Dial_show_0 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)1};
^
build-GENERIC/frozen_content.c:17925:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_0') [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_0') [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_0') [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17925:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_0') [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__Dial_show_2 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)0};
^
build-GENERIC/frozen_content.c:17929:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_2') [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_2') [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_2') [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17929:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_2') [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__Dial_show_4 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)0};
^
build-GENERIC/frozen_content.c:17933:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_4') [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_4') [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_4') [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17933:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_4') [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__Dial_show_5 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)2};
^
build-GENERIC/frozen_content.c:17934:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_5') [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_5') [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_5') [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:17934:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__Dial_show_5') [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__0 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)3};
^
build-GENERIC/frozen_content.c:18185:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__0') [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__0') [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__0') [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:18185:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__0') [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: unknown type name 'mp_obj_complex_t'
STATIC const mp_obj_complex_t const_obj_nanogui__lt_module_gt__1 = {{&mp_type_complex}, (mp_float_t)0, (mp_float_t)3};
^
build-GENERIC/frozen_content.c:18186:1: error: braces around scalar initializer [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__1') [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: initialization makes integer from pointer without a cast [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__1') [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__1') [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: excess elements in scalar initializer [-Werror]
build-GENERIC/frozen_content.c:18186:1: error: (near initialization for 'const_obj_nanogui__lt_module_gt__1') [-Werror]
cc1: all warnings being treated as errors
../../py/mkrules.mk:63: recipe for target 'build-GENERIC/build-GENERIC/frozen_content.o' failed
make: *** [build-GENERIC/build-GENERIC/frozen_content.o] Error 1

How to solve this issue.Thanks!

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

Re: micropython-nano-gui to esp8266

Post by pythoncoder » Mon Oct 05, 2020 7:35 am

Please see my response on GitHub. It seems to be related to a lack of complex number support on ESP8266.
Peter Hinch

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

Re: micropython-nano-gui on esp8266

Post by pythoncoder » Tue Nov 17, 2020 6:02 pm

Partly in response to this thread I've refactored nano-gui so that only widgets in use are now imported. New ones can be added to the library with zero impact on existing applications (which I've done). A further gain is that, depending on the widgets in use, RAM usage can be smaller.

The cmath dependency is now removed from the main module. Now only the Dial widget, the plot module and associated demos require it.

Note you'll need to preserve the new directory structure when freezing code. Naturally you only need freeze modules and fonts which you intend to use.

You may now be in with a chance on ESP8266. Please report the outcome if you do try this.
Peter Hinch

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

Re: micropython-nano-gui to esp8266

Post by pythoncoder » Wed Nov 18, 2020 8:52 am

Curiosity got the better of me so I tried this, and it works.

I chose a 128*128 color OLED display to give it a bit of a challenge. I froze a subset of the drivers and the gui directories. In the following description, __init__.py was always left in place.

From drivers I removed everything except ssd1351/ssd1351_generic.py.
From gui I removed fonts except for arial10.
From demos I removed all but scale.py and tbox.py.
From core I removed all but colors.py writer.py and nanogui.py.

I erased flash, built and installed the new firmware. Finally I copied the following to /pyboard/color_setup.py

Code: Select all

# esp8266_setup.py Copy to target as color_setup.py
# WIRING (Adafruit pin nos and names).
# Pyb   SSD
# 3v3   Vin (10)
# Gnd   Gnd (11)
# IO0   DC (3 DC)
# IO16  CS (5 OC OLEDCS)
# IO2   Rst (4 R RESET)
# IO14  CLK (2 CL SCK)  Hardware SPI1
# IO13  DATA (1 SI MOSI)

from machine import SPI, Pin
import gc
from drivers.ssd1351.ssd1351_generic import SSD1351 as SSD

height = 128   # Ensure height is correct (96/128)

pdc = Pin(0, Pin.OUT, value=0)  # Arbitrary pins
pcs = Pin(16, Pin.OUT, value=1)
prst = Pin(2, Pin.OUT, value=1)
# Hardware SPI on native pins for performance
spi = SPI(1, baudrate=10_000_000, polarity=0, phase=0)

gc.collect()
ssd = SSD(spi, pcs, pdc, prst, height=height)
Both demos worked perfectly with an Adafruit display.

I am amazed that an ESP8266 can drive such a display, with uasyncio providing dynamic changes.

[EDIT]
See these improved instructions on how to do this.
Peter Hinch

skylin008
Posts: 74
Joined: Wed Mar 11, 2015 6:21 am

Re: [SOLVED] micropython-nano-gui on esp8266

Post by skylin008 » Fri Nov 20, 2020 12:08 pm

So cute.Thanks! I will test in esp8266 with ssd1306 oled.

Post Reply