Timer and UART confugration
I want to send radnom values via UART every second. I've got this code:
uart = UART(0, baudrate=115200)
str1 = str(value) + "\r\n"
value += 1
tim = Timer(0, mode=Timer.PERIODIC)
tim_a = tim.channel(Timer.A, freq=1000)
it = 0
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:
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:
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.
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:
livius last edited by
Ach - you have Wipy 1 - no that samle is for Wipy2 only
I do not know wipy1 - maybe someone else can help you
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?
livius last edited by livius
use Alarm to fire event in some interval