Simple Menu

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
vahithosan
Posts: 19
Joined: Wed Jul 26, 2017 5:15 pm

Simple Menu

Post by vahithosan » Thu Jul 08, 2021 8:14 pm

Hi.
I want to make simple menu with rotary pcd8544 esp32.

I tried some but didn't work

When I use interrupt and interrupt to assign another function, it resets esp32 with machine.disable_irq().

how can i make a simple menu with submenu

Code: Select all

from rotary_irq_esp import RotaryIRQ
import pcd8544_fb
import time
import utime as time
from machine import Pin, SPI

r = RotaryIRQ(pin_num_clk=35,
              pin_num_dt=34,
              min_val=0,
              max_val=4,
              reverse=False,
              range_mode=RotaryIRQ.RANGE_WRAP)

button = Pin(39, Pin.IN)

spi = SPI(1)
spi.init(baudrate=2000000, polarity=0, phase=0)
cs = Pin(15)
dc = Pin(4)
rst = Pin(27)
lcd = pcd8544_fb.PCD8544_FB(spi, cs, dc, rst)

while True:
    rot=r.value()
    if rot == 0:
        lcd.fill(0)
        lcd.text("> HIZ       ",0,0,1)
        lcd.text("  START AYAR",0,8,1)
        lcd.text("  STOP AYAR ",0,16,1)
        lcd.text("  AYARLAR   ",0,24,1)
        lcd.text("  KODLAMA   ",0,32,1)
        lcd.show()
        if button.value() == 0 and button_old == 1:
            lcd.fill(0)
            lcd.text("----HIZ-----",0,0,1)
            lcd.text("            ",0,8,1)
            lcd.text("            ",0,16,1)
            lcd.text("            ",0,24,1)
            lcd.text("            ",0,32,1)
            lcd.show()

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Simple Menu

Post by jimmo » Thu Jul 08, 2021 11:37 pm

vahithosan wrote:
Thu Jul 08, 2021 8:14 pm
When I use interrupt and interrupt to assign another function, it resets esp32 with machine.disable_irq().
Can you post an example of the code that causes this?

vahithosan
Posts: 19
Joined: Wed Jul 26, 2017 5:15 pm

Re: Simple Menu

Post by vahithosan » Fri Jul 09, 2021 5:41 pm

jimmo wrote:
Thu Jul 08, 2021 11:37 pm
vahithosan wrote:
Thu Jul 08, 2021 8:14 pm
When I use interrupt and interrupt to assign another function, it resets esp32 with machine.disable_irq().
Can you post an example of the code that causes this?

i use
MicroPython v1.16 on 2021-06-23; ESP32 module with ESP32
Type "help()" for more information.

Code: Select all

from rotary_irq_esp import RotaryIRQ
import pcd8544_fb
import time
import utime as time
from machine import Pin, SPI

r = RotaryIRQ(pin_num_clk=35,
              pin_num_dt=34,
              min_val=0,
              max_val=4,
              reverse=False,
              range_mode=RotaryIRQ.RANGE_WRAP)

button = Pin(39, Pin.IN)
spi = SPI(1)
spi.init(baudrate=2000000, polarity=0, phase=0)
cs = Pin(15)
dc = Pin(4)
rst = Pin(27)
lcd = pcd8544_fb.PCD8544_FB(spi, cs, dc, rst)


def hiz(p):
    print("deneme")
    time.sleep(5)
    
button.irq(trigger=Pin.IRQ_FALLING, handler=hiz)

when i enter this:

Code: Select all

machine.disable_irq()

Code: Select all

>>> machine.disable_irq()
395296
>>> Guru Meditation Error: Core  0 panic'ed (Interrupt wdt timeout on CPU0). 

Core  0 register dump:
PC      : 0x40094e63  PS      : 0x00060e34  A0      : 0x800d70cc  A1      : 0x3ffcd1b0  
A2      : 0x3ffc44b8  A3      : 0x00000000  A4      : 0x3ffc4504  A5      : 0x00000000  
A6      : 0x3ffc44b8  A7      : 0x00000000  A8      : 0x80094e63  A9      : 0x3ffcd190  
A10     : 0x3ffc44b8  A11     : 0x00000000  A12     : 0x000005b6  A13     : 0x3f43ff4b  
A14     : 0x00000001  A15     : 0x000001fe  SAR     : 0x00000020  EXCCAUSE: 0x00000005  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

Backtrace:0x40094e60:0x3ffcd1b0 0x400d70c9:0x3ffcd1f0 0x400d5616:0x3ffcd210 0x400f0ebd:0x3ffcd230 0x400f3d23:0x3ffcd250 0x400d5484:0x3ffcd290
Core  1 register dump:
PC      : 0x401cce8e  PS      : 0x00060034  A0      : 0x800d4c76  A1      : 0x3ffbc490  
A2      : 0x3ffc3bf1  A3      : 0x00060020  A4      : 0x00060020  A5      : 0x00060023  
A6      : 0x00000001  A7      : 0x00060723  A8      : 0x800d466d  A9      : 0x3ffbc480  
A10     : 0x00000003  A11     : 0x00060023  A12     : 0x00060020  A13     : 0x000000a5  
A14     : 0x000000a5  A15     : 0x00060023  SAR     : 0x0000001d  EXCCAUSE: 0x00000005  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace:0x401cce8b:0x3ffbc490 0x400d4c73:0x3ffbc4b0 0x400928b8:0x3ffbc4d0


ELF file SHA256: f1951b90976124e4

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:5640
load:0x40078000,len:12696
load:0x40080400,len:4292
entry 0x400806b0
i use esp32wroom

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Simple Menu

Post by jimmo » Sat Jul 10, 2021 12:27 pm

vahithosan wrote:
Fri Jul 09, 2021 5:41 pm
>>> machine.disable_irq()
I'm pretty sure you can't disable IRQs at the REPL, as the system requires IRQs to function, and you should only be disabling IRQs for very short periods of time (less than milliseconds). (My guess here is what's happening is the watchdog is activating).

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Simple Menu

Post by dhylands » Tue Jul 13, 2021 10:39 pm

Yeah - there is code here: https://github.com/micropython/micropyt ... #L576-L587 which reenables IRQs if you try to disable them from the REPL (at least if using USB). For the ESP32, it doesn't look like that code path would be taken, and the watchdog would trigger,

Post Reply