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

    PIN questions

    Scheduled Pinned Locked Moved GPy
    3 Posts 2 Posters 44 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.
    • K Offline
      kjm
      last edited by kjm

      A couple of PIN questions:

      1. In the docs they say alt is the alternate fn for p = Pin('P10', mode=Pin.OUT, pull=None, alt=-1) I don't understand what that means? Could someone give me an example of how you might use alt?
      2. I want to change multiple output pins simultaneously. There doesn't seem to be a way to group pins? Any suggestions?
      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @kjm
        last edited by

        @kjm
        About pt1: You have to look into the ESP32 technical reference manual, section "IO_MUX Pad List". There is a table with the suitable functions of each Pin.
        About pt 2: You use machine.mem32 to write directely to the GPIO output register. You can set the Pins to respective mode before. You will find the addresses of the output register in the ESP32 technical reference, chapter 4.12. Writing for instance a 1 to the respective position in register GPIO_OUT_W1TS_REG will set that bit to 1 without changing the other pins, wrting a 1 to GPIO_OUT_W1TS_REG will set that bit to 0. Writing a pattern to GPIO_OUT_REG will write that pattern to the set output pints. You can get the actual value. And you have to refer to the GPIO numbers, not the Pxx numbers.
        Below is a sample script, not very efficient, but it works. The interesting line is line 22.

        from machine import Pin, mem32
        
        def write_multi(data, pin_list, init=False):
            if init:
                for pin in pin_list:
                    Pin(pin[0], Pin.OUT)
            mask = 0
            value = 0
            if type(data) is int:
                for i in range(len(pin_list) - 1, -1, -1):
                    pin = pin_list[i][1]
                    mask |= 1 <<  pin
                    value |= ((data & 1) << pin)
                    data >>= 1
            else:
                for i in range(len(pin_list)):
                    print(pin_list[i])
                    pin = pin_list[i][1]
                    mask |= 1 << pin
                    value |= ((data[i] & 1) << pin)
            mask = 0xffffffff - mask
            mem32[0x3FF44004] = (mem32[0x3FF44004] & mask) | value
        
        def run():
            init = True
            for n in range(8):
                write_multi(n, (("P9", 12), ("P10", 13), ("P11", 22)), init)
                init = False
            for n in range(8):
                write_multi((n >> 2, n >> 1, n), (("P9", 12), ("P10", 13), ("P11", 22)), init)
        
        
        1 Reply Last reply Reply Quote 0
        • K Offline
          kjm
          last edited by

          tnx Rob I'll try my luck

          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