Site Information

 Loading... Please wait...

Blog

ESP32 Project: USB to Bluetooth Gateway

Posted by Wilfried Voss on

ESP Series of Modules

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.

Hardware

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.

Software

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 DevicesElectronics 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. 

IoT-Enabled Control, Data Logger, and Data Transmission Platform with CAN Bus Interface

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 [...]

Read More »


Arduino-Compatible Microsoft Azure Certified IoT Development Kit with Visual Studio Code Support

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 [...]

Read More »


Raspberry Pi Compute Module With CAN FD for Automation and IoT Applications

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, [...]

Read More »


A New Generation of SAE J1939 Gateway, ECU Simulator, and Starter Kit

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 [...]

Read More »


ESP32 Starter and Development Kits for Building Bluetooth and WiFi Enabled IoT Devices

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 [...]

Read More »


Embedded CAN Bus, SAE J1939, NMEA 2000 Development With ESP32

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 [...]

Read More »


Industrial Cellular 4G LTE Router For Advanced IoT Applications

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 [...]

Read More »


ESP32 Development Boards and Accessories for IoT Applications

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 [...]

Read More »


STM32 Ultra-Low-Power IoT Development Kit With Integrated CAN FD Interface

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 [...]

Read More »