Site Information

 Loading... Please wait...

Blog

ESP32 Programming - Classical CAN to Bluetooth Gateway

Posted by Wilfried Voss on

In this post, I will present a CAN to Bluetooth gateway based on the ESP32 processor. The above image shows my test setup using our ESP32 WiFi, Bluetooth Classic, BLE, CAN Bus Module, a CAN-Bus Hub With 7 Ports And DC Power Connection, and the PCAN-USB Pro. As its description implies, the ESP32 module provides all necessary ports, i.e., a CAN Bus controller plus transceiver and a Bluetooth connection. Of course, the ESP32 also supports Bluetooth Low Energy (BLE) and WiFi, but in this post, I will focus on Bluetooth and address the others in a future post. 

I will not go too deep into the ESP32 capabilities, assuming that the reader is already familiar with the topic. Furthermore, there are multiple references and posts on this website. Just check out the information on our ESP32 product pages. However, I would like to mention that I am still excited about how easy it is to program wireless applications with the ESP32. My "bible" for Bluetooth and BLE is Electronics Projects with the ESP8266 and ESP32: Building Web Pages, Applications, and WiFi Enabled Devices as referenced on the bottom of this page. My Arduino Sketch for the Bluetooth gateway is based on the code in this book.

The Arduino Sketch

The code for the Bluetooth gateway is wrapped around the Bluetooth code as mentioned above plus a CAN driver by Thomas Barth, available on github.com. 

The code receives CAN data frames, converts them into an ASCII string and transmits the string per Bluetooth. There are also prints on the Serial Monitor. The format is as follows:

I chose ASCII code because it's easy to display the data on a terminal software, such as RealTerm. RealTerm also allows to send an ASCII string representing a CAN data frame to be transmitted as described in the next paragraph.

As usual, I will not go into detail of the code, but need to mention that it was designed for the ESP32 module as referenced above. Any modifications to work with other ESP32 boards should be easy to accomplish, though. The code represents a basic sample for a CAN to Bluetooth gateway. It may not be 100% fool-proof, and I did not include features such as baud rate setting (I use a default baud rate that can be changed within the code), filters, or more. However, the code gives the reader a great basis for further developments.

Click her to download the code (zip file).

Connecting the Bluetooth Device under Windows

Go to Settings->Bluetooth & devices -> Devices.

Click on "Add device."

Select Bluetooth.

You should see the ESP32-BT device. Click on it. As soon as the message "Your device is ready to go!" click "Done."

The device is still not connected. Now, we need to find out which port has been assigned to the Bluetooth device:

Scroll down the screen and look for "More Bluetooth Settings," and click on it.

The Bluetooth Settings appear:

Look for the "Outgoing" port, which in our example is COM8.

The easiest way to monitor the data traffic is to start a terminal software, such as RealTerm (as shown below):

Select Port 8 and click the "Change" command button. As displayed above, you can see the CAN data frames scrolling.

Transmitting CAN Data Frames per Bluetooth

Now it's time to send some data back to the network: Using the same terminal software, I designed two CAN data frames in the "Send" section as shown below.

The first data frame is in extended format, i.e., with 29-bit message identifier. The second frame is standard with an 11-bit message identifier. I sent the frames by clicking on the corresponding "Send ASCII" command button and verified the result with PCAN View:


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

PCI Express Board Integrates Four High-Speed CAN/CAN FD Ports

Kvaser has introduced their compact M.2 PCIe, a highly integrated embedded CAN Bus board that adds four high-speed CAN/CAN FD channels to any host computer with PCI Express connectivity and an available B or M keyed M.2 slot. The embedded board provides four distributed CAN CC (Classic CAN) or CAN FD transceivers, adding CAN CC and CAN [...]

Read More »


ESP32: CAN Bus Programming with MCP2515 and MCP2517FD

For good reasons, the ESP32 processor is a prevalent choice for embedded hardware development. Besides considerable memory resources, it provides various hardware features for many applications, most prominently the Internet of Things (IoT). All that comes with more than reasonable price tags, specifically when you use one of the multiple ESP32 development modules. And since [...]

Read More »


ESP32 Application: Galvanically Isolated CAN Bus Repeater and Baud Rate Converter

With this application, I am adding yet another example to the vast CAN library we developed over the years. The use of the Dual Isolated CAN Bus HAT with the ESP32 opens the door to a number of possible applications. The development of a CAN repeater and/or Baud Rate Converter came to mind first, because the [...]

Read More »


Kvaser's Leaf v3 Supports Classical CAN and CAN FD in Silent Mode

Every professional CAN Bus development, may it be Classical CAN, CAN FD, or higher layer protocols such as SAE J1939, require a data monitoring device for a proof of functionality. Kvaser has introduced such a device, the Leaf v3 interface supporting Classial CAN and CAN FD in optional Silent Mode. The Leaf series depicts one of the [...]

Read More »


Dual Isolated CAN Bus PCIe Expansion Card for Industrial, Automotive Applications

Cervoz Technology, a supplier of embedded components for the industrial PC market, has extended its industrial modular expansion cards line with the MEC-CAN-2802i, which provides two isolated CAN CC (Classical CAN) interfaces. The expansion card delivers a cost-effective solution for integrating CAN CC ports into embedded computer systems, especially in hostile environments. The board incorporates an M.2 [...]

Read More »


Under Development: Programmable CAN Bus to USB, Bluetooth, BLE, WiFi Gateway

For the longest time, I had resisted the idea of creating my version of a CAN-to-USB gateway, primarily due to the vast competition. A professional CAN/J1939 development requires a professional CAN-to-PC solution to monitor data traffic. I am pleased with the PEAK PCAN-USB device, as shown in the above image. However, not everybody is willing [...]

Read More »


Mini PCI-E Module Integrates Classical CAN (CAN bus 2.0 A/B, OBDII, SAE J1939), CAN FD, and GNSS features

Antzer Tech, a subsidiary of Innodisk, introduced their GADN-FD7L0 PC interface card, which integrates CAN (CAN bus 2.0 a/b, OBDII, SAE J1939), CAN FD, and GNSS features into one mini PCI-E combo module. The board comes in a standard Mini PCI Express form factor. It supports USB 2.0 and two independent CAN FD ports with data-phase bit [...]

Read More »


Programmable ECU and GPS Modules with Classical CAN, CAN FD, SAE J1939 Connections

PEAK-System presented several innovative I/O products with Classical CAN and CAN FD connections in this year's Embedded World trade show.  The versatile control unit PCAN-MicroMod FD ECU integrates customer-specific accessories for automotive applications. For this purpose, the device offers a CAN FD connection and a combination of analog and digital I/Os. The I/O processing and message [...]

Read More »


ESP32 Triple CAN Bus Application Through Adding Two MCP2515 Ports

The first question that may arise when talking about accessing the MCP2515 CAN Bus controller per ESP32 may be, "Why would you need an MCP2515 controller when the ESP32 comes with an internal CAN port?" Yes, I found this question in one of the online forums while researching this particular topic. The answer is easy: [...]

Read More »