11. Networking & Communications¶
This week’s group assignment was to send a message between two projects.
We tried to interface ESP-WROOM-32(ESP32) and smartphone using Bluetooth.
Testing for Bluetooth Communication¶
Try Serial and Classical Bluetooth bridge (communication between PC and smartphone)
Device
ESP-WROOM-32(ESP32) | |
---|---|
Size | 25.5mm x 18mm |
CPU | Tensilica Xtensa Dual-Core LX6 @ 160 / 240Mhz |
RAM | 520 KB |
Flash memory | 64MB |
Wi-Fi | 802.11n up to 150 Mbps,802.11g up to 54 Mbps,802.11 b/g/n/d/e/i/k/r |
Bluetooth | Bluetooth v4.2 BR/EDR and BLE specification |
Number of pins | 38pin |
Power supply | 2.2~3.6V / 80 mA |
Usable temperature | -40℃~125℃ |
Workflow:
1. Download and Install USB to UART Bridge Virtual COM Port (VCP) drivers (for PC)
2. Download and Install Serial Bluetooth Terminal App (for Android)
3. Use “BluetoothSerial.h” library on Arduino IDE
4. Find and connect to the device on smarphone
5. Communicate!
1.Download and Install USB to UART Bridge Virtual COM Port (VCP) drivers (for PC)
¶
Prepare for PC
“The CP210x USB to UART Bridge Virtual COM Port (VCP) drivers are required for device operation as a Virtual COM Port to facilitate host communication with CP210x products. These devices can also interface to a host using the direct access driver.”
Download driver from here:
https://www.silabs.com/developer-tools/usb-to-uart-bridge-vcp-drivers?tab=downloads
2.Download and Install Serial Bluetooth Terminal App (for Android)
¶
Download Serial Bluetooth Terminal App (for Android) https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal
“A line-oriented terminal/console app for microcontrollers, Arduinos and other devices with a serial/UART interface connected to a Bluetooth serial converter to an Android device”
3.Use “BluetoothSerial.h” library on Arduino IDE
¶
Choose ESP32-WROOM-DA as boards.
Use the “Serial To Serial BT” sample code from “BluetoothSerial.h” library.
Change device name (this line)
String device_name = "FLK2025";
When you connect the device at the first time, you should reboot it. Press R+B button and connect USB.
![]() |
![]() |
![]() |
---|---|---|
4.Find and connect to the device on smartphone
¶
Pair the device with Bluetooth
![]() |
![]() |
---|---|
Open Serial Bluetooth Terminal App. Choose Bluetooth Classic. Refresh and find the device.
![]() |
![]() |
---|---|
5.Communicate!
¶
send the message from smartphone
Codes for ESP-WROOM-32(ESP32)¶
// This example code is in the Public Domain (or CC0 licensed, at your option.)
// By Evandro Copercini - 2018
//
// This example creates a bridge between Serial and Classical Bluetooth (SPP)
// and also demonstrate that SerialBT have the same functionalities of a normal Serial
// Note: Pairing is authenticated automatically by this device
#include "BluetoothSerial.h"
String device_name = "FLK2025";
// Check if Bluetooth is available
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
// Check Serial Port Profile
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin(device_name); //Bluetooth device name
//SerialBT.deleteAllBondedDevices(); // Uncomment this to delete paired devices; Must be called after begin
Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(20);
}
Result¶
It worked correctly!!