# CAN-BUS setup ### CANDO Module ![CANDO](https://i.imgur.com/enHvStl.jpg =400x200) --- ![](https://i.imgur.com/Xb25Zn5.png) ### 1. Connection ```graphviz digraph hierarchy { nodesep=0.5 node [color=Black,fontname=Courier,shape=box] edge [color=Black, style=dashed] CAN_H->Green[color=Green] CAN_L->Yellow[color=Orange] {rank=right;CAN_H Green} {rank=right;CAN_L Yellow} } ``` ### 2. SocketCAN (Linux only) - List CAN devices ```bash ifconfig -a ``` - Set can bitrate to 500k bps ```bash sudo ip link set up can0 type can bitrate 500000 ``` - Enable can0 device ```bash sudo ip link set up can0 ``` - Disable can0 device ```bash sudo ip link set down can0 ``` 1. Prep CanDo connection ```sh cd ~/evpi_ws/src/evpi_bringup/startup_service ./set_cando_unbuntu20.sh ``` 2. Setup service for evpi_bringup ```sh sudo cp ~/evpi_ws/src/evpi_bringup/startup_service/evpi.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl start evpi.service # Runs the script now sudo systemctl enable evpi.service # Sets the script to run every boot ``` 3. Check the status ```sh systemctl status evpi.service ``` ### can-utils --- Installation ```bash sudo apt-get install can-utils ``` See the raw traffic on the CAN bus. ```bash # for all devices candump can0 # for data from id 0x123 candump vcan0,0x123:0x7FF # for data from id 0x123 and 0x456 candump vcan0,0x123:0x7FF,0x456:0x7FF ``` Send a single CAN message on the bus. Pass the CAN ID, then # then the data bytes. ```bash cansend can0 120#0011223344 ``` See changing CAN traffic. Very useful to identify which bytes of which message contain the value for a sensor like the accelerator, brake, steering wheel sensor. ```bash cansniffer can0 -cae ``` Generate random CAN messages so their effect can be investigated. See cangen -h for details on the arguments. ```bash cangen can0 ``` Replay captured CAN log file from candump. ```bash canplayer -I can_trace.asc can0 ```