Still the same error Sir, "MemoryError: memory allocation failed, heap is locked".
Here is the code:
import pyb,micropython, aswitch
from pyb import LED, Pin, ExtInt
import uasyncio as asyncio
import utime as time
from alcd import LCD, PINLIST
micropython.alloc_emergency_exception_buf(100)
delay = aswitch.Delay_ms()
lcd = LCD(PINLIST, cols = 16)
async def lcd_update():
await asyncio.sleep(1)
ext = pyb.ExtInt('PE7', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, callback)
while True:
lcd[0] = 'Vibration Detected' if delay.running() else ' '
await asyncio.sleep(1)
def callback(_):
delay.trigger(1000)
pyb.LED(4).toggle()
loop = asyncio.get_event_loop()
loop.create_task(lcd_update())
loop.run_forever()
So now i tried with a different method, i declared a global variable and whenever ISR is executed, global variable will be set. Depending on this global variable we will be printing on LCD. But for some reason it also didnt work. Below is my code:
#Write a program to interface vibra Sensor board.
import pyb
import pyb,micropython
from pyb import LED, Pin, ExtInt
import uasyncio as asyncio
import utime as time
from alcd import LCD, PINLIST
micropython.alloc_emergency_exception_buf(100)
data = False
lcd = LCD(PINLIST, cols = 16)
vibra_value = pyb.Pin('PE7',Pin.IN,Pin.PULL_DOWN)
def callback(_):
global data
pyb.LED(4).toggle()
pyb.LED(3).toggle()
pyb.LED(2).toggle()
pyb.LED(1).toggle()
data = True
ext = pyb.ExtInt('PE7', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, callback)
async def lcd_update():
global data
if data == True:
lcd[0] = "Vibration Detected"
await asyncio.sleep(1)
elif data == False:
lcd[0] = " "
await asyncio.sleep(1)
data = False
while True:
loop = asyncio.get_event_loop()
loop.run_until_complete(lcd_update())
So here my global variable is data =0, so as ISR is serviced, data should become 1. As soon as data becomes high, the LCD should print but its not working as data value is not geting updated or Any reason ? or can you improve the above code.
Thank You