Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Timer and UART confugration

    Scheduled Pinned Locked Moved WiPy 2&3
    timeuart0wipywipy 1
    9 Posts 3 Posters 2.8k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M Offline
      michalt38
      last edited by michalt38

      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 += 1

      tim = 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)?

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @michalt38
        last edited by livius

        @michalt38
        use Alarm to fire event in some interval
        https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/timers.html

        think about people first, then computers

        M 1 Reply Last reply Reply Quote 0
        • M Offline
          michalt38 @livius
          last edited by

          @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?

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @michalt38
            last edited by

            @michalt38
            Ach - you have Wipy 1 - no that samle is for Wipy2 only
            I do not know wipy1 - maybe someone else can help you

            think about people first, then computers

            1 Reply Last reply Reply Quote 0
            • robert-hhR Offline
              robert-hh
              last edited by

              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

              M 1 Reply Last reply Reply Quote 0
              • M Offline
                michalt38 @robert-hh
                last edited by michalt38

                @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.

                1 Reply Last reply Reply Quote 0
                • robert-hhR Offline
                  robert-hh
                  last edited by

                  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.

                  1 Reply Last reply Reply Quote 1
                  • robert-hhR Offline
                    robert-hh
                    last edited by

                    I found a thread about it:
                    http://forum.micropython.org/viewtopic.php?f=11&t=2127&p=13811&hilit=Timer.A+Timer.B#p13811

                    M 1 Reply Last reply Reply Quote 1
                    • M Offline
                      michalt38 @robert-hh
                      last edited by

                      @robert-hh Thanks a lot! :)

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom