Hello,
I'm trying to start timer and set object method as collback, but i receive:
TypeError: 'NonType' object is not callable
I supported this:
https://docs.micropython.org/en/latest/ ... -callbacks
and this:
https://github.com/dhylands/upy-example ... eat_irq.py
My program:
from machine import Timer
import micropython
class Data(object):
def __init__(self):
timer = Timer(1)
timer.init(period=2000, mode=Timer.PERIODIC)
timer.callback(self.cb_timer)
def cb_timer(self, timer):
print("CB_TIMER")
micropython.alloc_emergency_exception_buf(100)
Data()
Object method as timer callback
Re: Object method as timer callback
Try:
The error message your code gets first is:
AttributeError: 'Timer' object has no attribute 'callback
Code: Select all
from machine import Timer
import micropython
class Data(object):
def __init__(self):
timer = Timer(1)
timer.init(period=2000, mode=Timer.PERIODIC, callback=self.cb_timer)
def cb_timer(self, timer):
print("CB_TIMER")
micropython.alloc_emergency_exception_buf(100)
Data()
AttributeError: 'Timer' object has no attribute 'callback