<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://elvis.hcw.ac.at/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NStrasser</id>
	<title>Elvis Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://elvis.hcw.ac.at/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=NStrasser"/>
	<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php/Special:Contributions/NStrasser"/>
	<updated>2026-09-10T16:24:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.5</generator>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6050</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6050"/>
		<updated>2021-02-24T18:32:52Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: NStrasser moved page Creating CAN-BUS Shield V2.0 to Creating CAN-BUS Shield V2.0 Tutorial over redirect&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6048</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6048"/>
		<updated>2021-02-24T18:32:38Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: NStrasser moved page Creating CAN-BUS Shield V2.0 Tutorial to Creating CAN-BUS Shield V2.0&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=CAN-BUS_Shield_V2.0&amp;diff=6047</id>
		<title>CAN-BUS Shield V2.0</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=CAN-BUS_Shield_V2.0&amp;diff=6047"/>
		<updated>2021-02-24T18:31:27Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: NStrasser moved page CAN-BUS Shield V2.0 to Creating CAN-BUS Shield V2.0 Tutorial&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Creating CAN-BUS Shield V2.0 Tutorial]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6046</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6046"/>
		<updated>2021-02-24T18:31:27Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: NStrasser moved page CAN-BUS Shield V2.0 to Creating CAN-BUS Shield V2.0 Tutorial&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6045</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6045"/>
		<updated>2021-02-24T18:29:55Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6044</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6044"/>
		<updated>2021-02-24T18:27:31Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0 Tutorial]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6042</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6042"/>
		<updated>2021-02-24T08:22:50Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6041</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6041"/>
		<updated>2021-02-24T08:20:45Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0:Summary]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6040</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6040"/>
		<updated>2021-02-24T08:19:59Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0|Summary]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6039</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6039"/>
		<updated>2021-02-24T08:03:06Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6038</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6038"/>
		<updated>2021-02-23T21:20:28Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Can_log_file.JPG&amp;diff=6037</id>
		<title>File:Can log file.JPG</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Can_log_file.JPG&amp;diff=6037"/>
		<updated>2021-02-23T21:20:00Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6036</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6036"/>
		<updated>2021-02-23T21:19:43Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somewhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take from 15ms up to 50ms for opening. The lab was setup with a sending interval of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. When slowing down the speed to 500ms a CAN.LOG file is genereated and populated as programmed.&lt;br /&gt;
&lt;br /&gt;
[[File:Can_log_file.JPG|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6035</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6035"/>
		<updated>2021-02-23T21:14:42Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
=== Taking it further ===&lt;br /&gt;
&lt;br /&gt;
Next we aim to build a CAN message reader for a real car. Therefore we somehow need to save the captured packets somwhere. The CAN-BUS Shield V2.0 comes with a built in memory card slot. We will utilize it and save captured data onto it. In order to do that we need to include the SD.h header file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SD.h&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the setup function we need to activate SD module.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
if (!SD.begin(4))&lt;br /&gt;
{&lt;br /&gt;
    SERIAL.println(&amp;quot;SD Card init failed. Check PIN&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this has happend we can start opening a file and writing to it.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
File dataFile = SD.open(&amp;quot;can.log&amp;quot;, FILE_WRITE);&lt;br /&gt;
if (dataFile)&lt;br /&gt;
{&lt;br /&gt;
    dataFile.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
    dataFile.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
    dataFile.println(canId, HEX);&lt;br /&gt;
    for (int i = 0; i &amp;lt; len; i++)&lt;br /&gt;
    { // print the data&lt;br /&gt;
        dataFile.print(buf[i], HEX);&lt;br /&gt;
        dataFile.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    dataFile.println();&lt;br /&gt;
    dataFile.close();&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
    Serial.println(&amp;quot;error opening datalog.txt&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unfortunately I ran into troubles with the writing speeds. CAN is sending data way much faster than it can be written to a file so the Arduino starts to stuck and cannot open the file anymore. A file on a SD card can take up to 50ms for opening. The lab was setup with a frequency of 100ms. In a real world card the freuquency would be much higher so logging on the SD card won&#039;t work. &lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6034</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6034"/>
		<updated>2021-02-23T20:14:03Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== Hardware details ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
== Hands on lab ==&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6033</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6033"/>
		<updated>2021-02-23T20:12:59Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: /* Used Hardware */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
2 x [[Arduino Board Uno Rev3 DIP Version, ATmega328, USB]]&lt;br /&gt;
&lt;br /&gt;
2 x [[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
2 x Jumper wires&lt;br /&gt;
&lt;br /&gt;
2 x USB 2.0 B to USB 2.0 A cables&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6032</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6032"/>
		<updated>2021-02-23T20:10:09Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Arduino UNO]]&lt;br /&gt;
&lt;br /&gt;
[[CAN-BUS Shield V2.0]]&lt;br /&gt;
&lt;br /&gt;
[[2 x Jumper wires]]&lt;br /&gt;
&lt;br /&gt;
[[2 x USB 2.0 B to USB 2.0 A cables]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6031</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6031"/>
		<updated>2021-02-23T20:09:35Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which basically means that the difference between CAN-H and CAN-L signal is used to determine which bit was transfered. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated. In a real world example the CAN Bus is terminated on each end with a 120k Ohm resistor. Because this is a lab setup and the distance of the CAN Bus is minimal it is not neccessary to terminate the bus with 120k Ohm resistors.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE. &lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Arduino UNO]]&lt;br /&gt;
[[CAN-BUS Shield V2.0]]&lt;br /&gt;
[[2 x Jumper wires]]&lt;br /&gt;
[[2 x USB 2.0 B to USB 2.0 A cables]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6030</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6030"/>
		<updated>2021-02-23T20:05:47Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car built after 1994. CAN was founded by BOSCH primarily to shrink cable harness within cars. This bus is robust because of its differential signal transmission which on other words mean the difference between CAN-H and CAN-L signal is used to determine the transfered bits. CAN uses a broadcast to transfer messages. Each message contains an identifier with which the priority is negotiated.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
When both Arduinos are flashed correctly the will start blinking. The sending nodes TX and RX LEDs will blink as CAN transceivers listen and write to the bus simultaneously. On the receiving node the RX and the INT LEDs will start to blink. Everytime a CAN message is received an interrupt is triggered to run the specified function which in this case is printing the raw data to SERIAL:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Arduino UNO]]&lt;br /&gt;
[[CAN-BUS Shield V2.0]]&lt;br /&gt;
[[2 x Jumper wires]]&lt;br /&gt;
[[2 x USB 2.0 B to USB 2.0 A cables]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
* https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6029</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6029"/>
		<updated>2021-02-23T19:53:05Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. &lt;br /&gt;
&lt;br /&gt;
The following code is based on the send example from the library and needs to be flashed on the first node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next we need the code for the receiving node.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin                           &lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif&lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop() {&lt;br /&gt;
    unsigned char len = 0;&lt;br /&gt;
    unsigned char buf[8];&lt;br /&gt;
&lt;br /&gt;
    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming&lt;br /&gt;
        CAN.readMsgBuf(&amp;amp;len, buf);    // read data,  len: data length, buf: data buf&lt;br /&gt;
&lt;br /&gt;
        unsigned long canId = CAN.getCanId();&lt;br /&gt;
&lt;br /&gt;
        SERIAL.println(&amp;quot;-----------------------------&amp;quot;);&lt;br /&gt;
        SERIAL.print(&amp;quot;Get data from ID: 0x&amp;quot;);&lt;br /&gt;
        SERIAL.println(canId, HEX);&lt;br /&gt;
&lt;br /&gt;
        for (int i = 0; i &amp;lt; len; i++) { // print the data&lt;br /&gt;
            SERIAL.print(buf[i], HEX);&lt;br /&gt;
            SERIAL.print(&amp;quot;\t&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        SERIAL.println();&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step 4 ====&lt;br /&gt;
Nodes are talking to each other:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6028</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6028"/>
		<updated>2021-02-23T19:49:12Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
Download and install the Arduino IDE. Afterwards we need to install the CAN-Shield library which can be found here https://github.com/Seeed-Studio/Seeed_Arduino_CAN. Download this repository as zip file and import it to the Arduino IDE:&lt;br /&gt;
[[File:Add_lib.JPG|750px]]&lt;br /&gt;
&lt;br /&gt;
==== Step 3 ====&lt;br /&gt;
Next we are going to need a sending node, which will send CAN messages at periodic intervalls and we will need an receiving node, which listens on the CAN Bus and creates an interrupt everytime a package is received. The following code is based on the send example from the library.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;SPI.h&amp;gt;&lt;br /&gt;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE&lt;br /&gt;
    #define SERIAL SerialUSB&lt;br /&gt;
#else&lt;br /&gt;
    #define SERIAL Serial&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#define CAN_2515&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
#include &amp;quot;mcp2518fd_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2515&lt;br /&gt;
#include &amp;quot;mcp2515_can.h&amp;quot;&lt;br /&gt;
const int SPI_CS_PIN = 9;&lt;br /&gt;
const int CAN_INT_PIN = 2;&lt;br /&gt;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin&lt;br /&gt;
#endif                              // Set CS pin&lt;br /&gt;
&lt;br /&gt;
void setup() {&lt;br /&gt;
    SERIAL.begin(115200);&lt;br /&gt;
    while(!Serial){};&lt;br /&gt;
&lt;br /&gt;
#ifdef CAN_2518FD&lt;br /&gt;
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k&lt;br /&gt;
#else&lt;br /&gt;
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k&lt;br /&gt;
#endif        &lt;br /&gt;
        SERIAL.println(&amp;quot;CAN BUS Shield init fail&amp;quot;);&lt;br /&gt;
        SERIAL.println(&amp;quot; Init CAN BUS Shield again&amp;quot;);&lt;br /&gt;
        delay(100);&lt;br /&gt;
    }&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS Shield init ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};&lt;br /&gt;
void loop() {&lt;br /&gt;
    // send data:  id = 0x00, standrad frame, data len = 8, stmp: data buf&lt;br /&gt;
    stmp[7] = stmp[7] + 1;&lt;br /&gt;
    if (stmp[7] == 100) {&lt;br /&gt;
        stmp[7] = 0;&lt;br /&gt;
        stmp[6] = stmp[6] + 1;&lt;br /&gt;
&lt;br /&gt;
        if (stmp[6] == 100) {&lt;br /&gt;
            stmp[6] = 0;&lt;br /&gt;
            stmp[5] = stmp[6] + 1;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    CAN.sendMsgBuf(0x00, 0, 8, stmp);&lt;br /&gt;
    delay(100);                       // send data per 100ms&lt;br /&gt;
    SERIAL.println(&amp;quot;CAN BUS sendMsgBuf ok!&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Step x ====&lt;br /&gt;
Nodes are talking to each other:&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking.gif|500 px]]&lt;br /&gt;
&lt;br /&gt;
[[File:Nodes_talking_console.JPG|1000 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Add_lib.JPG&amp;diff=6027</id>
		<title>File:Add lib.JPG</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Add_lib.JPG&amp;diff=6027"/>
		<updated>2021-02-23T19:35:55Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6026</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6026"/>
		<updated>2021-02-23T19:29:38Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
=== Step x ===&lt;br /&gt;
Nodes are talking to each other:&lt;br /&gt;
[[File:Nodes_talking.gif]]&lt;br /&gt;
[[File:Nodes_talking_console.JPG]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Nodes_talking_console.JPG&amp;diff=6025</id>
		<title>File:Nodes talking console.JPG</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Nodes_talking_console.JPG&amp;diff=6025"/>
		<updated>2021-02-23T19:29:13Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Nodes_talking.gif&amp;diff=6024</id>
		<title>File:Nodes talking.gif</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Nodes_talking.gif&amp;diff=6024"/>
		<updated>2021-02-23T19:27:08Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6023</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6023"/>
		<updated>2021-02-21T10:07:27Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle cable. This will enable is to take the CAN-Node (Arduino and CAN-Shield) and plug it into the cars OBD 2.0 port in order to see what is going on on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6022</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6022"/>
		<updated>2021-02-21T10:05:32Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtact Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtact Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6021</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6021"/>
		<updated>2021-02-21T09:46:28Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6020</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6020"/>
		<updated>2021-02-21T09:45:18Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6019</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6019"/>
		<updated>2021-02-21T09:44:37Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car.&lt;br /&gt;
&lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
CAN is the abbrevation for Controller Area Network and is a common and reliable bus system. It is used in almost every car since 1994. CAN was founded by BOSCH. Its main aim is to shrink cable harness.&lt;br /&gt;
&lt;br /&gt;
In order to complete the following steps, you should be familiar with the Arduino UNO and the Arduino IDE.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
* https://www.bosch.com/de/stories/das-controller-area-network/&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6018</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6018"/>
		<updated>2021-02-20T20:06:18Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;(DRAFT)&lt;br /&gt;
&lt;br /&gt;
== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car. &lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6017</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6017"/>
		<updated>2021-02-20T19:49:14Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car. &lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg|500 px]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Pigiback the CAN shields onto the Arduinos and connect both terminals. Bare in mind connecting CAN-H on the first board with CAN-H on the second board and CAN-L on the first board with CAN-L on the second board. This would look something like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Arduino_ECUs_connected.jpg|400 px]]&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Arduino_ECUs_connected.jpg&amp;diff=6016</id>
		<title>File:Arduino ECUs connected.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Arduino_ECUs_connected.jpg&amp;diff=6016"/>
		<updated>2021-02-20T19:47:11Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6015</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6015"/>
		<updated>2021-02-20T19:37:48Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car. &lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator: PWR=power;TX=blink when the data is sending;RX=blink when there&#039;s data receiving;INT=data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6014</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6014"/>
		<updated>2021-02-20T19:35:53Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car. &lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator:&lt;br /&gt;
PWR: power&lt;br /&gt;
TX: blink when the data is sending&lt;br /&gt;
RX: blink when there&#039;s data receiving&lt;br /&gt;
INT: data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6013</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6013"/>
		<updated>2021-02-20T19:35:33Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car. &lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg]]&lt;br /&gt;
&lt;br /&gt;
# Terminal: CAN-H, CAN-L&lt;br /&gt;
# Led Indicator:&lt;br /&gt;
  ## PWR: power&lt;br /&gt;
  ## TX: blink when the data is sending&lt;br /&gt;
  ## RX: blink when there&#039;s data receiving&lt;br /&gt;
  ## INT: data interrupt&lt;br /&gt;
# V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
# DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
# Arduino Pinouts&lt;br /&gt;
# I2C Connector&lt;br /&gt;
# Serial Connector&lt;br /&gt;
# ICSP Pins&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6012</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6012"/>
		<updated>2021-02-20T19:34:24Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car. &lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg]]&lt;br /&gt;
&lt;br /&gt;
* Terminal: CAN-H, CAN-L&lt;br /&gt;
* Led Indicator:&lt;br /&gt;
  PWR: power&lt;br /&gt;
  TX: blink when the data is sending&lt;br /&gt;
  RX: blink when there&#039;s data receiving&lt;br /&gt;
  INT: data interrupt&lt;br /&gt;
* V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
* DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
* Arduino Pinouts&lt;br /&gt;
* I2C Connector&lt;br /&gt;
* Serial Connector&lt;br /&gt;
* ICSP Pins&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6011</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6011"/>
		<updated>2021-02-20T19:33:19Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains an example implementation, which is able to read and write CAN messages. In another step a real car communication is captured and presented.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is an add-on shield which can be used with an Arduino Board. It comes with the MCP2515 CAN Bus Controller and the MCP2551 CAN transceiver. When used with an appropriate OBD 2.0 cable and library it can function as a diagnostic tool for a car. &lt;br /&gt;
[[File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg]]&lt;br /&gt;
&lt;br /&gt;
1. Terminal: CAN-H, CAN-L&lt;br /&gt;
2. Led Indicator:&lt;br /&gt;
    PWR: power&lt;br /&gt;
    TX: blink when the data is sending&lt;br /&gt;
    RX: blink when there&#039;s data receiving&lt;br /&gt;
    INT: data interrupt&lt;br /&gt;
3. V_OBD: Indicates if the power comes from OBD&lt;br /&gt;
4. DB9 Interface: to connect to OBD 2.0 via DB9-OBDII-cable&lt;br /&gt;
5. Arduino Pinouts&lt;br /&gt;
6. I2C Connector&lt;br /&gt;
7. Serial Connector&lt;br /&gt;
8. ICSP Pins&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
* https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg&amp;diff=6010</id>
		<title>File:InkedCAN-BUS Shield V2.0 desc LI.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:InkedCAN-BUS_Shield_V2.0_desc_LI.jpg&amp;diff=6010"/>
		<updated>2021-02-20T19:28:39Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6009</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6009"/>
		<updated>2021-02-20T19:05:42Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which in its easiest form is able to read and write CAN messages. In another step a real car communication is captured.  &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is a add-on shield for Arudion &lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6008</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6008"/>
		<updated>2021-02-20T16:09:24Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which is able to read CAN messages from a real car. &lt;br /&gt;
&lt;br /&gt;
== CAN-BUS Shield V2.0 ==&lt;br /&gt;
&lt;br /&gt;
The CAN-BUS Shield V2.0 is a add-on shield for Arudion &lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6007</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6007"/>
		<updated>2021-02-20T16:06:56Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which is able to read CAN messages from a real car. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
== Implementation ==&lt;br /&gt;
&lt;br /&gt;
=== Requirements ===&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
=== Description ===&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Step 1 ====&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
==== Step 2 ====&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
=== Used Hardware ===&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ===&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ===&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6006</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6006"/>
		<updated>2021-02-20T16:04:41Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which is able to read CAN messages from a real car. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up a lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate two ECUs, where one of them sends the data and the other is receives it. After this works as planned we will take a step further and integrate the CANtext Bundle. This will enable is to take the reading Arduino-ECU and plug it into the cars OBD 2.0 port in order to see what is going on the car CAN-BUS.&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:Arduino_Uno.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
== Used Hardware ==&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Arduino_Uno.jpg&amp;diff=6005</id>
		<title>File:Arduino Uno.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Arduino_Uno.jpg&amp;diff=6005"/>
		<updated>2021-02-20T16:01:02Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6004</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6004"/>
		<updated>2021-02-20T16:00:47Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which is able to read CAN messages from a real car. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up the lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate an ECU. After this works as planned we will take a step further and integrate the CANtext Bundle. &lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|CAN-BUS Shield V2.0]]&lt;br /&gt;
[[File:CAN-BUS_Shield_V2.0.jpg|thumb|Arduino UNO]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
== Used Hardware ==&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:CAN-BUS_Shield_V2.0.jpg&amp;diff=6003</id>
		<title>File:CAN-BUS Shield V2.0.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:CAN-BUS_Shield_V2.0.jpg&amp;diff=6003"/>
		<updated>2021-02-20T16:00:17Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6002</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6002"/>
		<updated>2021-02-20T16:00:04Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which is able to read CAN messages from a real car. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up the lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate an ECU. After this works as planned we will take a step further and integrate the CANtext Bundle. &lt;br /&gt;
[[File:example.jpg|thumb|caption]]&lt;br /&gt;
[[File:example.jpg|thumb|caption]]&lt;br /&gt;
[[File:CANtext_Bundle.jpg|thumb|CANtext Bundle]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
== Used Hardware ==&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:CANtext_Bundle.jpg&amp;diff=6001</id>
		<title>File:CANtext Bundle.jpg</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:CANtext_Bundle.jpg&amp;diff=6001"/>
		<updated>2021-02-20T15:59:09Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6000</id>
		<title>Creating CAN-BUS Shield V2.0 Tutorial</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Creating_CAN-BUS_Shield_V2.0_Tutorial&amp;diff=6000"/>
		<updated>2021-02-20T15:58:05Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: Created page with &amp;quot;== Summary ==   This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which is able to read CAN messages from...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary == &lt;br /&gt;
&lt;br /&gt;
This documentation introduces the CAN-BUS Shield V2.0 and all its key facts. It also contains a example implementation, which is able to read CAN messages from a real car. &lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages: git emacs&lt;br /&gt;
&lt;br /&gt;
In order to complete these steps, you should have read this(https://wiki.elvis.science/index.php?title=Arduino_Board_Uno_Rev3-Atmega_328:_First_Steps) before.&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
In order to create a functioning CAN message reader we need to set up the lab, which consits of two CAN-BUS Shield V2.0 and two Arduino UNOs. The Arduinos will be used to simulate an ECU. After this works as planned we will take a step further and integrate the CANtext Bundle. &lt;br /&gt;
[[File:example.jpg|thumb|caption]]&lt;br /&gt;
[[File:example.jpg|thumb|caption]]&lt;br /&gt;
[[File:example.jpg|thumb|caption]]&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Step 1 ===&lt;br /&gt;
&lt;br /&gt;
Enter these commands in the shell&lt;br /&gt;
&lt;br /&gt;
 echo foo&lt;br /&gt;
 echo bar&lt;br /&gt;
&lt;br /&gt;
=== Step 2 ===&lt;br /&gt;
&lt;br /&gt;
Make sure to read&lt;br /&gt;
&lt;br /&gt;
* War and Peace&lt;br /&gt;
* Lord of the Rings&lt;br /&gt;
* The Baroque Cycle&lt;br /&gt;
&lt;br /&gt;
== Used Hardware ==&lt;br /&gt;
&lt;br /&gt;
[[Device to be used with this documentation]]&lt;br /&gt;
[[Maybe another device to be used with this documentation]]&lt;br /&gt;
&lt;br /&gt;
== Courses ==&lt;br /&gt;
&lt;br /&gt;
* [[A course where this documentation was used]] (2017, 2018)&lt;br /&gt;
* [[Another one]] (2018)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://wikipedia.org&lt;br /&gt;
* https://google.com&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=SQL_Injection&amp;diff=5859</id>
		<title>SQL Injection</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=SQL_Injection&amp;diff=5859"/>
		<updated>2021-01-21T09:40:33Z</updated>

		<summary type="html">&lt;p&gt;NStrasser: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQL Injection == &lt;br /&gt;
&lt;br /&gt;
SQL Injection is a vulnerability, which can be found in applications, especially web applications. According to the List of OWASP Top 10 Web Application Security Risks Injections are still on top in 2020. SQL Injections - which are a specific type of Injections - are the most common way for attackers to either fetch sensitive data from databases or harm a system in its dependability or even causing non-availablity of the same. Such vulnerabilities become possible when input data is concatenated to SQL queries in conjuction with the absence of data sanitation. &lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
This vulnerability can only arise when there is a lack of data sanitation. This implies the existence of data input interfaces, whether an input field or a HTTP header field. However when SQL is used in code at application layer it is often concatenated with input data from presentation layer. The combination of unsanitized input and SQL code concatenation with data input is very bad, because this leads to perfect SQL Injections. Input interfaces can be distinguished between: &lt;br /&gt;
&lt;br /&gt;
# Userinput can be every field in the User Interface (UI) where a user can input data. &lt;br /&gt;
# Cookies can be altered, because they reside on client-side which enables the user to inject malicious code into it.&lt;br /&gt;
# HTTP Header are also a type of input which can contain malicious SQL code.&lt;br /&gt;
&lt;br /&gt;
All these entities contain data which is created on the client-side and also can be altered on the same. This is why the first step when any of this data arrives on the server is sanitation and validation. The latter can be partly done already on client-side. Thus, defining HTML attributes, which force user to use specific type or validating with JS, which can be used to apply regular expressions (Regex) on inputs, is essential.&lt;br /&gt;
&lt;br /&gt;
=== Direct attack method ===&lt;br /&gt;
When input data, therefore malicious SQL code, is directly concatenated to the SQL code in the application tier it is called Direct attack method. This way an authentication of a web-page can be bypassed. &lt;br /&gt;
&lt;br /&gt;
=== Indirect attack method ===&lt;br /&gt;
In contrast to direct attack the indirect attack is when the SQL statement is terminated and arbitrary statements are attached to it. The end is then marked as a comment with using SQL specific commenting syntax, a double dash &#039;&#039;--&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Either way the malicious code is executed at the time it is received by the database. &lt;br /&gt;
&lt;br /&gt;
An attack could look like this:&lt;br /&gt;
&lt;br /&gt;
=== Case 1 ===&lt;br /&gt;
In the business logic of the application, a query is used to retrieve the data of an user based on username and password. The username and password are filled in by the user via a web form. The input goes directly into the query.&lt;br /&gt;
&lt;br /&gt;
 SELECT * FROM Users WHERE name =&#039;userName&#039; and password=&#039;password&#039;;&lt;br /&gt;
&lt;br /&gt;
Suppose the attacker gives admin as the username and &#039; or &#039;1&#039; = &#039;1&#039; as a password. That results in the following query that will be evaluated by the database:&lt;br /&gt;
 SELECT * FROM Users WHERE name =&#039;admin&#039; and password=&#039;&#039; or &#039;1&#039;=&#039;1&#039;;&lt;br /&gt;
&lt;br /&gt;
The above SQL query is valid and returns all tuples from the Users relation. By adding the OR condition &#039;1&#039; = &#039;1&#039;, the WHERE clause is always evaluated as true. The query then corresponds to:&lt;br /&gt;
 SELECT * FROM Users;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Case 2 ===&lt;br /&gt;
Furthermore, several SQL statements can be executed simultaneously on many database servers by separating them with semicolons. The attacker can thus insert additional commands, for example, to delete a relation with a call.&lt;br /&gt;
&lt;br /&gt;
The attacker enters the following in the password field:&lt;br /&gt;
 &lt;br /&gt;
 &#039; or &#039;1&#039;=&#039;1&#039;; DROP TABLE Users; SELECT * FROM info WHERE &#039;1&#039; = &#039;1&lt;br /&gt;
&lt;br /&gt;
This results in the following queries:&lt;br /&gt;
 SELECT * FROM Users WHERE name =&#039;admin&#039; and password=&#039; &#039;or &#039;1&#039;=&#039;1&#039;; DROP TABLE Users; SELECT * FROM info WHERE &#039;1&#039; = &#039;1&#039;&lt;br /&gt;
&lt;br /&gt;
When the database server processes these two queries, it first returns all data records from the Users relation and then deletes or removes the entire Users table.&lt;br /&gt;
&lt;br /&gt;
== Types of SQL queries ==&lt;br /&gt;
&lt;br /&gt;
There are a number of SQL injection attacks that occur in different situations.&lt;br /&gt;
Depending on the target of the attacker, the techniques can be used separately as well as together. &lt;br /&gt;
These are for example:&lt;br /&gt;
&lt;br /&gt;
=== Tautologies ===&lt;br /&gt;
The goal of the Tautologies attack is to find injectable parameters in the application to bypass authentication and initially extract data.&lt;br /&gt;
The basic idea here is to always set the where clause in the SQL statement to true so that the condition is ignored. The most common tautology is or 1 = 1. By concatenating the operator or and 1 = 1, another condition is set that is always true, so that the result of the entire condition is true. An example of this can be found in the previous chapter.&lt;br /&gt;
&lt;br /&gt;
=== Union Query ===&lt;br /&gt;
&lt;br /&gt;
In the case of a UNION query attack, the keyword &#039;UNION&#039; is inserted in the input in order to retrieve data from other relations in the database. UNION enables the execution of several independent SQL queries in addition to the main instruction. The results of the further queries are appended to the results of the legitimate SQL query.&lt;br /&gt;
&lt;br /&gt;
As a prerequisite, the attacker must have information about the database in order to extract data using UNION. These include e.g. Information about table names and their respective attributes, with which the further queries can be created and linked to the original statement. Furthermore, the individual queries must return the same number of columns and the data types of the attributes must be compatible between the individual queries.&lt;br /&gt;
The attacker can use the ORDER BY clause to derive the number of columns from the results. The clause is added to the statement and the column index is increased until an error message occurs. The columns in a relation can be specified in the ORDER BY clause by an index, so you do not need to know the column names.&lt;br /&gt;
&lt;br /&gt;
Example of a UNION query attack:&lt;br /&gt;
 SELECT accounts FROM Users WHERE username=&#039;&#039;username&#039;&#039; and password=&#039;&#039;password&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The attacker extends the legitimate instruction by entering the following in the password field:&lt;br /&gt;
&lt;br /&gt;
 &#039; &#039;UNION SELECT cardNo FROM Credit Cards WHERE acctNo=123456 -- &#039;,&lt;br /&gt;
&lt;br /&gt;
This results in the following query:&lt;br /&gt;
&lt;br /&gt;
SELECT accounts FROM users WHERE login=&#039; &#039; UNION SELECT cardNo from CreditCards&lt;br /&gt;
where acctNo=123456&lt;br /&gt;
&lt;br /&gt;
The first statement returns zero. However, the second query is performed and returns the card number from the account number 123456.&lt;br /&gt;
&lt;br /&gt;
=== SQL Blind SQL Injection ===&lt;br /&gt;
&lt;br /&gt;
Error messages provide the attacker with information on how he can continue his attack against the database. So it is usually a tool for attackers. With Blind SQl Injection, the attacker assumes that the error messages from the database are deactivated and still tries to executes the SQL injection.&lt;br /&gt;
 &lt;br /&gt;
It is assumed that a website retrieves its user data from the database using a UserId. The ID is transferred via the URL:&lt;br /&gt;
To check whether an SQL injection is possible, the following condition (and 1 = 2) is added.&lt;br /&gt;
&lt;br /&gt;
 http://newspaper.com/items.php?id=2 and 1=2&lt;br /&gt;
&lt;br /&gt;
The actual SQL query that is executed is:&lt;br /&gt;
&lt;br /&gt;
 SELECT title, description, body FROM items WHERE ID = 2 and 1=2&lt;br /&gt;
&lt;br /&gt;
In order for this assertion to be confirmed, the attacker builds a condition that returns true. This would be, for example, and 1 = 1, since 1 = 1 is always correct:&lt;br /&gt;
&lt;br /&gt;
 http://newspaper.com/items.php?id=2 and 1=1&lt;br /&gt;
&lt;br /&gt;
=== Procedure Stored procedure attacks ===&lt;br /&gt;
&lt;br /&gt;
The basic idea behind stored procedure attacks is to execute a stored database procedure. The attacker determines the database type and uses this knowledge to find out which procedures exist. The attacker first determines the database type and uses this knowledge to determine which stored procedures may exist. There appear to be several threats against which the database is vulnerable, such as the escalation of permissions, SQL injection buffer overflow and the gathering of extended information, since these are based on stored procedures. The following is a stored procedure that returns a description of its products using the buyer&#039;s first name.&lt;br /&gt;
&lt;br /&gt;
 CREATE PROCEDURE getDescription&lt;br /&gt;
 @vname VARCHAR(50)&lt;br /&gt;
 AS&lt;br /&gt;
 EXEC(&#039;SELECT description FROM products WHERE name = &lt;br /&gt;
 &#039;&#039;&#039;+@vname+ &#039;&#039;&#039;&#039;)&lt;br /&gt;
 RETURN&lt;br /&gt;
&lt;br /&gt;
Dabei wird der Vorname von dem/der KäuferIn eingegeben. Der Angreifer gibt jedoch statt dem Namen eine wahre Bedingung.&lt;br /&gt;
&lt;br /&gt;
 AND &#039;a&#039;=&#039;b&#039; UNION SELECT password FROM members WHERE &lt;br /&gt;
 username=&#039;admin&lt;br /&gt;
&lt;br /&gt;
Beim Ausführen der Bedingung ergibt sich die folgende Prozedur:&lt;br /&gt;
&lt;br /&gt;
 CREATE PROCEDURE getDescription&lt;br /&gt;
 @vname VARCHAR(50)&lt;br /&gt;
 AS&lt;br /&gt;
 EXEC(&#039;SELECT description FROM products WHERE name =&#039;z&#039; AND &lt;br /&gt;
 &#039;a&#039;=&#039;b&#039; UNION&lt;br /&gt;
 SELECT password FROM members WHERE username=&#039;admin&#039;&#039;)&lt;br /&gt;
 RETURN&lt;br /&gt;
&lt;br /&gt;
== Prevention ==&lt;br /&gt;
The countermeasures for SQL injection, apart from the type of attack, are mainly the same. The root cause of SQL injections is the lack of input validation. Therefore, the simple solution to address these vulnerabilities is to use appropriate defensive coding. If you are working with user input that is initially used in SQL queries, it should be passed to the query via parameters and validated using defined regular expressions, also known as input whitelisting.&lt;br /&gt;
&lt;br /&gt;
* Check the input type by parameterizing &lt;br /&gt;
* Positive pattern comparison&lt;br /&gt;
* Filter input data&lt;br /&gt;
* Avoid error messages&lt;br /&gt;
* Least privilege&lt;br /&gt;
&lt;br /&gt;
== Practice ==&lt;br /&gt;
&lt;br /&gt;
=== Damn Vulnerable Web App (DVWA) ===&lt;br /&gt;
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is damn vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, help web developers better understand the processes of securing web applications and aid teachers/students to teach/learn web application security in a class room environment.&lt;br /&gt;
&lt;br /&gt;
To Install the DvWA project follow the following page:&lt;br /&gt;
&lt;br /&gt;
* https://github.com/ethicalhack3r/DVWA&lt;br /&gt;
&lt;br /&gt;
Installation: &lt;br /&gt;
&lt;br /&gt;
=== Burp suite ===&lt;br /&gt;
Burp Suite is a tool for performing penetration testing of web applications. With the Burp Suite, administrators can intercept and manipulate HTTP / HTTPS traffic to web applications before it is sent to the server. This enables security gaps in web applications to be discovered quickly and effectively.&lt;br /&gt;
&lt;br /&gt;
To start intercepting web traffic, you have to set the proxy of the browser to 127.0.0.1:8080. The proxy listener is by default configured on 127.0.0.1:8080 in burp suite.&lt;br /&gt;
&lt;br /&gt;
[[File:Proxy 4.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the DVWA project move to &amp;quot;SQL Injection&amp;quot; and type in the following input as User ID:&lt;br /&gt;
&lt;br /&gt;
 1&#039; or 1=1&lt;br /&gt;
&lt;br /&gt;
This will deliver all users stored in the database as the condition is always true.&lt;br /&gt;
&lt;br /&gt;
[[File:demo2.png]] &lt;br /&gt;
&lt;br /&gt;
Afterwards when switching to burp suite tab &amp;quot;Proxy&amp;quot; -&amp;gt; History you will see that the request has been captured. Within the request the &amp;quot;PHPSESSID&amp;quot; will be included as part of the cookie. &lt;br /&gt;
&lt;br /&gt;
[[File:demo3.png]] &lt;br /&gt;
&lt;br /&gt;
With this sessionid it is possible to connect to database and get further information with the help of a third tool called &amp;quot;sqlmap&amp;quot;. To get the databases within DBMS system use the following command:&lt;br /&gt;
&lt;br /&gt;
 sqlmap -u &amp;quot;http://localhost/DVWA/vulnerabilities/sqli/?id=1&amp;amp;Submit=Submit&amp;quot; &amp;quot;--cookie=security=&amp;lt;e.g. medium&amp;gt;; PHPSESSID=&amp;lt;SessionID&amp;gt;&amp;quot; --dbs&lt;br /&gt;
&lt;br /&gt;
[[File:demo4.png]]&lt;br /&gt;
&lt;br /&gt;
To retrieve the tables of a specific database for example dvwa database. Replace the &amp;quot;--dbs&amp;quot; option with the &amp;quot;--tables&amp;quot; and &amp;quot;-D&amp;quot; option and define the database.&lt;br /&gt;
&lt;br /&gt;
 sqlmap -u &amp;quot;http://localhost/DVWA/vulnerabilities/sqli/?id=1&amp;amp;Submit=Submit&amp;quot; &amp;quot;--cookie=security=low; PHPSESSID=t664gnfopfo6kem1nkon3a6kvb&amp;quot; --tables -D dvwa&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:demo5.png]]&lt;br /&gt;
&lt;br /&gt;
Furthermore, it is possible to see the database schema from database &amp;quot;dvwa&amp;quot; as well by executing the following command:&lt;br /&gt;
&lt;br /&gt;
 sqlmap -u &amp;quot;http://localhost/DVWA/vulnerabilities/sqli/?id=1&amp;amp;Submit=Submit&amp;quot; &amp;quot;--cookie=security=low; PHPSESSID=t664gnfopfo6kem1nkon3a6kvb&amp;quot; --columns -D dvwa -T users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:demo6.png]]&lt;br /&gt;
&lt;br /&gt;
At the end to get to the sensitive data the attacker will execute the command:&lt;br /&gt;
 &lt;br /&gt;
 sqlmap -u &amp;quot;http://localhost/DVWA/vulnerabilities/sqli/?id=1&amp;amp;Submit=Submit&amp;quot; &amp;quot;--cookie=security=low; PHPSESSID=t664gnfopfo6kem1nkon3a6kvb&amp;quot; --dump -D dvwa -T users&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:demo7.png]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* https://ieeexplore.ieee.org/document/6400112&lt;br /&gt;
* https://pdfs.semanticscholar.org/81a5/02b52485e52713ccab6d260f15871c2acdcb.pdf/&lt;br /&gt;
* https://ieeexplore.ieee.org/abstract/document/6396096&lt;br /&gt;
* https://www.dbcybertech.com/pdf/sql-injection-detection-web-environment.pdf&lt;br /&gt;
* https://www.cisecurity.org/wp-content/uploads/2017/05/SQL-Injection-White-Paper2.pdf&lt;br /&gt;
* https://info.sucuri.net/hubfs/images/owasp-ebook-2019/sucuri-ebook-OWASP-top-10.pdf&lt;br /&gt;
* http://www.dvwa.co.uk/&lt;br /&gt;
* https://owasp.org/www-project-top-ten/&lt;br /&gt;
&lt;br /&gt;
[[Category:Basic]]&lt;/div&gt;</summary>
		<author><name>NStrasser</name></author>
	</entry>
</feed>