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

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 »


Bluetooth Low Energy (BLE) Wireless Modules Suitable For High-Speed IoT Devices And Applications

Fujitsu Components America released their FWM7BLZ20B series of Bluetooth 5.0 Low Energy wireless modules matching the speed demands of Internet-of-Things (IoT) devices and applications.The FWM7BLZ20B series is powered by Nordic Semiconductor's nRF52832 System-on-Chip (SoC). The symbol rate and data rate supports both 1Mbps and enhanced 2Mbps to expedite communication speed with other Bluetooth devices.The series comprises [...]

Read More »


Configuration-Free Wireless CAN Bus Bridge Connects Two CAN Bus Networks With Different CAN Bus Bitrates

Kvaser, a specialist in CAN Bus (Controller Area Network) development, introduced their Air Bridge Light HS, a wireless CAN Bus bridge to connect CAN networks. Comprising a preconfigured pair of plug-and-play units, with integrated antennas and rugged housings, the Kvaser Air Bridge Light HS provides a method of raw CAN Bus data exchange. Kvaser Air Bridge Light HS, [...]

Read More »


Ruggedized CAN Bus - IoT Gateway Connects Vehicles To The Cloud Via Wireless Or Cellular Interfaces

TTControl, a joint-venture company of TTTech Computertechnik and Hydac International, introduced an end-to-end solution connecting vehicles and mobile machines via a cloud platform for data processing and analysis. The product was designed to enable OEMs (Original Equipment Manufacturer) and fleet owners to optimize their fleet management and machine design. It also serves to assure the availability [...]

Read More »


Safe Wireless CAN Bus Bridge For Machine To Machine Communication Also Supports SAE J1939

The CAN-Sync wireless CAN Bus bridge from Humanistic Robotics (HRI) allows the user to transmit CAN data wirelessly over a transparent point-to-point bridge, without modifying the data. Higher-Layer Protocols such as SAE J1939 and CANopen are also supported.The product provides a wireless link between two CAN Bus interfaces with HRI’s Safetysense technology which is designed to guarantee that critical control [...]

Read More »


SAE J1939 Network Bridge With RS232/Wireless Connection

As part of another customer project, we have started work on an SAE J1939 network bridge device, which we call the jCOM.J1939.BRIDGE. The bridging serial hardware layer is RS232 in combination with a bit-stuffing protocol, similar to the protocol described at JCOM.J1939 PROTOCOL & PROGRAMMING INTERFACE (PDF).  Our customer will use the RS232 serial port for extension of [...]

Read More »


Wireless CAN Bus Bridge with USB Interface

ESD Electronics announced its CAN-CBX-AIR/3, a wireless CAN Bus bridge with USB interface. The bridge meets the requirements according to ETSI EN 300 328 V.2.0.20 (RED) standard. Like the previous CAN-CBX-AIR/2 version, the CAN-CBX-AIR/3 module works with a carrier frequency of 2,4 GHz in the ISM band. The transmission distance is up to 200 m (~ 600 ft) line-of-sight [...]

Read More »


Industrial Linux SBC With ARM Processor Supports WiFi, Bluetooth Plus Two CAN Bus Interfaces

Technologic Systems introduced their TS-7680, an embedded computer system powered by a 454 MHz ARM CPU that offers a great balance between industrial features, such as a 24-position rugged screw terminal connector and 3-Amp relays, and high-end capabilities, such as WiFi and Bluetooth. The TS-7680 offers low power and low cost at industrial grade, including industrial [...]

Read More »


LTE-Advanced Vehicle Router With Long-Range Gigabit Wi-Fi And Gigabit Ethernet Connects To SAE J1939 Or OBD-II Networks

The AirLink® MP70 by Sierra Wireless is a high performance, LTE-Advanced vehicle router developed specifically for mobile mission critical applications in public safety, transit and field services.The MP70 router a high-performance vehicle networking solution to connect multiple high-bandwidth applications in and around the vehicle, while also providing IT departments with the flexibility to manage mobile assets in [...]

Read More »