290 lines
11 KiB
Markdown
290 lines
11 KiB
Markdown
# Sillyfilly-CAN
|
|
A fork of [esp-idf-can2http](https://github.com/nopnop2002/esp-idf-can2http)
|
|
|
|
A CAN bus tool built for the esp32. It has a builtin web interface and works with nearly any CAN transceiver like the [N65HVD230](https://www.amazon.com/SN65HVD230-CAN-Board-Communication-Development/dp/B00KM6XMXO/) or the [TJA1050](https://www.amazon.com/Comimark-Transceiver-TJA1050-Controller-Schnittstelle/dp/B07W4VZ2F2/)
|
|
|
|
## Hardware needed
|
|
* esp32(-X) (My favorite esp32)[https://www.amazon.com/Espressif-ESP32-S3-DevKitC-1-N32R8V-Development-Board/dp/B09R4GSDJM]
|
|
* CAN transceiver like the [N65HVD230](https://www.amazon.com/SN65HVD230-CAN-Board-Communication-Development/dp/B00KM6XMXO/) or the [TJA1050](https://www.amazon.com/Comimark-Transceiver-TJA1050-Controller-Schnittstelle/dp/B07W4VZ2F2/)
|
|
some jumper wires
|
|
* Jumper wires
|
|
|
|
## Optional
|
|
* [ODB2 pigtail](https://www.amazon.com/iKKEGOL-Connector-Diagnostic-Extension-Pigtail/dp/B0828YHWFG/)
|
|
|
|
## Installation
|
|
1) install [esp-idf](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/index.html#installation) if not installed on your computer already
|
|
2) open esp-idf terminal
|
|
3) plug in your esp32 to computer via USB cable
|
|
4) Run these commands:
|
|
```
|
|
git clone https://github.com/PrincessPi3/Sillyfilly-CAN.git
|
|
cd Sillyfilly-CAN
|
|
idf.py set-target esp32s3 # example idf.py set-target <your_esp32_ type>
|
|
idf.py menuconfig
|
|
```
|
|
5) Under "Sillyfilly-CAN Configuration" set your settings like wifi and CRX and CTX pins.
|
|
6) Wire transceiver to the pins: CRX->RX, CTX-TX, GND->GND
|
|
7) run this command
|
|
```idf.py flash monitor # ctrl+] to exit monitor```
|
|
<your_esp32_type> can be one of 'esp32', 'esp32s2', 'esp32c3', 'esp32s3', 'esp32c2', 'esp32c6', 'esp32h2', 'esp32p4', 'esp32c5', 'esp32c61'
|
|
|
|
# Original README.md
|
|
# esp-idf-can2http
|
|
CANbus to http bridge using esp32.
|
|
It's purpose is to be a bridge between a CAN-Bus and a HTTP-Server.
|
|
|
|

|
|

|
|

|
|
|
|
|
|
# Software requirement
|
|
ESP-IDF V4.4/V5.x.
|
|
ESP-IDF V5.1 is required when using ESP32C6.
|
|
|
|
# Hardware requirements
|
|
- 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.
|
|
|
|
# Wireing
|
|
|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
|
|
|
|
|
|
|
|
# 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)
|
|
```
|
|
|
|
__NOTE__
|
|
3V CAN Trasnceviers like VP230 are fully interoperable with 5V CAN trasnceviers like MCP2551.
|
|
Check [here](http://www.ti.com/lit/an/slla337/slla337.pdf).
|
|
|
|
|
|
# Installation
|
|
```
|
|
git clone https://github.com/nopnop2002/esp-idf-can2http
|
|
cd esp-idf-can2http
|
|
idf.py set-target {esp32/esp32s2/esp32s3/esp32c3/esp32c6}
|
|
idf.py menuconfig
|
|
idf.py flash
|
|
```
|
|
|
|
# Configuration
|
|

|
|

|
|
|
|
## CAN Setting
|
|

|
|
|
|
## WiFi Setting
|
|

|
|
|
|
You can use static IP.
|
|

|
|
|
|
You can connect using mDNS.
|
|

|
|
|
|
## External HTTP Server Setting
|
|
The External HTTP Server receives CAN Bus received data.
|
|

|
|
|
|
__Note__
|
|
The Built-in HTTP Server receives CAN Bus transmittion data.
|
|
|
|
# Definition from CANbus to HTTP
|
|
When CANbus data is received, it is sent by HTTP POST according to csv/can2http.csv.
|
|
The file can2http.csv has three columns.
|
|
In the first column you need to specify the CAN Frame type.
|
|
The CAN frame type is either S(Standard frame) or E(Extended frame).
|
|
In the second column you have to specify the CAN-ID as a __hexdecimal number__.
|
|
In the last column you have to specify the HTTP-POST-Path of external HTTP server.
|
|
Each CAN-ID is allowed to appear only once in the whole file.
|
|
|
|
```
|
|
S,101,/post
|
|
E,101,/post
|
|
S,103,/post
|
|
E,103,/post
|
|
```
|
|
|
|
When a CAN frame with ID 0x101 is received, POST with the 'canid':257.
|
|
When a CAN frame with ID 0x103 is received, POST with the 'canid':259.
|
|
|
|
POST Parameter Example:
|
|
CAN-ID is a decimal number, not a hexadecimal number.
|
|
|
|
```
|
|
{"canid":257, "frame": "standard", "data": [16, 17, 18]}
|
|
{"canid":257, "frame": "extended", "data": [16, 17, 18]}
|
|
{"canid":259, "frame": "standard", "data": [16, 17, 18]}
|
|
{"canid":259, "frame": "extended", "data": [16, 17, 18]}
|
|
```
|
|
|
|
__CAN messages not registered in csv/can2http.csv are discarded and not POSTed to HTTP.__
|
|
|
|
# Definition from HTTP to CANbus
|
|
Not exist.
|
|
You can send any CAN-ID.
|
|
|
|
|
|
# Send CANBus frame using curl
|
|
CAN-ID is specified in __decimal number__.
|
|
```
|
|
$ curl -X POST -H "Content-Type: application/json" -d '{"canid": 513, "frame": "standard", "data": [16, 17, 18]}' http://esp32-server.local:8000/api/twai/send
|
|
twai send successfully
|
|
|
|
$ curl -X POST -H "Content-Type: application/json" -d '{"canid": 513, "frame": "extended", "data": [16, 17, 18]}' http://esp32-server.local:8000/api/twai/send
|
|
twai send successfully
|
|
```
|
|
|
|
CANBus reception using UNO.
|
|
|
|

|
|
|
|

|
|
|
|
|
|
---
|
|
|
|
# HTTP Server Using Tornado
|
|
```
|
|
cd $HOME
|
|
sudo apt install python3-pip python3-setuptools
|
|
python3 -m pip install -U pip
|
|
python3 -m pip install -U wheel
|
|
python3 -m pip install tornado
|
|
git clone https://github.com/nopnop2002/esp-idf-can2http
|
|
cd esp-idf-can2http
|
|
cd tornado
|
|
python3 can.py
|
|
```
|
|
|
|
You can specify the number of lines to display and the port number.
|
|
The default port number is 8000 and the default number of display lines is 20.
|
|
Redisplay every 5 seconds.
|
|

|
|
|
|
|
|
# HTTP Server Using Flask
|
|
```
|
|
cd $HOME
|
|
sudo apt install python3-pip python3-setuptools
|
|
python3 -m pip install -U pip
|
|
python3 -m pip install -U wheel
|
|
python3 -m pip install -U Werkzeug
|
|
python3 -m pip install flask
|
|
git clone https://github.com/nopnop2002/esp-idf-can2http
|
|
cd esp-idf-can2http
|
|
cd flask
|
|
python3 can.py
|
|
```
|
|
|
|
You can specify the number of lines to display and the port number.
|
|
The default port number is 8000 and the default number of display lines is 20.
|
|
Redisplay every 5 seconds.
|
|

|
|
|
|
|
|
# Brows received data Using Tornado/Flask
|
|
Open your browser and put the Server's IP in the address bar.
|
|
|
|

|
|
|
|
# Visualize CAN-Frame
|
|
|
|
## Using python
|
|
There is a lot of information on the internet about the Python + visualization library.
|
|
- [matplotlib](https://matplotlib.org/)
|
|
- [seaborn](https://seaborn.pydata.org/index.html)
|
|
- [bokeh](https://bokeh.org/)
|
|
- [plotly](https://plotly.com/python/)
|
|
|
|
## Using node.js
|
|
There is a lot of information on the internet about the node.js + __real time__ visualization library.
|
|
- [epoch](https://epochjs.github.io/epoch/real-time/)
|
|
- [plotly](https://plotly.com/javascript/streaming/)
|
|
- [chartjs-plugin-streaming](https://nagix.github.io/chartjs-plugin-streaming/1.9.0/)
|
|
|
|
# Troubleshooting
|
|
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://e2e.ti.com/support/interface-group/interface/f/interface-forum/378932/iso1050-can-bus-stub-length).
|
|
|
|
# Reference
|
|
https://github.com/nopnop2002/esp-idf-candump
|
|
|
|
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-can2socket
|
|
|
|
https://github.com/nopnop2002/esp-idf-CANBus-Monitor
|
|
|