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.
If you only want to access OBD2 data and not dive into the lower layer CAN bus this is also available:
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
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 ;-)
- 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!