Timer and UART confugration
-
Hello,
I want to send radnom values via UART every second. I've got this code:uart = UART(0, baudrate=115200)
def irq_handler(value):
str1 = str(value) + "\r\n"
uart.write(str1)
value += 1tim = Timer(0, mode=Timer.PERIODIC)
tim_a = tim.channel(Timer.A, freq=1000)
tim_a.freq(5)it = 0
tim_a.irq(trigger=Timer.TIMEOUT, handler=irq_handler(it))
But it doesn't work beacouse it sends only first value - '0'. How to solve this problem and what is a difference between this freq: tim_a = tim.channel(Timer.A, freq=1000) and this freq: tim_a.freq(5)?
-
@robert-hh Thanks a lot! :)
-
I found a thread about it:
http://forum.micropython.org/viewtopic.php?f=11&t=2127&p=13811&hilit=Timer.A+Timer.B#p13811
-
There was a discussion about it and long periods. As far as I recall, the setting should be:
tim = Timer(0, mode=Timer.PERIODIC, width = 32) tim_a = tim.channel(Timer.A|Timer.B, freq=1) value = 0 tim_a.irq(trigger=Timer.TIMEOUT, handler=irq_handler())
But the discussion is somewhere buried in this board talk:
http://forum.micropython.org/viewforum.php?f=11
Which is anyhow the better place for WiPy 1 question.And you cannot return a value from an irq handler, unless you modify global symbols or class members. The other question is whether you can allocate memory in that handler, which you do by creating str1. Try to send a constant value first, to see, if it's periodic, and if that succeeds, take the next step.
-
@robert-hh
Ok but what is wrong with my code that it does not work? It's just like in the example you sent. It sends only first value and timer's irq handler does not execute after it.
-
The documentation for WiPy 1 is here: http://docs.micropython.org/en/latest/wipy/
and an example on how to use the timer with a callback is here:
http://docs.micropython.org/en/latest/wipy/wipy/quickref.html
-
@michalt38
Ach - you have Wipy 1 - no that samle is for Wipy2 only
I do not know wipy1 - maybe someone else can help you
-
@livius
In this line:self.__alarm = Timer.Alarm(self._seconds_handler, 1, periodic=True)
I've got an error: no such attribute. Does it work on WiPy 1?
-
@michalt38
use Alarm to fire event in some interval
https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/timers.html