The ESP32 processor allows the integration of Wi-Fi, Bluetooth, and Bluetooth LE (BLE) for a wide range of IoT (Internet of Things) applications. Using Wi-Fi ensures connectivity within a large radius. At the same time, Bluetooth allows the user to easily detect (with low-energy beacons) a module and connect it to an Android/iOS smartphone or tablet. The board adds priceless functionality and versatility to your applications.
In this post, we will explore the development of a Bluetooth to USB gateway. However, the word "development" seems ridiculous when you look at that amazingly concise Arduino sketch below. Nevertheless, it proves the great potential of using the ESP32 in combination with the Arduino IDE, i.e., simple code with incredible functionality.
For the test hardware I used the ESP32-WROOM-32 development board. The same program also runs on our ESP32-CAN Bus Development board. As a matter of fact, we are using a more sophisticated form of that sketch in our CAN to Bluetooth gateway.
Unless you have already done so, before working with the ESP32 using the Arduino IDE, you need to install a few components. For more information, see:
Before I started getting my feet wet using Bluetooth, I did my research by working through numerous online resources. All these posts described working solutions, but I was glad I chose a book, Electronics Projects with the ESP8266 and ESP32, as described below.
I like that all projects are more or less isolated, so that developers can focus on their specific needs. Developing my Bluetooth and BLE (Bluetooth Low Energy) applications went fast and without headaches. The Author explains the hardware aspects in detail without being overwhelming. Also helpful are the numerous references to testing tools.
Electronics Projects with the ESP8266 and ESP32: Building Web Pages, Applications, and WiFi Enabled Devices
Copperhill Technologies highly recommends using this book for your wireless application projects. Yes, many good books and free online resources are available these days, but this is the book we are using. It made our approach to Bluetooth, BLE, and WIFI a breeze. Programming wireless applications without hassles was fun, and we will share them on this web page.
Projects throughout the book utilize the wireless functionality and processing power of the ESP microcontrollers. Projects are built in the Arduino IDE, so you don't need to download other programming software. In addition, mobile apps are now ubiquitous, making the app build projects of the book very relevant, as are the web page design projects.
In Electronics Projects with the ESP8266 and ESP32, you'll see how easy and practical it is to access information over the internet, develop web pages, build mobile apps to remotely control devices with speech recognition, or incorporate Google Maps in a GPS route tracking app. More Information...
The original code for the Bluetooth to USB gateway application is available at:
I took, however, the liberty of optimizing the code and thus increasing the performance (i.e., transmission time between the two ports).
The image below shows the optimized sketch. It is so short that I didn't even bother putting it up for download.
In short, the program reads the serial data from one port and passes it to the other. Before I continue, let me add some references on how to connect to Bluetooth:
Connecting Bluetooth to a Windows PC
Connecting Bluetooth to an Android Device
Testing under Windows
First of all, after pairing the ESP32 with Windows, you need to determine the associated port number. The following screen shot shows my Windows 10 machine's Bluetooth section:
The paired ESP32 Bluetooth connection is marked in red. In order to determine the COM port number, click on "More Bluetooth options (marked in green.
Under the COM Ports section, you will find some entries similar to my setup. Have a look at the Outgoing port associated with the ESP32 Bluetooth device ID. In the above example, the COM port number is 22.
In the following, we 'll use the Arduino IDE Serial Monitor to display the information received by the ESP32 board. On the Windows PC side, I am using RealTerm, a free terminal software. In the RealTerm software, I set the port number to 22. Under the Send tab, I entered a sample ASCII string and clicked on "Send ASCII":
The Arduino Serial Monitor displays the data as received:
In the Serial Monitor, I entered another ASCII string and hit "Send":
This sequence successfully tests the connection, and now you can go ahead and add more code.
In the meantime, I will follow up with a similar application based on BLE.
The RapidM2M C3 by Microtronics represents a control, data logger, and data transmission platform with IoT capabilities, suitable for remote control, automation, and control tasks in industrial automation. The device includes a PLC (Programmable Logic Controller), router, firewall, and data transmission to a web platform. Process-related requirements are pre-configured, minimizing the solution integration effort. Data from analog sensors [...]
This Microsoft Azure Certified IoT DevKit (IOT-AZ3166) is an all-in-one kit optimized for prototyping and developing Internet of Things (IoT) applications leveraging Microsoft Azure services. It supplies an Arduino-compatible board with multiple peripherals such as an OLED display, sensors, hardware debugging chip (ST-Link), and security chip. The project collection offers creative examples for learning and reference, plus [...]
Kontron announced the release of their Pi-Tron CM4 computer with Linux OS, which utilizes the fourth-generation Raspberry Pi compute module with the 1,5-GHz, 64-bit Broadcom BCM2711 chip and four Arm Cortex-A72 processors. The computer’s steel housing allows for universal use, e.g., for automation and IoT (Internet of Things) applications. Depending on the variant, it provides a 1-GiB, 2-GB, [...]
Like many other businesses, we have to deal with the global shortage of electronic components. For instance, the NXP LPC 17xx processors we used for our SAE J1939 gateways and the starter kit are not available at this time. Even worse, there is no reliable information if/when production resumes. This situation forced us to rethink [...]
The integration of Wi-Fi, Bluetooth, and Bluetooth LE allow a wide range of applications with ESP32 modules. Using Wi-Fi ensures connectivity within a large radius, while using Bluetooth allows the user to easily detect (with low-energy beacons) a module and connect it to a smartphone. The chips add priceless functionality and versatility to your applications [...]
Like many businesses in the CAN Bus marketplace, we have struggled with the global shortage of electronic components. For instance, our SAE J1939 gateways are equipped with NXP processors, mainly the LPC1754 and LPC1768. Unfortunately, both processors are currently unavailable, and they come with remarkably long delivery times that go well into next year. We [...]
Phytools announced adding a new suite of products to their portfolio of industrial networking solutions. The Teltonika Networks product line incorporates dependable, secure, and easy-to-use cellular 4G LTE mobile routers, gateways, and switches for industrial, enterprise, IoT, and M2M applications. The RUT240 is one of the most popular industrial 4G LTE WiFi routers for professional M2M and [...]
The integration of Wi-Fi, Bluetooth, and Bluetooth LE allows a wide range of applications with the ESP32 modules. Using Wi-Fi ensures connectivity within a large radius, while using Bluetooth allows the user to easily detect (with low-energy beacons) a module and connect it to a smartphone. The chips add priceless functionality and versatility to your [...]
Rutronik introduced its development kit RUTDevKit-STM32L5 for AI-based (Artificial Intelligence) applications at the edge. The kit also comes with a CAN FD interface.The kit utilizes the 110-MHz STM32L562ZET6Q micro-controller. The 32-bit Arm Cortex-M33 processor with Arm Trustzone function offers hardware-based security features. The core implements a protected processing environment for cyber protection and sensitive code and an [...]