In this illustration we will going to wire the CAN BUS (Controller Area Network Bus) Shield with Arduino, if you don’t have any background how CAN (Controller Area Network Bus) works please refer this this link. As you can see the illustration below it is demonstrated using ODB (On-board diagnostics) Interface as acquiring data from the car ECU (Engine Control Unit) if you don’t have any idea how ECU works please refer to this link
Modern vehicles are equipped with controller area network bus instead of placing a hundred, millions of cable wires communicating all devices that modern car has all electronic sensors, motors, relays lock doors, other things that plug into the car to enable more functions and having more features. From each node like the electric door locks, power window it is sending a message across the CAN when TIPM (Totally Integrated Power Module) detects a valid message it will react accordingly.
The CAN BUS Shield is a device driven by MCP2515 manufactured by Microchip Semiconductor, please refer to the MCP2515 Datasheet for more details.
Required Components
Arduino UNO
MCP2515 CAN BUS Shield
Jumper Wires / DuPont Wires
Wiring Diagram to OBD Interface
Wiring Diagram for 2 Controller Area Network
Arduino Sketch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
/* 14CORE | CAN BUS DEMO CODE =============================================================== CAN-BUS Shield Bridge Demo Requires two CAN Bus Shields First shield should be left default = CS is on D9 and INT is on D2 Second shield needs modified so CS is on D10 and INT is on D3 Written by Cory J. Fowler December 09, 2015 */ #include <mcp_can.h> #include <SPI.h> long unsigned int rxId; unsigned char len = 0; unsigned char rxBuf[8]; MCP_CAN CAN0(9); // Set first CAN interface CS to pin 9 MCP_CAN CAN1(10); // Set second CAN interface CS to pin 10 void setup() { Serial.begin(115200); pinMode(2, INPUT); // Setting pin 2 for first CAN bus /INT input pinMode(3, INPUT); // Setting pin 3 for second CAN bus /INT input CAN0.begin(CAN_500KBPS); // init first CAN bus : baudrate = 500k CAN1.begin(CAN_250KBPS); // init second CAN bus : baudrate = 250k Serial.println("CAN Bridge Example."); } void loop() { if(!digitalRead(2)) // If pin 2 is low, read receive buffer of first CAN interface { CAN0.readMsgBuf(&len, rxBuf); // Read data: len = data length, buf = data byte(s) rxId = CAN0.getCanId(); // Get message ID CAN1.sendMsgBuf(rxId, 1, len, rxBuf); // Unfortunately this library does not return if the received // message was standard or extended. So sending as extended. Serial.println("Received on CAN0"); } if(!digitalRead(3)) // If pin 3 is low, read receive buffer of second CAN interface { CAN1.readMsgBuf(&len, rxBuf); // Read data: len = data length, buf = data byte(s) rxId = CAN1.getCanId(); // Get message ID CAN0.sendMsgBuf(rxId, 1, len, rxBuf); // Unfortunately this library does not return if the received // message was standard or extended. So sending as extended. Serial.println("Received on CAN1"); } } |
Downloads
Download the CAN -Bus Shield Code Library | Pdf
Download the MCP2515 Datasheet | Pdf
Download the MCP2551 Datasheet | Pdf
Download the CAN Bus Shield Schematics Diagram | Pdf
Download the CAN Bus Shield Eagle File | Zip