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

    PWM signal to one pin instead of all

    Scheduled Pinned Locked Moved Discussion
    2 Posts 2 Posters 198 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.
    • D Offline
      Dezert754
      last edited by

      So Im trying to understand if all the pins are directly connected to a single PWM? In my case I'm using a WiPy, when I run my code all my pins seem to get that signal as I have multiple servos moving, however im specifying a single pin to get the PWM signal.

      Im only calling one function at a time.

      import machine
      import time
      
      def shelfServoOpenA():
          pwm = machine.PWM(0, frequency=50)
          pwm_ca = pwm.channel(0, pin='P23', duty_cycle=0.02)
          time.sleep(2)
          print("A Going to 60")
          pwm_ca.duty_cycle(0.2450)
      
      def shelfServoCloseA():
          pwm = machine.PWM(0, frequency=50)
          pwm_ca = pwm.channel(0, pin='P23', duty_cycle=0.02)
          time.sleep(2)
          print("A Going to 0")
          pwm_ca.duty_cycle(0.0450)
      
      def shelfServoOpenB():
          pwm = machine.PWM(0, frequency=50)
          pwm_cb = pwm.channel(0, pin='P22', duty_cycle=0.02)
          time.sleep(2)
          print("B Going to 60")
          pwm_cb.duty_cycle(0.2450)
      
      def shelfServoCloseB():
          pwm = machine.PWM(0, frequency=50)
          pwm_cb = pwm.channel(0, pin='P22', duty_cycle=0.02)
          time.sleep(2)
          print("B Going to 0")
          pwm_cb.duty_cycle(0.0450)
      
      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jcaron @Dezert754
        last edited by

        @Dezert754 you probably want to use different timers (the first argument to machine.PWM) and/or different channels (the first argument to pwm.channel). Probably the latter rather the former.

        You can also probably avoid instantiating / configuring each time you need to do something.

        1 Reply Last reply Reply Quote 1

        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