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

SAE J1939 250k/500k Baudrate Converter with Arduino Due - Source Code Included

The introduction of 500 Kbps (see SAE J1939/14) as an alternative to 250 Kbps, required clarifications on how to solve problems that come with incorporating devices supporting different baud rate settings in the same network. One solution comes with automatic baud rate detection. The SAE J1939/16 document outlines the methods used to detect the baud rate [...]

Read More »


LIN Bus Simulation Device with USB Interface Controlled by Windows Software

The Baby-LIN-II by Lipowsky Industrie-Elektronik is a compact system for controlling a LIN BUS network via USB. The PC works as a LIN monitor, LIN Master, or LIN Slave. The system also supports operation in stand-alone mode and allows the execution of continuously running sequences without a PC. In addition, the galvanic isolation guarantees interference-free data transmission. The [...]

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 »


Telematics Gateway for Real-Time SAE J1939 or ISOBUS Data Monitoring

The CANUp telematics gateway by Technoton measures the operational parameters of vehicles and equipment and reports their performance. The core feature of the CANUp gateway includes the utilization of edge/fog computing methods, which detect 10,000+ possible parameters of vehicle or equipment operation and send generated operation reports to a web-based telematics server and directly to a user via [...]

Read More »


Standard IoT Gateway with ARM i.MX8M Plus Quad-Core Cortex-A53 Supports Two CAN FD Ports

Aaeon, a manufacturer of reliable and high-quality computing platforms, introduced their SRG-IMX8P IoT gateway solution with two CAN FD interfaces, bringing extended connectivity and utility across vertical markets. It is powered by Arm NXP i.MX8M Plus quad-core Cortex-A53 and Cortex-M7 processors with 8 GiB of onboard DDR4, the device reduces object detection time to 13 msec [...]

Read More »


NMEA 2000 Data Scanner with Bluetooth, BLE for Android, iOS, PC Applications

Our N2K-BT gateway functions as a NMEA 2000 to Bluetooth data scanner for any host device with a Bluetooth or BLE (Bluetooth Low Energy) port, such as PCs, phones, or tablets. Therefore, it supports operating systems such as Windows, Linux, iOS, Android, and more. In addition, the wireless communication protocol employs easy-to-read and easy-to-process ASCII [...]

Read More »


ESP32 Based CAN Bus, SAE J1939 and NMEA 2000 to Bluetooth Gateway

The following is a follow-up on our post  Controller Area Network (CAN), SAE J1939, NMEA 2000 Wireless Module for IoT and ELD Applications. The CAN Bus, SAE J1939 and NMEA 2000 to Bluetooth Gateway is the first product of a new series of wireless gateways for IoT (Internet of Things), ELD (Electronic Logging Devices), and other applications. At the [...]

Read More »


SAE J1939 Starter Kit and Network Simulator - New Hardware Variant Using the ESP32 Processor

Our SAE 1939 Starter Kit And Network Simulators allow the experienced engineer and the beginner to experiment with SAE J1939 data communication without connecting to a real-world J1939 network, i.e., a diesel engine. To establish a network, you need at least two nodes. That fact applies, especially to CAN/J1939 nodes. A single CAN Bus controller [...]

Read More »


Four Channel CAN Bus to USB Gateway Using The Arduino Due

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

Read More »