Blog
Recent Posts
SAE J1939 Protocol Stack Sketch for ESP32 Using the Arduino IDE
Posted by
onThe ESP32 is a series of low-cost, low-power system-on-chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs a Tensilica Xtensa LX6 microprocessor in both dual-core and single-core variations and includes built-in antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules.
Furthermore, the processor provides the means to easily and quickly create applications like CAN/J1939 gateways, CAN Bridges, J1939 ECUs, J1939 Data Logger, and many more. However, the Controller Area Network (CAN) port on the ESP32 provides only TTL levels, and you will need additional hardware (transceivers) to make them hardware-compliant with the CAN Bus standard ISO-11898.
For that reason, I am using our ESP32 WiFi, Bluetooth Classic, BLE, CAN Bus Module. This board comes not only with an onboard ESP32 WROOM-32 WiFi, Bluetooth Classic, BLE Module, but also a CAN Bus port with a transceiver.
CAN Bus Driver Software
Naturally, in order to implement an SAE J1939 protocol stack, you need to have a good CAN Bus driver software. I chose the ESP32 Protocol Demo on giothub.com. However, I made some minor modifications for better usability under SAE J1939, most prominently the implementation of CAN Bus error detection. The modifications are:
- Added CANError to:
- CAN.c
- CAN.h
- ESP32CAN.cpp
- ESP32CAN.h
- CAN.c:
- Renamed to CAN.cpp
- CAN.cpp -> Corrected declaration of CAN_read_frame_phy
- CAN.cpp -> CAN_isr -> Added cast to interrupt = MODULE_CAN->IR.U;
ARD1939 - SAE J1939 Protocol Stack for Arduino
The ARD1939 SAE J1939 protocol stack for Arduino was originally developed for the Arduino Uno and Arduino Mega 2560. In the meantime, I added versions for the Arduino Due and the ESP32.
All technical information about ARD1939, the SAE J1939 protocol stack for Arduino, plus detailed description of implementation and available function calls is included in my book SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino.
Arduino sketches (software projects) include a J1939 network scanner, and a simple SAE J1939 to USB Gateway application with associated Windows GUI (Visual Studio C# project). The collection of sketches is concluded by the ARD1939 project, a fully functional SAE J1939 protocol stack for the Arduino Uno and Mega 2560. And while the documentation refers to these processors, the protocol features apply to the ESP32 as well.
ARD1939 for ESP32
The ARD1939 code itself is directly compatible with the ESP32 when used with the Arduino IDE, however, the Arduino Due CAN Bus driver software required some modifications as discussed previously. Also, I needed to adjust the CAN Bus function calls to the same functionality as used for the Uno, Mega 2560, and Due version.
Please note: I had contemplated releasing ARD1939 in form of the original source code but ultimately decided against it, mostly out of respect for those small businesses that make a living from selling SAE J1939 devices and software tools. Instead, I provide a pre-compiled code.
Download the Software
Disclaimer: All Arduino sketches and other code samples and projects as introduced here are free software; you can redistribute and/or modify them. The programs are introduced in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. With downloading these programs, you confirm that these code samples and projects were created for demonstration and educational purpose only.
=> SAE J1939 Protocol Stack for ESP32 (.zip file)...
Last, but not least, sorry, but there is no technical support for this software. After all, it is free-of-charge.
Further Resources
- How to install ESP32 Board in Arduino IDE - Hackster.io...
- CAN Bus Development with ESP32-WROOM32 Development Board - Copperhill (copperhilltech.com)...
Electronics Projects with the ESP8266 and ESP32: Building Web Pages, Applications, and WiFi Enabled Devices
Copperhill Technologies highly recommends using this book for your ESP32 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...
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 [...]
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 [...]
ESP32 Project: USB to Bluetooth Gateway
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 [...]
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 [...]
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 [...]
Controller Area Network (CAN), SAE J1939, NMEA 2000 Wireless Module for IoT and ELD Applications
Due to the global shortage of electronic components, we at Copperhill Technologies began rethinking our strategy regarding new developments. Luckily, that change turned out to be a blessing in disguise because the transition from NXP LPC to the ESP32 processor opened the door to more industrial and automotive applications, especially those involving wireless transmissions for [...]
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, [...]
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 [...]
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 [...]