RTL8720DN

19K930

Intro: RTL8720DN

This instructables should how to use RTL8720DN with Arduino IDE.

STEP 1: What Is RTL8720DN?

Realtek RTL8720DN is a WiFi and Bluetooth module that has dual bands for WiFi communication. It is worth saying that this little module can support WiFi 5G and Bluetooth Low Energy 5.0 as well. This WiFi and Bluetooth module is a highly integrated WiFi and Bluetooth module with the main chip RTL8720DN, it can be regarded as an SoC for the WiFi and Bluetooth application with typical SBCs.

RTL8720DN just like ESP32 is WiFi and Blutooth module, but it have extra support for WiFi 5GHz. It is a very big advantages, since 2.4GHz only have 3 non-overlapping channels, 5GHz can provide more options. The performance and number of pins not as rich as ESP32, it is more like ESP8266.

Picture 1: DW16, this is a RTL8720DN module with RF shield

Picture 2: Rtlduino, this is a DW16 dev board but it need some tricks to program it.

Picture 3: Wio Terminal, this is a dev device Embedded DW16 for wireless connectivity.

Ref.:

https://www.seeedstudio.com/Realtek8720DN-2-4G-5G-...

https://en.wikipedia.org/wiki/List_of_WLAN_channel...

https://www.electronics-lab.com/rtlduino-rtl8720dn...

https://www.seeedstudio.com/Wio-Terminal-p-4509.ht...

STEP 2: Arduino Support

Realtek has released Arduino IDE support for RTL8722CSM/RTL8722DM. The software also can support their family member RTL8720DN, but require some patch:

  1. Download and install latest Arduino IDE if not yet:
    https://www.arduino.cc/en/software
  2. Follow "Getting Started with RTL8722" guide to install AmebaD:
    https://www.amebaiot.com/en/amebad-arduino-getting...
  3. Follow "Getting Started with Arduino and BW16 Module" guide to update the "variant.cpp" file:
    https://github.com/mikey60/BW16-RTL8720DN-Module-...

After applied miley60's file patch, the pin layout is a little bit different from the PCB print, so I have draw a pinout diagram showing the correct PIN numbers and usage.

STEP 3: BW16 Breadboard Connection


BW16 pins are 2 mm pitch, I have made a connector help to connect it to breadboard:

https://www.thingiverse.com/thing:4808016

STEP 4: BW16 Upload Program


Here are the BW16 to USB Serial Adapter connection summary:

BW16   -> USB Serial Adapter
LOG_RX -> TX
LOG_TX -> RX
3V3    -> 3V3
GND    -> GND

When upload program:

  1. Connect LOG_TX to GND
  2. Connect EN to GND and then reconnect EN to 3V3 to trigger reset
  3. disconnect LOG_TX from GND
  4. BW16 now entered the upload mode

After upload program, connect EN to GND and then reconnect EN to 3V3 to trigger reset. New program start run.

Notes:

For first upload only, you may found new program not uploaded after finished "upload program", please try follow command erase and flash manually:

macOS:

cd ~/Library/Arduino15/packages/realtek/tools/ameba_d_tools/1.0.5
tools/macos/image_tool/amebad_image_tool /dev/cu.usbserial-*

STEP 5: Rtlduino Program Tricks

Rtlduino is a RTL8720DN breakout dev board, but I guess it is designed for using AT Command firmware only. The USB to Serial chip is connected to the Serial Port, GPIO1(PB1) and GPIO0(PB2), that using for AT firmware communication only. If you want to program it with Arduino IDE, amebad_image_tool require communicating to LOG Serial Port, pins GPIO14(PA7) and GPIO15(PA8). The simplest way to fix this issue is connect 2 Serial Ports together, i.e. join PB1 to PA7 and join PB2 to PA8. Please be reminded that this method sacrificed 1 Serial Port or 2 GPIO pins, but no need to desoldering and reroute any connections.

The remained GPIO still enough to connect to a SPI display like ILI9341 LCD.

Here are the connection summary:

Rtlduino        -> ILI9341 LCD
3V3             -> VCC
GND             -> GND
GPIO1 -> GPIO14
GPIO0 -> GPIO15
GPIO18          -> CS
GPIO22          -> RST
GPIO17          -> DC
GPIO19          -> CLK
GPIO23          -> LED
GPIO21          -> MOSI

Ref.:

https://www.arduino.cn/thread-101986-1-1.html

https://www.thingiverse.com/thing:4552162

STEP 6: Test With Arduino_GFX


  1. Download latest Arduino_GFX libraries:
    (press "Clone or Download" -> "Download ZIP")
    https://github.com/moononournation/Arduino_GFX
  2. Import libraries in Arduino IDE
    (Arduino IDE "Sketch" Menu -> "Include Library" -> "Add .ZIP Library" -> select downloaded ZIP file)
  3. Select PDQGraphicsTest example
    (Arduino IDE "File" Menu -> "Examples" -> "GFX Library for Arduino" -> "PDQGraphicsTest")
  4. Select Board: RTL8722DM/RTL8722CSM
    (Arduino IDE "Tools" Menu -> "Board:" -> "Ameba ARM (32-bits) boards" -> "RTL8722DM/RTL8722CSM")
  5. Hold the Rtlduino "Burn" button, press the "RST" button and then release the "Burn" button
  6. Press "Upload" for compile and upload the program

STEP 7: WiFi Photo Frame

RTL8720DN MCU is fast enough and have enough memory for JPEG image decode and also the SPI is good enough for display image.

However, AmebaD not yet have internal flash filesystem support like ESP8266 or ESP32 does. And also RTL8720DN does not have all AmebaD SDIO API required pins.

Fortunately RTL8720DN is WiFi capable, you can direct download the JPEG image and stream to the JPEG decoder and display it:

  1. Select WiFiPhotoFrame example
    (Arduino IDE "File" Menu -> "Examples" -> "GFX Library for Arduino" -> "WiFiPhotoFrame")
  2. Fill your own SSID_NAME, SSID_PASSWORD, HTTP_HOST, HTTP_PORT and HTTP_PATH_TEMPLATE
  3. Compile and upload

Please see my previous instructables to know more about how to build a photo web server: https://www.instructables.com/Face-Aware-OSD-Phot...

STEP 8: Dual Band WiFi Analyzer

RTL8720DN is a dual band WiFi capable, 2.4GHz and 5GHz. So it is a better WiFi Analyzer than ESP8266 or ESP32 does.

  1. Select RTLWiFiAnalyzer example
    (Arduino IDE "File" Menu -> "Examples" -> "GFX Library for Arduino" -> "WiFiAnalyzer" -> "RTLWiFiAnalyzer")
  2. Compile and upload

Ref.:

https://www.instructables.com/Dual-Band-WiFi-Analy...

STEP 9: What's Next?

AmebaD still have many example for RTL8722DM/RTL8722CSM, most also works for RTL8720DN. But Sticky remember RTL8720DN is much lesser GPIO than RTL8722DM/RTL8722CSM, so many example requires override the default pins. E.g. blink example defined LED pin as GPIO8 but RTL8720DN does not have GPIO8.

mikey60 also rewrote some examples: https://github.com/mikey60/BW16-RTL8720DN-Module-...

19 Comments

Hi, do you know if i can use this chip to connect a bluetooth headest?
Great. I bought three of these RTL8720DN modules from Seed Studio. I was originally looking for a PCIe half mini wifi card thinking that this was that. Anyway I'm not too familiar with Arduino really. I'm trying to figure out what to do with these things. So basically I bought some kind of a tinker board with wifi and bluetooth 5.0 capability?
Espero pueda resolver mi duda. Hasta dónde he estudiado ESP32 no puede usar simultáneamente el Bluetooth y el Wifi, desearía saber si éste módulo si puede usar simultáneamente Bluetooth y Wifi al mismo tiempo, ya que por lo que observo del módulo, únicamente posee una sola antena. Muchas gracias de antemano.
Hi. thank you for your excellent introduction to RTL8720DN. Do you have any data on iperf testing, tcp or udp, for this chip? Since it has 5G band, most people would expect it to outperform esp32 substantially. I have googled but cannot find any posts or videos with real world test. Do you have any information to share?
Hey !!!
I have a problem at work my colleagues don't want to work and play games all the time. I need to disconnect from the game. The DSTIKE clock can do this, but not all of them - they can only do it at a frequency of 2.4, and I need a frequency of 5 gigahertz. Can you help me give the firmware - you have already worked with the BW16 RTL8720DN 5.0 module. Looking forward to help.
Even with the stock "B+T" firmware on the BW16 module a connection to a close (sitting next to it) OPEN wifi access point causes system to crash. Same behavior with SDK/make and Arduino environments. Putting unit in partial faraday cage or simply putting finger on antenna alleviates the problem. Appears problem is in the wifi driver library which I cannot get the source to. I hope Realtek fixes this problem. Id like to replace ESP designs with this. This was a great article and the rtl8720dn a great 5Ghz solution.
Ref: https://forum.amebaiot.com/t/rtl8720dn-sdk-crash-r...


Hi Chen! I am working on RTL8720DN module. The flashing process works fine for me but I have issue with serial as no data received.

Code:

#include

#if defined(BOARD_RTL8722DM)
SoftwareSerial mySerial(0, 1); // RX, TX
#elif defined(BOARD_RTL8722DM_MINI)
SoftwareSerial mySerial(2, 1); // RX, TX
#elif defined(BOARD_RTL8720DN_BW16)
SoftwareSerial mySerial(PB2, PB1); // RX, TX
#else
SoftwareSerial mySerial(0, 1); // RX, TX
#endif


void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Serial.println("Goodnight moon!");

// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}

void loop() { // run over and over
if (mySerial.available()) {
mySerial.write(mySerial.read());
}
}

Please help to resolve serial communication problem. I used the same hardware connection.
Hi! Can you share a little bit more about your configuration in the Arduino IDE I followed the guide that you gave but I have a problem :
When I plug in the FT232 (USB to serial adapter) with the BW16 connected to my computer, I can't select a port in the arduino IDE
Any USB serial adapter should be the same in Arduino IDE, no special configuration. Before you open the IDE, can you see the port with command `ls /dev/cu.*`
Hi Moon,
I purchased two rtlduino modules. I followed your instrucatable on this as best I could. One thing,I could not figure out how to 'overwrite' the original realtek/amibad files with the 'mikey' variant modded files. Regardless i was able to upload code sketches to the rtlduino with success but,,after repower and also trying the rst button,,the module never functions,,I want these to work as a repeater for a drone flying project so wifi only. If i open Arduino console i do see interface 0 & interface 1 initialzied,,,and UART something,and that is all? Am powering the rtlduino with usb mimi cable? Thank You, brcisna@gmail.com
Barry Cisna
I have added a notes at step 4, please try is it work for you.
Hello Chen... is there some library to support WPS on RTL8720DN? Do you know some example about how to use WPS?
Is it possible to upgrade the rtlduino dev kit (rtl8720dn) firmware directly from the PC through its microUSB port, not using an official development/IO board?
Yes, please read the details in step 4 and 5.
Finally I could put it working. What I had to do was to erase the flash before to upload my sketch to the board.

The solution was based on the link below:
https://wiki.seeedstudio.com/Wio-Terminal-Network-...

Maybe it´s not the best solution, but it is the one that worked for me. What I did was to change the function getAvailableBoard() in script ambd_flash_tool.py, and let it like below:
def getAvailableBoard():
for info in getAllPortInfo():
port, desc, hwid = info
ii = hwid.find("VID:PID")
print (str(info))
#hwid: USB VID:PID=2886:002D SER=4D68990C5337433838202020FF123244 LOCATION=7-3.1.3:1.
if ii != -1:
for b in BOARD_IDS:
print (str(b) + " " + str(b["info"]) + " " + str(ii) + str(hwid[ii + 8: ii + 8 + 4]) + " " + hwid[ii + 8 + 5 :ii + 8 + 5 + 4 ])
(vid, pid) = b["info"]
if vid == hwid[ii + 8: ii + 8 + 4] and pid == hwid[ii + 8 + 5 :ii + 8 + 5 + 4 ]:
print("passou")
if b["isbootloader"] == True :
return port, True
else:
return port, False
elif b["isbootloader"] == True :
print("Ok, eh bootloader")
return port, True

After that, I´ve opened the PowerShell and executed it as below:

C:\Users\mcava\ambd_flash_tool> python.exe .\ambd_flash_tool.py erase

But, before to execute the command below, put the board in the download mode, like below:
1) press and hold the burn button;
2) press and release the RST button;
3) release the burn button.

It will start to erase the board´s flash, it will take a while (~ 5 or 10 minutes), and afterwards all you have to do is to upload your sketch.

Thank you for answering soon. Yes, I did it. But the output I have after reseting the board is the one shown in picture attached.
void setup() {
Serial.begin(115200);
delay(1000);
// initialize digital pin LED_BUILTIN as an output.
pinMode(19, OUTPUT);
pinMode(20, OUTPUT);
pinMode(21, OUTPUT);
}

void loop() {
digitalWrite(19, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(20, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(21, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(19, LOW); // turn the LED off by making the voltage LOW
digitalWrite(20, LOW); // turn the LED off by making the voltage LOW
digitalWrite(21, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
Serial.println("teste111");
}

Does this script work for you?

Please find attached the picture of my board.

Notice that there´s a command that is intended to send the message "teste111" to the serial output, that is not shown in the log that I attached in the previous message.