This article was translated to English, and was originally published for deviceplus.jp.
In this article, we’ll use the Bluetooth (BLE) function to connect ESP-WROOM-32 with other devices.
Today’s Electronic Recipe
Estimated time to complete: 60 minutes
Parts needed
・ESP-WROOM-32 development board
Table of Contents
1. What is Bluetooth?
2. Difference between Bluetooth and BLE
3. Preparation for Use of BLE with ESP-WROOM-32
4. Operation of Sample Program
5. Conclusion
A variety of recent devices support Bluetooth communication, including earphones/headphones, speakers, car audio systems, mice, keyboards, etc. Though not the same as wireless communication such as Wi-Fi, Bluetooth communication is a relatively familiar communication method for those who use it frequently.
In the first place, what kind of communication is Bluetooth? You may have the impression that with Bluetooth you can connect nearby things but can’t communicate with distant things. Let’s quickly learn the mechanism and specifications of Bluetooth.
Bluetooth
Bluetooth is a wireless technology standard used for exchanging data between fixed and mobile devices over short distances using short-wavelength UHF radio waves in the industrial, scientific and medical radio bands, from 2.400 to 2.485 GHz, and building personal area networks (PANs). It was originally conceived as a wireless alternative to RS-232 data cables.
Bluetooth is managed by the Bluetooth Special Interest Group (SIG), which has more than 35,000 member companies in the areas of telecommunication, computing, networking, and consumer electronics. The IEEE standardized Bluetooth as IEEE 802.15.1, but no longer maintains the standard. The Bluetooth SIG oversees development of the specification, manages the qualification program, and protects the trademarks. A manufacturer must meet Bluetooth SIG standards to market it as a Bluetooth device. A network of patents apply to the technology, which are licensed to individual qualifying devices. As of 2009, Bluetooth integrated circuit chips ship approximately 920 million units annually.
[Adapted from Wikipedia] https://en.wikipedia.org/wiki/Bluetooth
As described in Wikipedia, Bluetooth is basically a short-range wireless communication standard intended to be used in digital devices.
Method of Recognition and Connection
Bluetooth requires the steps of “pairing” and “connection” when using it. For wireless LAN, it is common to connect to an access point by entering a password. For Bluetooth, however, a process is required in which one device detects and registers (authenticates) another device.
What is Pairing?
You need to set up pairing first, for example, if you want to use your smartphone and headphones with Bluetooth. It’s like a ceremony of face-to-face to allow relevant devices to connect to each other (that is, authentication registration). If the Bluetooth mechanism lacked this ceremony, similarly to wireless LAN, music played on B’s smartphone could be played on A’s headphones when B connects a smartphone with A’s headphones with password authentication while A uses the headphones. To prevent such problems, Bluetooth provides a mechanism that authenticates and registers devices, and allows only registered devices to be connected when using them.
So, for Bluetooth devices, basically only one connection can be established at the same time per Bluetooth module.
Have you ever seen the notation “BLE” with Bluetooth? BLE is a type of Bluetooth. Some communications are made with BLE depending on the type and use of the device. BLE, an acronym for Bluetooth Low Energy, is a communication method that assumes devices that can be used with reduced power consumption compared to normal Bluetooth.
The difference between Bluetooth and BLE is the communication speed and power consumption. Some applications send relatively large amounts of data, like Bluetooth headphones or other devices that need to send audio data. BLE isn’t suitable for them, since communication speed and power consumption are required to some extent, unlike ordinary text information. On the other hand, BLE is suitable for data such as the power ON / OFF state or other data that can be simply expressed with text or numbers. (* BLE sometimes doesn’t need pairing)
The ESP-WROOM-32 module supports BLE communication, so let’s use it now.
Now let’s use BLE with ESP-WROOM-32. We built the environment in Part 69, but BLE communication cannot be provided with Arduino based on that alone. Download and deploy the required files.
Required files – ESP-BLE-Arduino
https://github.com/nkolban/ESP32_BLE_Arduino/tree/98cd2290d036a4e27db061a76a512b526ef1cc14
Download the files (zip file) from “Clone or download” on the page and save them in the libraries/BLE directory of the Arduino installation as in the previous procedure.
Deploy the downloaded files under the libraries/BLE directory.
Restart Arduino IDE after installing these files, and sketch examples are created in ESP BLE Arduino. If you can see them, you’re ready.
Next, we’ll operate ESP-WROOM-32 as a Bluetooth device. Open the “BLE_client” program from “File”-“Examples”-“ESP32 BLE Arduino” and write the program on the board.
Once the program has been written, it is started as a BLE client (BLE work according to a server–client concept, which will be explained in a subsequent Part).
Enable Bluetooth on your smartphone or other device to detect surrounding devices, the ESP-WROOM-32 terminal should successfully be displayed.
Now, you’re ready to use ESP-WROOM-32 as a BLE device. You can use this to operate ESP-WROOM-32 from a smartphone or other device and send data from ESP-WROOM-32 to a smartphone with the BLE communication function.