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.
ESP-IDF V4.4/V5.x.
ESP-IDF V5.1 is required when using ESP32C6.
-
SN65HVD23x CAN-BUS Transceiver
SN65HVD23x series has 230/231/232.
They differ in standby/sleep mode functionality.
Other features are the same. -
Termination resistance
I used 150 ohms.
SN65HVD23x | ESP32 | ESP32-S2/S3 | ESP32-C3/C6 | ||
---|---|---|---|---|---|
D(CTX) | -- | GPIO21 | GPIO17 | GPIO0 | (*1) |
GND | -- | GND | GND | GND | |
Vcc | -- | 3.3V | 3.3V | 3.3V | |
R(CRX) | -- | GPIO22 | GPIO18 | GPIO1 | (*1) |
Vref | -- | N/C | N/C | N/C | |
CANL | -- | To CAN Bus | |||
CANH | -- | To CAN Bus | |||
RS | -- | GND | GND | GND | (*2) |
(*1) You can change using menuconfig. But it may not work with other GPIOs.
(*2) N/C for SN65HVD232
+-----------+ +-----------+ +-----------+
| 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)
NOTE
3V CAN Trasnceviers like VP230 are fully interoperable with 5V CAN trasnceviers like MCP2551.
Check here.
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
You can select the output format.
You can choose between TCP and UDP protocols.
ESP32 acts as a TCP client or a UDP client.
TCP Host is specified by one of the following.
- IP address
192.168.10.20
- mDNS host name
tcp-server.local
- Fully Qualified Domain Name
tcp-server.mydomain.com
There are the following four methods for specifying the UDP Address.
-
Limited broadcast address
The address represented by 255.255.255.255, or <broadcast>, cannot cross the router.
Both the sender and receiver must specify a Limited broadcast address. -
Directed broadcast address
It is possible to cross the router with an address that represents only the last octet as 255, such as 192.168.10.255.
Both the sender and receiver must specify the Directed broadcast address.
Note that it is possible to pass through the router. -
Multicast address
Data is sent to all PCs belonging to a specific group using a special address (224.0.0.0 to 239.255.255.255) called a multicast address.
I've never used it, so I don't know anything more. -
Unicast address
It is possible to cross the router with an address that specifies all octets, such as 192.168.10.41.
Both the sender and receiver must specify the Unicast address.
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.
There is a module of SN65HVD230 like this.
There is a 120 ohms terminating resistor on the left side.
I have removed the terminating resistor.
And I used a external resistance of 150 ohms.
A transmission fail is fixed.
If the transmission fails, these are the possible causes.
- There is no receiving app on CanBus.
- The speed does not match the receiver.
- There is no terminating resistor on the CanBus.
- There are three terminating resistors on the CanBus.
- The resistance value of the terminating resistor is incorrect.
- Stub length in CAN bus is too long. See here.
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