External wifi antenna on the gpy



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



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



  • 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



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



  • @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)
    


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


Log in to reply
 

Pycom on Twitter