Page 1 of 1

rtc.irq : can't convert function to int

Posted: Mon Dec 19, 2016 7:19 am
by BigMan
By playing around, I try to understand more about time-interrupts.

This is my code:

Code: Select all

import machine

def alarm_handler(rtc_o):
   print("Hello from alarm_handler")

rtc = machine.RTC()
rtc.alarm(machine.RTC.ALARM0, 10000)
rtc_i = rtc.irq(trigger=machine.RTC.ALARM0, handler=alarm_handler, wake=machine.idle)

while True:
    machine.idle()
    print("Hello from while-loop")
==> which gives me the error message: TypeError: can't convert function to int

I am using Micropython for ESP8266 board.

Re: rtc.irq : can't convert function to int

Posted: Mon Dec 19, 2016 9:22 am
by pythoncoder
The immediate cause of your problem is that the line

Code: Select all

rtc_i = rtc.irq(trigger=machine.RTC.ALARM0, handler=alarm_handler, wake=machine.idle)
should read

Code: Select all

rtc_i = rtc.irq(trigger=machine.RTC.ALARM0, handler=alarm_handler, wake=machine.IDLE)
machine.idle is a function, machine.IDLE is a constant.

Alas I still can't make it work. There seem to be several issues with the firmware, at least with the build I have (27th Nov). Several constants are missing from the machine module (including IDLE). And there also seems to be a problem with the rtc.irq() method which objects to the handler arg. I will raise an issue on Github.

There is another point to note here. The docshttp://docs.micropython.org/en/latest/e ... chine.html indicate that machine.idle() may wake milliseconds later due to an interrupt being received. In my testing this seems to happen. machine.sleep() gives a "not yet implemented" error. So you may have to use deepsleep.