rtc.irq : can't convert function to int

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
BigMan
Posts: 22
Joined: Sat Oct 29, 2016 2:29 pm

rtc.irq : can't convert function to int

Post by BigMan » Mon Dec 19, 2016 7:19 am

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.

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

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

Post by pythoncoder » Mon Dec 19, 2016 9:22 am

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.
Peter Hinch

Post Reply