There are many CAN libraries that work with the ESP32, here are the ones I've found so far. If you are thinking about an ESP32 based CAN project my tip is to check out the examples included with each library, they will give you some idea on different approaches.
https://github.com/collin80/esp32_can - NOTE: This library now works with both ESP32 and ESP-S3
https://github.com/sandeepmistry/arduino-CAN
https://github.com/adafruit/arduino-CAN
https://github.com/timurrrr/arduino-CAN
If you only want to access OBD2 data and not dive into the lower layer CAN bus this is also available:
https://github.com/sandeepmistry/arduino-OBD2
I'm sure there are more libraries out there. If you find something that has some special advantage feel free to email me so I can add it here
Since the ESP32-S3 is slightly different when it comes to its CAN API compared to the older ESP32 one way to code for it is to use Visual Code Studio and the Espressif toolchain by following these install instructions:
https://github.com/espressif/vscode-esp-idf-extension/blob/master/docs/tutorial/install.md
I've made some examples that you can use in the Arduino IDE with just the libraries that come with the board installation if you don't want to use Visual Code Studio:
https://github.com/MagnusThome/RejsaCAN-ESP32/tree/main/Code%20Examples (use the ESP32-S3 examples)
But if you want to use the Arduino IDE and a known Arduino library this one is now supporting the S3: https://github.com/collin80/esp32_can
I added a simplified OBD2 library for the above CAN library to make requesting standard OBD2 data really easy. It is a fork and rewrite of the OBD2 library written by sandeepmistry
https://github.com/MagnusThome/esp32_obd2
I also did a quick rewrite/hack of ESP32RET to support the newer ESP32-S3 chip (that does not have old school serial BT)
https://github.com/MagnusThome/ESP32S3RET
You can also look into these interesting ports for ESP32-S3 that might be useful:
https://github.com/pawelka/ESP32RET
https://github.com/pawelka/esp32_can
https://github.com/sdp8483/ESP32-Arduino-CAN
https://github.com/Sheimy/TWAI_S3_LISEN
https://github.com/halfroad/TWAIMessager
A great video showing how to use the S3's built in USB (and separate UART) in different modes, CDC/OTG:
https://www.youtube.com/watch?v=hJSBTFsOnoA
Recommended settings in the Arduino IDE for the S3:
The USB chip on the 2.x boards is a CP2104 from Silicon Labs
You can find drivers for your PC here under downloads https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
Download and install the Arduino IDE development editor https://www.arduino.cc/en/software
Start the IDE and go to File > Preferences
Click the symbol on the right side
Add the line
https://dl.espressif.com/dl/package_esp32_index.json
Go to Tools > Board: xxx > Boards Manager...
Enter "ESP32" in the search box and hit enter to search, then click and install the latest version
Go to Tools > Board: xxx > ESP32 Arduino > and choose ESP32 Dev Module
Go to Tools > Manage Libraries...
When you have decided what CAN library/libraries you want to use, search for and install these from here. But since it is often a bit tricky to search for CAN libraries since the word "can" is present in many many other libraries it is often easier to go directly to github and download the library you are after, unzip and place the contents in the Arduino library directory (which normally is found in the same directory as where you place your projects).
Most of the code examples on here needs these two libraries https://github.com/collin80/esp32_can and https://github.com/collin80/can_common (as stated within the example code ;-)
To set the S3 version of the ESP32 into code download mode, hold the PROG button pressed while pressing the RESET button. Release the RESET button first then the PROG button.
- Download and install Arduino IDE or cli for your platform.
- Download and install ESP32 prerequisites
- Follow the steps 1-5 on setting up the ESP32 environment.
- If you wish to compile and flash the ESP32 blink example, do so by going to ~/esp/esp-idf, and do
- $ source export.sh
- $ cd ~/esp/esp-idf/examples/blink
- $ idf.py build to compile
- $ idf.py -p (PORT) flash
- If you have a v2.1 board, change #define BLINK_GPIO CONFIG_BLINK_GPIO to: #define BLINK_GPIO 13
- recompile and reflash to get the blue LED blinking
- Choose what CAN library/libraries you want to use and download, for example clone esp32_can and can_common to your ~/Arduino/libraries directory.
- copy obd2.h to ~/Arduino/libraries/obd2/
- Install ESP32 environment for Arduino
- Choose "ESP32 Dev Module" as your board, build and flash!