Skip to content

Commit eae67a9

Browse files
authored
WiFi DA: Added Dual Antenna to the docs and example created (#6357)
Summary Added the Dual Antenna documentation. Added the DA example.
1 parent 52575d6 commit eae67a9

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

Diff for: docs/source/api/wifi.rst

+29
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,35 @@ Use static allocation if you want to have more performance and if your applicati
6767

6868
By default, the memory allocation will be set to **dynamic** if this function is not being used.
6969

70+
setDualAntennaConfig
71+
********************
72+
73+
Configures the Dual antenna functionallity. This function should be used only on the **ESP32-WROOM-DA** module or any other ESP32 with RF switch.
74+
75+
.. code-block:: arduino
76+
77+
bool setDualAntennaConfig(uint8_t gpio_ant1, uint8_t gpio_ant2, wifi_rx_ant_t rx_mode, wifi_tx_ant_t tx_mode);
78+
79+
80+
* ``gpio_ant1`` Configure the GPIO number for the antenna 1 connected to the RF switch (default ``GPIO2`` on ESP32-WROOM-DA)
81+
* ``gpio_ant2`` Configure the GPIO number for the antenna 2 connected to the RF switch (default ``GPIO25`` on ESP32-WROOM-DA)
82+
* ``rx_mode`` Set the RX antenna mode. See wifi_rx_ant_t for the options.
83+
* ``tx_mode`` Set the TX antenna mode. See wifi_tx_ant_t for the options.
84+
85+
Return ``true`` if the configuration was successful.
86+
87+
For the ``rx_mode`` you can use the following configuration:
88+
89+
* ``WIFI_RX_ANT0`` Selects the antenna 1 for all RX activity.
90+
* ``WIFI_RX_ANT1`` Selects the antenna 2 for all RX activity.
91+
* ``WIFI_RX_ANT_AUTO`` Selects the antenna for RX automatically.
92+
93+
For the ``tx_mode`` you can use the following configuration:
94+
95+
* ``WIFI_TX_ANT0`` Selects the antenna 1 for all TX activity.
96+
* ``WIFI_TX_ANT1`` Selects the antenna 2 for all TX activity.
97+
* ``WIFI_TX_ANT_AUTO`` Selects the antenna for TX automatically.
98+
7099
WiFiAP
71100
------
72101

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# WiFiScan Example
2+
3+
This example demonstrates how to use the WiFi library to scan available WiFi networks and print the results.
4+
5+
This example shows the basic functionality of the dual antenna capability.
6+
7+
# Supported Targets
8+
9+
This example is compatible with the ESP32-WROOM-DA.
10+
11+
## How to Use Example
12+
13+
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
14+
15+
#### Using Arduino IDE
16+
17+
* Before Compile/Verify, select the correct board: `Tools -> Board`.
18+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
19+
20+
#### Using Platform IO
21+
22+
* Select the COM port: `Devices` or set the `upload_port` option on the `platformio.ini` file.
23+
24+
## Example/Log Output
25+
26+
```
27+
ets Jul 29 2019 12:21:46
28+
29+
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
30+
configsip: 0, SPIWP:0xee
31+
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
32+
mode:DIO, clock div:1
33+
load:0x3fff0030,len:1412
34+
load:0x40078000,len:13400
35+
load:0x40080400,len:3672
36+
entry 0x400805f8
37+
Setup done
38+
scan start
39+
scan done
40+
17 networks found
41+
1: IoTNetwork (-62)*
42+
2: WiFiSSID (-62)*
43+
3: B3A7992 (-63)*
44+
4: WiFi (-63)
45+
5: IoTNetwork2 (-64)*
46+
...
47+
```
48+
49+
## Troubleshooting
50+
51+
***Important: Be sure you're using a good quality USB cable and you have enough power source for your project.***
52+
53+
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
54+
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
55+
56+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
57+
58+
## Contribute
59+
60+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
61+
62+
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
63+
64+
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
65+
66+
## Resources
67+
68+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
69+
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
70+
* ESP32-WROOM-DA Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-wroom-da_datasheet_en.pdf)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* This sketch demonstrates how to scan WiFi networks.
3+
* The API is almost the same as with the WiFi Shield library,
4+
* the most obvious difference being the different file you need to include:
5+
*/
6+
#include "WiFi.h"
7+
8+
/* These are the GPIOs connected to the antenna switch on the ESP32-WROOM-DA.
9+
* Both GPIOs are not exposed to the module pins and cannot be used except to
10+
* control the antnnas switch.
11+
*
12+
* For more details, see the datashhet at:
13+
* https://www.espressif.com/sites/default/files/documentation/esp32-wroom-da_datasheet_en.pdf
14+
*/
15+
16+
#define GPIO_ANT1 2 // GPIO for antenna 1
17+
#define GPIO_ANT2 25 // GPIO for antenna 2 (default)
18+
19+
void setup()
20+
{
21+
bool err = ESP_FAIL;
22+
Serial.begin(115200);
23+
24+
// Set WiFi to station mode and disconnect from an AP if it was previously connected
25+
WiFi.mode(WIFI_STA);
26+
27+
// Set WiFi dual antenna configuration by passing the GPIO and antenna mode for RX ant TX
28+
err = WiFi.setDualAntennaConfig(GPIO_ANT1, GPIO_ANT1, WIFI_RX_ANT_AUTO, WIFI_TX_ANT_AUTO);
29+
30+
/* For more details on how to use this feature, see our docs:
31+
* https://docs.espressif.com/projects/arduino-esp32/en/latest/api/wifi.html
32+
*/
33+
34+
if(err == ESP_FAIL) {
35+
Serial.println("Dual Antenna configuration failed!");
36+
} else {
37+
Serial.println("Dual Antenna configuration successfuly done!");
38+
}
39+
40+
WiFi.disconnect();
41+
delay(100);
42+
43+
Serial.println("Setup done");
44+
}
45+
46+
void loop()
47+
{
48+
Serial.println("scan start");
49+
50+
// WiFi.scanNetworks will return the number of networks found
51+
int n = WiFi.scanNetworks();
52+
Serial.println("scan done");
53+
if (n == 0) {
54+
Serial.println("no networks found");
55+
} else {
56+
Serial.print(n);
57+
Serial.println(" networks found");
58+
for (int i = 0; i < n; ++i) {
59+
// Print SSID and RSSI for each network found
60+
Serial.print(i + 1);
61+
Serial.print(": ");
62+
Serial.print(WiFi.SSID(i));
63+
Serial.print(" (");
64+
Serial.print(WiFi.RSSI(i));
65+
Serial.print(")");
66+
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
67+
delay(10);
68+
}
69+
}
70+
Serial.println("");
71+
72+
// Wait a bit before scanning again
73+
delay(5000);
74+
}

0 commit comments

Comments
 (0)