ESP32-CAN-X2: Difference between revisions

 
(39 intermediate revisions by 3 users not shown)
Line 9: Line 9:
Features of ESP32-CAN-X2 development board:
Features of ESP32-CAN-X2 development board:


* Based on ESP32-SE-WROOM-1-N8R8 microcontroller powerful dual-core Xtensa LX6 CPU running at up to 240 MHz.
* Based on ESP32-S3-WROOM-1-N8R8 microcontroller powerful dual-core Xtensa LX6 CPU running at up to 240 MHz.
* 384 KB ROM,  512 KB SRAM,  16 KB SRAM in RTC, 8 MB PSRAM
* 384 KB ROM,  512 KB SRAM,  16 KB SRAM in RTC, 8 MB PSRAM
* Two LED’s : LED PWM & LED communication
* Two LED’s : Power LED and user defined LED1
* Integrated Wi-Fi (802.11b/g/n) and Bluetooth capabilities
* Integrated Wi-Fi (802.11b/g/n) and Bluetooth capabilities
* Reset and Boot push button
* Reset and Boot push button
Line 18: Line 18:
* Additional CAN communication controller CAN using MCP2515
* Additional CAN communication controller CAN using MCP2515
* 6-pin header is strategically positioned at the top for CAN communication
* 6-pin header is strategically positioned at the top for CAN communication
* ESP32-CAN-X2 supports an additional external CAN transceiver
* Easy-to-interface programming. Required no external debugger for flashing
* Easy-to-interface programming. Required no external debugger for flashing
* Integrated CAN transceivers
* Integrated CAN transceivers
Line 58: Line 57:
* Interrupt Output Pin with selectable enables
* Interrupt Output Pin with selectable enables
* Multiple receive and transmit buffers  
* Multiple receive and transmit buffers  
* Low-Power CMOS Technology: - Operates from 2.7V-5.5V, 5 mA active current (typical), 1 μA standby current
* Low-Power CMOS Technology: - 5 mA active current (typical), 1 μA standby current
<br>
<br>
The internal CAN controller also works at CAN V2.0. The internal CAN supports two message formats:
The internal CAN controller also works at CAN V2.0. The internal CAN supports two message formats:
Line 68: Line 67:


* CAN 1: This is a built-in CAN controller and its RX is connected to IO6 of the microcontroller and TX is connected to IO7 of the microcontroller. The  connections are shown in Figure 3 given below
* CAN 1: This is a built-in CAN controller and its RX is connected to IO6 of the microcontroller and TX is connected to IO7 of the microcontroller. The  connections are shown in Figure 3 given below
* CAN 2: This is the externally connected controller and this controller CS, MOSI, CLK, and MISO are connected at pin numbers 1O10, 1011, 1012, and 1O13 respectively. The  connections are shown in Figure 3 given below
* CAN 2: This is the externally connected controller and its CS, MOSI, CLK, and MISO are connected at pin numbers 1O10, 1011, 1012, and 1O13 respectively. The  connections are shown in Figure 3 given below


[[File:Internal connection.png|Figure 3]]
[[File:Internal connection.png|Figure 3]]
Line 79: Line 78:


The ESP32-CAN-X2 development board has one USB-C port. This port is used for multiple functions: it powers the board, allows programming, and facilitates serial communication both ways.
The ESP32-CAN-X2 development board has one USB-C port. This port is used for multiple functions: it powers the board, allows programming, and facilitates serial communication both ways.
However, it is important to note that when powering the board through the USB-C port, please ensure the voltage does not exceed 5V @ 2A or 3.3V @ 1A.
However, it is important to note that when powering the board through the USB-C port, please ensure the nominal voltage range is 6-20V and Vmax is 40V.


== Board Layout ==
== Board Layout ==
Line 87: Line 86:
* Width  : 42.10 mm
* Width  : 42.10 mm
* Length : 72 mm
* Length : 72 mm
 
<br>
The board top view is shown in the Figure 4 given below.
The board top view is shown in the Figure 4 given below.


Line 104: Line 103:
'''VIN Rating'''
'''VIN Rating'''


The recommended input voltage rating for the development board is 3-12V. Please do not attempt to power the board with a voltage outside the recommended range, particularly not higher than 12V.
The nominal input voltage rating for the development board is 6-20v, with a 40v max input. Please do not attempt to power the board with a voltage outside the recommended range.


'''Operating Current'''
'''Operating Current'''
Line 124: Line 123:
'''Multimaster system'''
'''Multimaster system'''


In CAN Bus communication, multiple controllers can act as a master, and multiple devices can act as a node. Each node can share the data with other nodes via the CAN bus. In modern cars, there are more than 70 ECUs, and using CAN communication each ECU acts as a node and can transfer the data to the CAN bus, this data is then available to all the ECUs, and ECU can then check the data and decide whether to receive or ignore it.
In CAN Bus communication, multiple controllers can act as a master, and multiple devices can act as a node. Each node can share data with other nodes via the CAN bus. In modern cars, there are more than 70 ECUs, and using CAN communication each ECU acts as a node and can transfer the data to the CAN bus, this data is then available to all the ECUs, and ECU can then check the data and decide whether to receive or ignore it.


For details, visit: https://www.csselectronics.com/pages/can-bus-simple-intro-tutorial
For details, visit: https://www.csselectronics.com/pages/can-bus-simple-intro-tutorial
Line 145: Line 144:


'''CAN network types'''
'''CAN network types'''
 
<br>
Prominent CAN network types are as follows.
Prominent CAN network types are as follows.


Line 151: Line 150:
* Low-Speed CAN bus  ( Supports bit rates between 40 kbit/s and 125 kbit/s )
* Low-Speed CAN bus  ( Supports bit rates between 40 kbit/s and 125 kbit/s )
* CAN FD  ( Supports bit rates between 1 Mbps to 8 Mbps )
* CAN FD  ( Supports bit rates between 1 Mbps to 8 Mbps )
 
<br>
For details, visit:https://dewesoft.com/blog/what-is-can-bus
For details, visit:https://dewesoft.com/blog/what-is-can-bus


Line 161: Line 160:
* Error frame ( report errors )
* Error frame ( report errors )
* Overload frame ( report overload )
* Overload frame ( report overload )
<br>
For details, visit:https://www.autopi.io/blog/can-bus-explained/
== CAN Termination ==
CAN termination is a process of terminating the CAN bus to prevent the signal reflection at the end of the bus and to ensure the correct DC level of the bus. The CAN BUS is bidirectional, and both ends of the bus must be properly terminated to prevent errors in communication. CAN termination is achieved by placing the termination resistance, which is normally 120 ohm, that matches the nominal resistance of the cable. ISO 11898 requires normally required CAN BUS cable of impedance 120 ohm; therefore, the CAN 120 ohm resistance is used for CAN termination. However, while doing the CAN termination, it must be kept in mind that the nodes from the far two ends of the cable only require termination resistors.


For details, visit:https://www.autopi.io/blog/can-bus-explained/
Figure 5 given below explain the CAN termination.
 
[[File:CAN BUS TERMINATION.png]]
 
Note :The low-speed CAN, single wire CAN, may not require the CAN bus termination.
 
'''How to enable & disable CAN termination in ESP-32-X2 ?'''
 
The ESP-32-X2 development board has given two separate CAN termination pads at the top of the development board adjacent to the 6-PIN  CAN communication header. The CAN termination jumpers are shown in the figure 6 given below.
 
[[File:CAN BUS TERMINATION DISABLE JUMPERS.png]]
 
* Enable termination : In ESP-32-X2 development board, CAN termination is enabled by default.
* Disable termination : Scratch the copper trace between the pads, TERM1 & TERM2.  
* Re-enable termination : Re-solder the traces between the pads
 
Note : Proper termination is necessary for ensuring errorless communication and signal integrity. Please follow the above given instruction carefully.


=Board Pinout=
=Board Pinout=


The ESP32-CAN-X2 board has 40 pins across its two headers, SV1 & SV2 headers, and a 6-pin header at the top. This guide explains the pin functionalities of the board. The pin configuration of development board shown in Figure 5 given below.
The ESP32-CAN-X2 board has 40 pins across its two headers, SV1 & SV2 headers, and a 6-pin header at the top. This guide explains the pin functionalities of the board. The pin configuration of development board shown in Figure 7 given below.


[[File:Pin Configuration of ESP-32-X2 development board.png|Figure 5]]
[[File:Pin Configuration 1.png|Figure 7]]


'''Left Header (SV2) Pinout (Top to Bottom)'''
'''Left Header (SV1) Pinout (Top to Bottom)'''


The pin count start from the top of the left header, and the pin details are as following :
The pin count start from the top of the left header, and the pin details are as following :
Line 191: Line 212:
| 6 || TX Pin || USART TX
| 6 || TX Pin || USART TX
|-
|-
| 7-20|| GPIO Pins || GPIO's
| 7-20|| GPIO Pins || GPIO's (3.3v tolerant; to avoid damage do not apply any higher voltages to these pins)
|-
|-
|}
|}


'''Right Header (SV1) Pinout (Bottom to Top )'''
'''Right Header (SV2) Pinout (Bottom to Top )'''


The pin count start from bottom to top and details are as following :
The pin count start from bottom to top and details are as following :
Line 204: Line 225:
! Pin !! Function !! Description
! Pin !! Function !! Description
|-
|-
| 1-11 || GPIO Pins || GPIO's
| 1-11 || GPIO Pins || GPIO's (3.3v tolerant; to avoid damage do not apply any higher voltages to these pins)
|-
|-
| 12-13 || Vin || Voltage Input
| 12-13 || 3.3V || 3.3v Voltage Output (can be used to power your custom circuits)
|-
|-  
| 14-15 || 5V || 5 Voltage Output
| 14-15 || 5V || 5v Voltage Output (can be used to power your custom circuits)
|-
|-
| 16-18 || GND || Ground
| 16-18 || GND || Ground
|-
|-
| 19-20 || 12 Vin || 12 Voltage Input
| 19-20 || 12 Vin || 12v voltage Input
|}
|}
==12v note==
Only connect 12v to the 12v voltage input (19-20). To avoid electrical damage, do not connect 12v to any other pin on the board.


'''Top Header Pinout'''
'''Top Header Pinout'''


The header supports CAN communication. Pin count start at the left viewing the board from the top. Pinout configuration of header is shown in Figure 6 given below.
The header supports CAN communication. Pin count start at the left viewing the board from the top. Pinout configuration of header is shown in Figure 8 given below.


[[File:Top header.png|Figure 6]]
[[File:6 PIN HEADER (1).png|Figure 8]]
* '''Note:''' Color codes on the provided pigtail may not match documentation.


{| class="wikitable"
{| class="wikitable"
Line 234: Line 259:
| 4 || GND || Ground
| 4 || GND || Ground
|-
|-
| 5 || CAN2H/2.7A || high-level signal for the first CAN channel
| 5 || CAN1H/2.7A || high-level signal for the first CAN channel
|-
|-
| 6 || +12V_ Aux || 6-12v power supply
| 6 || +12V_ Aux || 6-12v power supply
Line 252: Line 277:


* Updated Arduino IDE to compile code for ESP-32-X2.
* Updated Arduino IDE to compile code for ESP-32-X2.
* Update Mu Editor from codewith.mu
<br>
<br>
Note : Link to download Arduino IDE : https://www.arduino.cc/en/software
Note : Link to download Arduino IDE : https://www.arduino.cc/en/software || Link to download Mu Editor : codewith.mu
 
== Step by step instruction for Arduino IDE==
 
===Sample Arduino Project===
https://github.com/autosportlabs/ESP32-CAN-X2


== Step by step instruction ==


Step-by-step instructions for flashing ESP-32-X2 are as follows.
Step-by-step instructions for flashing ESP-32-X2 are as follows.
Line 265: Line 295:
* Open Arduino Ide
* Open Arduino Ide
* Go to File > Preferences
* Go to File > Preferences
<br>


[[File:Flashing1.png| Figure 7]]
[[File:Flashing1.png| Figure 7|800px]]


* Add the below given Json URL in the Additional board manager URL
* Add the below given Json URL in the Additional board manager URL


Json URL : (                                    )
Json URL : https://espressif.github.io/arduino-esp32/package_esp32_index.json
 
<br>
[[File:Flashing2.png|Figure 8]]
[[File:ESPBSP1.png|Figure 8|800px]]


* Go to Tools > Board > Boards Manager
* Go to Tools > Board > Boards Manager
<br>


[[File:Flashing3.png|Figure 9]]
[[File:Flashing3.png|Figure 9|800px]]


* In the Board Manager search bar, type ESP-32-X2 and click on install to install the board
* In the Board Manager search bar, type ESP-32, search for esp32 by Espressif and click on install to install the board
<br>
[[File:ESPBSP2.png|Figure 10|800px]]


[[File:Flashing4.png|Figure 10]]


* After installing, click on Tool > Boards and select ESP-32-X2
* After installing, click on Tool > Boards and select AutosportLabs ESP32-CAN-X2
<br>
<br>
'''Flashing'''
'''Flashing'''
Line 288: Line 321:
* Connect the ESP-32-X2 board to your computer using a USB-C cable with your Arduino IDE open
* Connect the ESP-32-X2 board to your computer using a USB-C cable with your Arduino IDE open


* Select ESP-32-X2 in Tools > Board menu
* Select AutosportLabs ESP32-CAN-X2 in Tools > Board menu


* Go to Tools > Port and select the COM port to which ESP-32-X2 is connected.
* Go to Tools > Port and select the COM port to which ESP-32-X2 is connected.


[[File:ArduinoFlashing3.png|Figure 11|800px]]
<br>
<br>
Note : If you don’t see the COM Port in your Arduino IDE, you need to install the CP210x USB to UART Bridge VCP Drivers: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
Note : If you don’t see the COM Port in your Arduino IDE, you need to install the CP210x USB to UART Bridge VCP Drivers: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
Line 302: Line 336:
* After successful uploading, you should see a “Done uploading.” message at the bottom console. This console will also show error messages if there is any error.
* After successful uploading, you should see a “Done uploading.” message at the bottom console. This console will also show error messages if there is any error.


[[File:Flashing5.png|Figure 11]]
[[File:ArduinoFlashing4...png|Figure 12|800px]]


If any issues occur during upload, double-check the board selection, COM port, and your code for errors.
If any issues occur during upload, double-check the board selection, COM port, and your code for errors.
<be>
===Importing Libraries in Arduino IDE===
* To Install Libraries for ESP32-CAN-X2 like mcp_canbus or mcp2515
* Go to Sketch > Include Library > Manage LibrarieSs
[[File:Arduino IDE Library 1.png]]
* Type and find the desired library like mcp_canbus by Longan Labs
* Search and Install the library
[[File:Arduino IDE Library 2...png]]
== Step-by-step instruction for CircuitPython==
===Sample CircuitPython code===
https://github.com/autosportlabs/ESP32-CAN-X2
'''Downloading ESP-32-X2 Board Support:'''<br>
Installing ESP-32-X2 is simple, please follow the steps given below :
* Go to circuitpython.org/board/autosportlabs_esp32_can_x2
Click on the browse S3<br>
[[File:CircuitpythonFlashing1.png|800px]]<br>
* Select the desired language<br>
<br>
[[File:CircuitpythonFlashing2.png|800px]]
* Download the latest .bin file
<br>
[[File:CircuitpythonFlashing4.png|800px]]
'''Prepare the ESP32 CAN X2 for Installation:'''<br>
* Connect the ESP-32-X2 board to your computer using a USB-C cable
* Press and hold the boot button on the development board.
* While holding the boot button, press and release the reset button once.
* Release the boot button to put the board into bootloader mode.
[[File:CircuitpythonFlashing5.png|800px]]
'''Connect to the Web Serial ESP Tool'''
* Go to : https://adafruit.github.io/Adafruit_WebSerial_ESPTool/
* Press the Connect button in the top right corner of the page.
* A pop-up will appear asking you to select the COM or Serial port.
* Look for an option with ESP32, JTAG Loader, SLAB, or FTDI in the name
<br>
[[File:CircuitpythonFlashing6.png|800px]]
'''Flash the Firmware'''
* Click on Choose the .bin file you downloaded.
* Ensure that the Offset box next to the file location is set to 0x0.
* After selecting the file, the button text will change to match your filename.
* Click the Program button to start flashing. A progress bar will appear, and after a minute or two, the firmware will be
written.
[[File:Circuytpython7.gif|800px]]
'''Exit Bootloader Mode'''
* Press the reset button to exit bootloader mode. Shortly, the CIRCUITPY drive will pop up.
'''Downloading and Installing Mu Editor'''
* Download and install the recommended Mu Editor from codewith.mu.
* When you first start Mu, you will be prompted to select your mode. Select CircuitPython.
<br>
<br>
[[File:Mudownload.png|800px]]


'''Endless Opportunities'''
* In Mu editor, click the Load button in the button bar, navigate to the CIRCUITPY drive, and choose code.py.
<br>
[[File:MU2.png|800px]]


Now you are ready to explore the endless opportunities.
'''Note :''' The CIRCUITPY drive is where your code and necessary libraries will reside. With a fresh CircuitPython install, the CIRCUITPY drive will contain a code.py file with print("Hello World!") and an empty lib folder. If your CIRCUITPY drive does not have a code.py file, create one and save it to the drive. CircuitPython automatically executes the code in code.py when the board starts up or resets. Do not press reset immediately after saving your code it will corrupt the drive and you may lose your code.  


=Sample Arduino Project=
* Enter your code into the editor and save the code.py file on the CIRCUITPY drive.
https://github.com/autosportlabs/ESP32-CAN-X2
<br>
 
[[File:MU3.png|800px]]
 
'''Congratulations!''' You have just run your first CircuitPython program.
 
=== Importing Libraries in Circuitpython ===
 
Importing libraries in Circuitpython is straightforward. For installing Libraries in Circuitpython, please follow the steps given below :
* Go to https://circuitpython.org/libraries and download the bundle for version 9.xx.
'''Note:''' The version of the bundle should be the same that you are using.
<br>
 
[[File:Mu4.png|800px]]
 
* Extract the zip file.
* Find the lib file where you can find your desired library.
* Copy that library folder or .mpy file and paste it to the lib folder in CIRCUITPY drive
<br>
 
[[File:Mueditor Library.gif|800px]]
 
=Bolt-ons=
Autosport Labs provides various add-on boards, known as "bolt-ons" for ESP32-CAN-X2. For Further details regarding bolt-on. Please click on the specific bolt-on links given below
* [https://wiki.autosportlabs.com/Bolt-on#GPS_Bolt-on GPS Bolt-on]
* [https://wiki.autosportlabs.com/Button-bolt-on Button Bolt-on]

Latest revision as of 19:14, 10 November 2024

Introduction

ESP32-CAN-X2 is an ESP32-based development board specifically designed for CAN communication. This board has all the features of a modern ESP32 development board, integrated Wi-Fi and Bluetooth, along with the extended CAN controller. Autosport Labs has specifically designed it for CAN communication along with fast processing and computation options.

This is a complete how-to-use guide and this user guide will describe each and every step to use the board and harness the maximum potential of the board.

Features

Features of ESP32-CAN-X2 development board:

  • Based on ESP32-S3-WROOM-1-N8R8 microcontroller powerful dual-core Xtensa LX6 CPU running at up to 240 MHz.
  • 384 KB ROM, 512 KB SRAM, 16 KB SRAM in RTC, 8 MB PSRAM
  • Two LED’s : Power LED and user defined LED1
  • Integrated Wi-Fi (802.11b/g/n) and Bluetooth capabilities
  • Reset and Boot push button
  • USB-C type socket for flashing, and power supply
  • Integrated antenna for long range communication
  • Additional CAN communication controller CAN using MCP2515
  • 6-pin header is strategically positioned at the top for CAN communication
  • Easy-to-interface programming. Required no external debugger for flashing
  • Integrated CAN transceivers
  • Configurable CAN termination resistors, which can be disabled via breakable jumpers
  • Flexible power supply options
  • Support of a wide choice of commonly used Integrated Development Environments (IDEs)
  • Comprehensive free software libraries and examples for CAN communication

Getting started

This section will provide you with comprehensive information about the ESP32-CAN-X2 development board's key components, mechanical layout, power rating, & requirements. This detailed information helps you to use the board effectively and efficiently in your projects.

Key Components of ESP32-CAN-X2 Development Board

Figure 1 given below indicates the important key components of the ESP32-CAN-X2 Development Board and their location on the board.

Figure 1

Microcontroller

The ESP32-CAN-X2 Development Board is designed around the ESP32-S3-WROOM-1-N8R8 microcontroller in a 40-pin package. The connections between the development board and the microcontroller is straightforward, where the majority of GPIO pins are directly connected with the external headers, SV1 & SV2, and some pins are reserved internal connections between the board and CAN controllers. The internal connections between the microcontroller and CAN controllers are shown in the CAN controller heading given below. The microcontroller pin layout is shown in Figure 2 given below.

Figure 2

External Connection Header

External headers, SV1 & SV2, are the two other important components of this development board. SV1 is the left side dual row header and the SV2 is the right side dual row header. Both of these headers have 20 pins available for connection. These headers provide connections for GPIOs, power output, ground (GND), power input, and CAN communication pins. Both of these header pinouts have standard size, allowing users to connect them using jumper wires, a breadboard, or even solder wires permanently onto the development board. However, while doing the wire connection the customer must make sure that none of them get short circuit. The details regarding the pin's names, numbers, outputs, and functions are given in the Board Pinout section below.

CAN Controllers

The MCP2515 external connected CAN communication controller, and ESP-32 built-in CAN communication controller are two other main components of this development board.

The MCP2515, operating as the second external CAN controller in this development board, is a specialized component designed for Controller Area Network (CAN) applications. Its features include:

  • Implements CAN V2.0B at up to 1 Mb/s.
  • High-Speed SPI Interface (10 MHz)
  • Interrupt Output Pin with selectable enables
  • Multiple receive and transmit buffers
  • Low-Power CMOS Technology: - 5 mA active current (typical), 1 μA standby current


The internal CAN controller also works at CAN V2.0. The internal CAN supports two message formats:

  • Base frame format (11-bit ID)
  • Extended frame format (29-bit ID)


Internal pinout connection between the CAN controllers and ESP32

  • CAN 1: This is a built-in CAN controller and its RX is connected to IO6 of the microcontroller and TX is connected to IO7 of the microcontroller. The connections are shown in Figure 3 given below
  • CAN 2: This is the externally connected controller and its CS, MOSI, CLK, and MISO are connected at pin numbers 1O10, 1011, 1012, and 1O13 respectively. The connections are shown in Figure 3 given below

Figure 3

6 pin JST-PH Connector

The ESP32-CAN-X2 development board provides an additional 6-pin connector header at the top of the board to supports CAN communication. This header makes wiring the device more convenient and robust. The CAN communication connection pinout details are given in the pinout section below.

USB-C Socket

The ESP32-CAN-X2 development board has one USB-C port. This port is used for multiple functions: it powers the board, allows programming, and facilitates serial communication both ways. However, it is important to note that when powering the board through the USB-C port, please ensure the nominal voltage range is 6-20V and Vmax is 40V.

Board Layout

Mechanical board outline physical dimensions:

  • Width  : 42.10 mm
  • Length : 72 mm


The board top view is shown in the Figure 4 given below.

Figure 4

Power Ratings & Environmental Requirements

Power Options

The ESP32-CAN-X2 development board is flexible in its power input, and it provides multiple power input options. Power can either be supplied via the VIN pin, or via USB-C connector. Any voltage input either via USB or VIN is stepped down to 3.3 V via a voltage regulator.

Pin Voltage

All digital & analog pins on the ESP32-CAN-X2 development board are 3.3 V. Do not connect any higher voltage devices to any of the pins as it will risk damaging the board.

VIN Rating

The nominal input voltage rating for the development board is 6-20v, with a 40v max input. Please do not attempt to power the board with a voltage outside the recommended range.

Operating Current

The typical operating current of ESP32-CAN-X2 development board is 105mA and maximum operating current is 500mA ( peak, during transmission )

Power Consumption

The normal power consumption of the board is 330mW and peak power consumption is 1.65W

Operating Temperature

Temperate rating is -40°C to +85°C

CAN bus information

CAN, also known as Control area networking, is a serial communication protocol that is widely used in Automotive applications. CAN bus communication protocol utilizes differential signaling methods in which data is transferred as a voltage difference between High and low voltage. Can Bus communication provides various advantages over other communication methods which makes it the most important communication protocol in automotive. A few features are follows

Multimaster system

In CAN Bus communication, multiple controllers can act as a master, and multiple devices can act as a node. Each node can share data with other nodes via the CAN bus. In modern cars, there are more than 70 ECUs, and using CAN communication each ECU acts as a node and can transfer the data to the CAN bus, this data is then available to all the ECUs, and ECU can then check the data and decide whether to receive or ignore it.

For details, visit: https://www.csselectronics.com/pages/can-bus-simple-intro-tutorial

Lossless communication

CAN communication uses a bitwise arbitration method that avoids the contentions of data on the bus. When two nodes simultaneously try to send the data, then the node with the high priority ( lower identifier ) gets priority and continues transmitting. The identifier message can be 11-bit ( standard CAN ) or 29-bit ( extended CAN) in length.

For details, visit: https://dewesoft.com/blog/what-is-can-bus

Simple and cheap

The CAN communication between the ECUs is done through a single CAN system instead of direct complex analog signal lines which makes it extremely simple and reduces errors.

For details, visit: https://www.autopi.io/blog/can-bus-explained/

Errorless communication

CAN incorporates different built-in error detection mechanisms including cyclic redundancy checks (CRC), and frame check sequences (FCS) to detect errors during data transmission.

CAN network types
Prominent CAN network types are as follows.

  • High-speed CAN bus ( Supports bit rates between 40 kbit/s and 1 Mbit/s )
  • Low-Speed CAN bus ( Supports bit rates between 40 kbit/s and 125 kbit/s )
  • CAN FD ( Supports bit rates between 1 Mbps to 8 Mbps )


For details, visit:https://dewesoft.com/blog/what-is-can-bus

Data transmission

In CAN, data is transferred between two nodes in messages known as CAN frames. There are four types of CAN frames.

  • Data frame ( Used to transfer data between two node )
  • Remote frame ( request data from other node )
  • Error frame ( report errors )
  • Overload frame ( report overload )


For details, visit:https://www.autopi.io/blog/can-bus-explained/

CAN Termination

CAN termination is a process of terminating the CAN bus to prevent the signal reflection at the end of the bus and to ensure the correct DC level of the bus. The CAN BUS is bidirectional, and both ends of the bus must be properly terminated to prevent errors in communication. CAN termination is achieved by placing the termination resistance, which is normally 120 ohm, that matches the nominal resistance of the cable. ISO 11898 requires normally required CAN BUS cable of impedance 120 ohm; therefore, the CAN 120 ohm resistance is used for CAN termination. However, while doing the CAN termination, it must be kept in mind that the nodes from the far two ends of the cable only require termination resistors.

Figure 5 given below explain the CAN termination.

CAN BUS TERMINATION.png

Note :The low-speed CAN, single wire CAN, may not require the CAN bus termination.

How to enable & disable CAN termination in ESP-32-X2 ?

The ESP-32-X2 development board has given two separate CAN termination pads at the top of the development board adjacent to the 6-PIN CAN communication header. The CAN termination jumpers are shown in the figure 6 given below.

CAN BUS TERMINATION DISABLE JUMPERS.png

  • Enable termination : In ESP-32-X2 development board, CAN termination is enabled by default.
  • Disable termination : Scratch the copper trace between the pads, TERM1 & TERM2.
  • Re-enable termination : Re-solder the traces between the pads

Note : Proper termination is necessary for ensuring errorless communication and signal integrity. Please follow the above given instruction carefully.

Board Pinout

The ESP32-CAN-X2 board has 40 pins across its two headers, SV1 & SV2 headers, and a 6-pin header at the top. This guide explains the pin functionalities of the board. The pin configuration of development board shown in Figure 7 given below.

Figure 7

Left Header (SV1) Pinout (Top to Bottom)

The pin count start from the top of the left header, and the pin details are as following :

Pin Function Description
1 CAN1H/2.7D high-level signal for the first CAN channel.
2 CAN1L/2.7D low-level signal for the first CAN channel
3 CAN2H/2.7C high-level signal for the second CAN channel
4 CAN2L/2.7C low-level signal for the second CAN channel
5 RX Pin USART RX
6 TX Pin USART TX
7-20 GPIO Pins GPIO's (3.3v tolerant; to avoid damage do not apply any higher voltages to these pins)

Right Header (SV2) Pinout (Bottom to Top )

The pin count start from bottom to top and details are as following :

Pin Function Description
1-11 GPIO Pins GPIO's (3.3v tolerant; to avoid damage do not apply any higher voltages to these pins)
12-13 3.3V 3.3v Voltage Output (can be used to power your custom circuits)
14-15 5V 5v Voltage Output (can be used to power your custom circuits)
16-18 GND Ground
19-20 12 Vin 12v voltage Input

12v note

Only connect 12v to the 12v voltage input (19-20). To avoid electrical damage, do not connect 12v to any other pin on the board.

Top Header Pinout

The header supports CAN communication. Pin count start at the left viewing the board from the top. Pinout configuration of header is shown in Figure 8 given below.

Figure 8

  • Note: Color codes on the provided pigtail may not match documentation.
Pin Function Description
1 CAN1L/2.7A low-level signal for the first CAN channel
2 CAN2L/2.7B low-level signal for the second CAN channel
3 CAN2H/2.7B high-level signal for the second CAN channel
4 GND Ground
5 CAN1H/2.7A high-level signal for the first CAN channel
6 +12V_ Aux 6-12v power supply

Flashing Firmware

Firmware flashing in this development board is straightforward. The following components are required for firmware flashings.

Hardware Components

  • USB-C cable
  • Computer running Windows, Linux, or macOS


Software Components

  • Updated Arduino IDE to compile code for ESP-32-X2.
  • Update Mu Editor from codewith.mu


Note : Link to download Arduino IDE : https://www.arduino.cc/en/software || Link to download Mu Editor : codewith.mu

Step by step instruction for Arduino IDE

Sample Arduino Project

https://github.com/autosportlabs/ESP32-CAN-X2


Step-by-step instructions for flashing ESP-32-X2 are as follows.

Install ESP-32-X2 Board Support:

Adding ESP-32-X2 in Arduino Ide is a single-time process and its steps are as follows.

  • Open Arduino Ide
  • Go to File > Preferences


Figure 7

  • Add the below given Json URL in the Additional board manager URL

Json URL : https://espressif.github.io/arduino-esp32/package_esp32_index.json
Figure 8

  • Go to Tools > Board > Boards Manager


Figure 9

  • In the Board Manager search bar, type ESP-32, search for esp32 by Espressif and click on install to install the board


Figure 10


  • After installing, click on Tool > Boards and select AutosportLabs ESP32-CAN-X2


Flashing

  • Connect the ESP-32-X2 board to your computer using a USB-C cable with your Arduino IDE open
  • Select AutosportLabs ESP32-CAN-X2 in Tools > Board menu
  • Go to Tools > Port and select the COM port to which ESP-32-X2 is connected.

Figure 11
Note : If you don’t see the COM Port in your Arduino IDE, you need to install the CP210x USB to UART Bridge VCP Drivers: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers

  • Write your firmware code or add an existing sketch that you want to upload to your custom board.
  • Go to Sketch > Click upload to compile and upload the code
  • After successful uploading, you should see a “Done uploading.” message at the bottom console. This console will also show error messages if there is any error.

Figure 12

If any issues occur during upload, double-check the board selection, COM port, and your code for errors. <be>

Importing Libraries in Arduino IDE

  • To Install Libraries for ESP32-CAN-X2 like mcp_canbus or mcp2515
  • Go to Sketch > Include Library > Manage LibrarieSs

Arduino IDE Library 1.png

  • Type and find the desired library like mcp_canbus by Longan Labs
  • Search and Install the library

Arduino IDE Library 2...png

Step-by-step instruction for CircuitPython

Sample CircuitPython code

https://github.com/autosportlabs/ESP32-CAN-X2


Downloading ESP-32-X2 Board Support:

Installing ESP-32-X2 is simple, please follow the steps given below :

  • Go to circuitpython.org/board/autosportlabs_esp32_can_x2

Click on the browse S3

CircuitpythonFlashing1.png

  • Select the desired language


CircuitpythonFlashing2.png

  • Download the latest .bin file


CircuitpythonFlashing4.png

Prepare the ESP32 CAN X2 for Installation:

  • Connect the ESP-32-X2 board to your computer using a USB-C cable
  • Press and hold the boot button on the development board.
  • While holding the boot button, press and release the reset button once.
  • Release the boot button to put the board into bootloader mode.

CircuitpythonFlashing5.png

Connect to the Web Serial ESP Tool


CircuitpythonFlashing6.png

Flash the Firmware

  • Click on Choose the .bin file you downloaded.
  • Ensure that the Offset box next to the file location is set to 0x0.
  • After selecting the file, the button text will change to match your filename.
  • Click the Program button to start flashing. A progress bar will appear, and after a minute or two, the firmware will be

written.

Circuytpython7.gif

Exit Bootloader Mode

  • Press the reset button to exit bootloader mode. Shortly, the CIRCUITPY drive will pop up.

Downloading and Installing Mu Editor

  • Download and install the recommended Mu Editor from codewith.mu.
  • When you first start Mu, you will be prompted to select your mode. Select CircuitPython.


Mudownload.png

  • In Mu editor, click the Load button in the button bar, navigate to the CIRCUITPY drive, and choose code.py.


MU2.png

Note : The CIRCUITPY drive is where your code and necessary libraries will reside. With a fresh CircuitPython install, the CIRCUITPY drive will contain a code.py file with print("Hello World!") and an empty lib folder. If your CIRCUITPY drive does not have a code.py file, create one and save it to the drive. CircuitPython automatically executes the code in code.py when the board starts up or resets. Do not press reset immediately after saving your code it will corrupt the drive and you may lose your code.

  • Enter your code into the editor and save the code.py file on the CIRCUITPY drive.


MU3.png

Congratulations! You have just run your first CircuitPython program.

Importing Libraries in Circuitpython

Importing libraries in Circuitpython is straightforward. For installing Libraries in Circuitpython, please follow the steps given below :

Note: The version of the bundle should be the same that you are using.

Mu4.png

  • Extract the zip file.
  • Find the lib file where you can find your desired library.
  • Copy that library folder or .mpy file and paste it to the lib folder in CIRCUITPY drive


Mueditor Library.gif

Bolt-ons

Autosport Labs provides various add-on boards, known as "bolt-ons" for ESP32-CAN-X2. For Further details regarding bolt-on. Please click on the specific bolt-on links given below