Home

Awesome

esp-idf-can2socket

CANbus to BSD-Socket bridge using esp32.
It's purpose is to be a bridge between a CAN-Bus and a BSD-Socket.
You can use Python's rich library to visualize CAN data, perform statistical processing, and transfer it to other computers.
This project does not include any visualization or statistical processing.
Many python visualization and statistical processing samples are available on the Internet.

Software requirement

ESP-IDF V4.4/V5.x.
ESP-IDF V5.1 is required when using ESP32C6.

Hardware requirements

Wireing

SN65HVD23xESP32ESP32-S2/S3ESP32-C3/C6
D(CTX)--GPIO21GPIO17GPIO0(*1)
GND--GNDGNDGND
Vcc--3.3V3.3V3.3V
R(CRX)--GPIO22GPIO18GPIO1(*1)
Vref--N/CN/CN/C
CANL--To CAN Bus
CANH--To CAN Bus
RS--GNDGNDGND(*2)

(*1) You can change using menuconfig. But it may not work with other GPIOs.

(*2) N/C for SN65HVD232

Test Circuit

   +-----------+   +-----------+   +-----------+ 
   | Atmega328 |   | Atmega328 |   |   ESP32   | 
   |           |   |           |   |           | 
   | Transmit  |   | Receive   |   | 21    22  | 
   +-----------+   +-----------+   +-----------+ 
     |       |      |        |       |       |   
   +-----------+   +-----------+     |       |   
   |           |   |           |     |       |   
   |  MCP2515  |   |  MCP2515  |     |       |   
   |           |   |           |     |       |   
   +-----------+   +-----------+     |       |   
     |      |        |      |        |       |   
   +-----------+   +-----------+   +-----------+ 
   |           |   |           |   | D       R | 
   |  MCP2551  |   |  MCP2551  |   |   VP230   | 
   | H      L  |   | H      L  |   | H       L | 
   +-----------+   +-----------+   +-----------+ 
     |       |       |       |       |       |   
     +--^^^--+       |       |       +--^^^--+
     |   R1  |       |       |       |   R2  |   
 |---+-------|-------+-------|-------+-------|---| BackBorn H
             |               |               |
             |               |               |
             |               |               |
 |-----------+---------------+---------------+---| BackBorn L

      +--^^^--+:Terminaror register
      R1:120 ohms
      R2:150 ohms(Not working at 120 ohms)

ESP32C3 Super Mini+SN65HVD230
esp32c3+SN65HVD230

NOTE
3V CAN Trasnceviers like VP230 are fully interoperable with 5V CAN trasnceviers like MCP2551.
Check here.

Installation

git clone https://github.com/nopnop2002/esp-idf-can2socket
cd esp-idf-can2socket
idf.py set-target {esp32/esp32s2/esp32s3/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash

Configuration

config-top config-app

CAN Setting

config-can

WiFi Setting

config-wifi

Socket Setting

You can select the output format.

config-format-text format-text

config-format-json format-json

config-format-xml format-xml

config-format-csv format-csv

You can choose between TCP and UDP protocols.
ESP32 acts as a TCP client or a UDP client.
config-protocol-tcp

TCP Host is specified by one of the following.

config-protocol-udp-1

There are the following four methods for specifying the UDP Address.

config-protocol-udp-2

Python code

If you use the TCP protocol, you can use tcp-server.py to display the can data.
If you use the UDP protocol, you can use udp-server.py to display the can data.

Troubleshooting

There is a module of SN65HVD230 like this.
SN65HVD230-1

There is a 120 ohms terminating resistor on the left side.
SN65HVD230-22

I have removed the terminating resistor.
And I used a external resistance of 150 ohms.
A transmission fail is fixed.
SN65HVD230-33

If the transmission fails, these are the possible causes.

Reference

https://github.com/nopnop2002/esp-idf-candump

https://github.com/nopnop2002/esp-idf-can2http

https://github.com/nopnop2002/esp-idf-can2mqtt

https://github.com/nopnop2002/esp-idf-can2usb

https://github.com/nopnop2002/esp-idf-can2websocket

https://github.com/nopnop2002/esp-idf-CANBus-Monitor