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

    How to use a Timer to blink a LED

    Scheduled Pinned Locked Moved WiPy 2&3
    wipy 2.0led on off
    3 Posts 2 Posters 2.1k Views 2 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.
    • C Offline
      ColombianAus
      last edited by

      Hi there,

      I've followed following example form "5. Hardware Timers" with no success

      from machine import Timer
      from machine import Pin
      led = Pin('GP16', mode=Pin.OUT) # enable GP16 as output to drive the LED
      tim = Timer(3) # create a timer object using timer 3
      tim.init(mode=Timer.PERIODIC) # initialize it in periodic mode
      tim_ch = tim.channel(Timer.A, freq=5) # configure channel A at a frequency of 5Hz
      tim_ch.irq(handler=lambda t:led.toggle(), trigger=Timer.TIMEOUT)

      If I type every line into the REPL, I got following error...

      from machine import Timer
      from machine import Pin
      led = Pin('G16', mode=Pin.OUT)
      tim = Timer(3)
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      TypeError: cannot create 'Timer' instances

      Now, if I follow the example under "Quick reference for the WiPy" (which is different to previous one!!!)...

      from machine import Timer
      from machine import Pin
      tim = Timer(0, mode=Timer.PERIODIC)
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      AttributeError: type object 'Timer' has no attribute 'PERIODIC'

      I would appreciate any help in regards to:

      1. Has anyone found a Timer Tutorial here?
      2. What is wrong with the snip codes that I 've pasted?

      Cheers
      ColombianAus

      1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino
        last edited by jmarcelino

        You're following the documentation for WiPy 1 but you have the new WiPy 2 which does Timers differently.

        All the new documentation is at https://docs.pycom.io

        The section you want is at https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/timers.html

        Use the Alarm example

        C 1 Reply Last reply Reply Quote 0
        • C Offline
          ColombianAus @jmarcelino
          last edited by

          @jmarcelino

          thank you mate...spot on. ...Do you know what is the most recent copy "Micropython Documentation"? for WiPy 2.0?

          cheers
          ColombianAus

          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