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

    External wifi antenna on the gpy

    Scheduled Pinned Locked Moved Projects
    gpyext wifi ant
    6 Posts 3 Posters 1.2k 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.
    • K Offline
      kjm
      last edited by kjm

      from machine import Pin
      from network import WLAN
      print(WLAN.EXT_ANT, WLAN.INT_ANT)
      Pin('P12', mode=Pin.OUT)(True)               # selects external antenna
      print(WLAN.EXT_ANT, WLAN.INT_ANT)
      Pin('P12', mode=Pin.OUT)(False)              # selects internal antenna
      print(WLAN.EXT_ANT, WLAN.INT_ANT)
      

      produces

      >>>
      1 0
      1 0
      1 0
      

      anybody know how to swap to the external wifi antenna on the gpy?

      S robert-hhR 2 Replies Last reply Reply Quote 0
      • S Offline
        Stevo52 @kjm
        last edited by Stevo52

        @kjm I'm still feeling my way around the GPY. I have tried a number of different options and still working on setting up the WLAN programmatically from stored/passed variables, but try these:
        For all of them use wlan.antenna() to read current state
        Precursor is to setup the wlan object:
        from network import WLAN
        wlan = WLAN()

        1. wlan.antenna(0) - uses the internal antenna

        2. wlan.antenna(WLAN.INT_ANT) - uses the internal antenna

        3. wlan.antenna(1) - uses the external antenna

        4. wlan.antenna(WLAN.EXT_ANT) - uses the external antenna

        I believe the Pin 12 command is used as an output to actually do the physical switching.

        These can be used on their own or with other options.

        Note: I haven't found much information on the use of integers for the WLAN options, but if you use wlan.XXXXX() it returns an integer for most of them so that seems to me to be a simple way to set the WLAN as you want it. Still investigating this as I want to pass WLAN setup data from a config file if I can, but it is not simple to do apparently :-)

        Other examples of using integers for WLAN settings are:
        MODE
        wlan.mode(1) sets it as WLAN.STA, wlan.mode(2) sets it as WLAN.AP and wlan.mode(3) sets it as WLAN.STA_AP

        'auth' SEC parameter:
        (1) sets to WLAN.WEP, (3) sets to WLAN.WPA2 etc.

        Note that SSID and Password info still needs to be in text of course.

        I'd be interested to find any additional information about setting WLAN up using this method if anyone can point me to it?

        Now registered on this forum as Steve Williams (due to an email address change) - stevo7452@gmail.com

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

          @kjm said in External wifi antenna on the gpy:

          WLAN.EXT_ANT, WLAN.INT_ANT

          These are constants which will not change if you switch the antenna. So the sequence should work:

          from machine import Pin
          from network import WLAN
          p=Pin('P12', mode=Pin.OUT)
          wlan=WLAN()
          wlan.antenna(WLAN.EXT_ANT)
          
          1 Reply Last reply Reply Quote 1
          • K Offline
            kjm
            last edited by

            Thnx for the replies fellas but I'm not convinced anything is actually happening. While it is true that wlan.antenna(WLAN.EXT_ANT) & Pin('P12', mode=Pin.OUT)(True) both send P12 to 3v there does not appear to be a cmd that confirms the switch to the ext antenna socket has occurred. print(WLAN.EXT_ANT, WLAN.INT_ANT) always returns 1 0 suggesting the external antenna is off and the internal is on. My RF sniffer probe confirms this with all the wifi RF action at the internal antenna & nothing at the socket.

            I've wasted over a week with this device and not much seems to work as advertised.

            1 Reply Last reply Reply Quote 0
            • K Offline
              kjm
              last edited by

              from machine import Pin
              from network import WLAN
              wlan=WLAN()
              p=Pin('P12', mode=Pin.OUT)  #this pin used for antenna switching
              wlan.antenna(WLAN.INT_ANT); print(wlan.antenna())
              wlan.antenna(WLAN.EXT_ANT); print(wlan.antenna())
              

              this seems to work because it returns

              0
              1
              

              Interestingly

              from machine import Pin
              from network import WLAN
              wlan=WLAN()
              p=Pin('P12', mode=Pin.OUT)(True); print(wlan.antenna()) 
              p=Pin('P12', mode=Pin.OUT)(False); print(wlan.antenna())
              

              does who knows what because it returns

              2
              2
              

              Which makes you wonder why it's still in the docs https://docs.pycom.io/firmwareapi/pycom/network/wlan.html

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

                @kjm wlan.antenna() return the value of in internal variable with the name antenna_type_selected, which is not change when you just set the value of the GPIO pin from your Python script.

                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