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.
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 [...]
Arduino Portenta H7 - Dual-Core STM32 Processor Board with Two CAN FD Ports and Support for Arduino IoT Cloud
The Portenta H7's central processor is represented by the dual-core STM32H747, including a Cortex M7 at 480 MHz and a Cortex M4 at 240 MHz. The two cores intercommunicate through a Remote Procedure Call mechanism that seamlessly enables calling functions on the other processor. Both processors share on-chip peripherals and can run Arduino Sketches on the Arm [...]
In the past, I frequently received inquiries regarding the availability of a four-channel CAN Bus gateway. Such devices exist in the marketplace; however, they are usually costly, and, after all, they don't support easy customization or programming. While we at Copperhill Technologies have the ability to create such a gateway, this is primarily a matter [...]
In the past months, customers have approached me regarding a CAN Bus baud rate converter for SAE J1939 networks. The original SAE J1939 Standards Collection was limited to a baud rate of 250k, basically to keep things simple and reliable. I don't know what triggered the decision to add the additional 500k baud rate. From [...]
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 [...]
The MAX33040Eshld shield evaluation kit by maxim integrated represents a demonstration and development platform for the MAX33040E CAN Bus transceiver. It serves as a standalone evaluation board and the Mbed or Arduino platform to communicate with a CAN Bus network. The board features test points to access critical signal pins of the transceiver. The MAX14931 digital isolator [...]
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 [...]
This book explains how to build sensor networks with Python and MicroPython using XBee radio modules, Raspberry Pi, and Arduino boards. This revised and updated edition will put all of these technologies together to form a sensor network and show you how to turn your Raspberry Pi into a MySQL database server to save sensor data. The reader [...]
Arduino Based CAN Bus, LIN Bus Development And Prototyping Boards For Automotive And Industrial Applications
Teensy is a line of Arduino-compatible boards designed to offer maximum I/O capabilities, backed up by a slew of fully featured software libraries designed to run on Arduino. The Teensy is a complete USB-based microcontroller development system in a minimal footprint, and it is capable of implementing many types of projects. All programming is done [...]