Sparkfun CAN Bus Shield Tutorial

Receive and transmit messages using Sparkfun CAN Bus Shield

What is CAN?

The CAN bus was developed by BOSCH as a multi-master, message broadcast system that specifies a
maximum signaling rate of 1 megabit per second (bps). Unlike a traditional network such as USB or Ethernet, CAN does not send large blocks of data point-to-point from node A to node B under the supervision of a central bus master. In a CAN network, many short messages like temperature or RPM are broadcast to the entire network, which provides for data consistency in every node of the system.

Step 1: Materials Needed

2 - Sparkfun CAN Bus Shield

2 - Arduino UNO

2 - 120 ohm resistors

1 - Breadboard

Jumper Wires

CAN Bus Shield Library Download:

https://drive.google.com/open?id=1Mnf2PN_fAQFpo1ID...

Advanced (CAN Bus):

DB9 (Female)

RJ45

UTP Cable

RJ45 2-Way Splitter

RJ45 Straight Connector

Tools:

Screwdriver

RJ45 Crimper

Soldering Iron

Step 2: Building CAN Bus on Breadboard

1. Mount CAN Bus Shield to one Arduino each

2. Wire CAN_H and CAN_L pins of the shield to the breadboard

3. Connect the 120-ohm terminating resistors across each end of the CAN_H and CAN_L lines

Step 3: Arduino Programming

1. Download and install the CAN Bus Shield Library from the link given above

Configure 1st Arduino to Read CAN messages

2. Open Arduino IDE

3. Go to File --> Examples --> SparkFun CAN-Bus --> CAN_Read_Demo

4. Select the appropriate Port of the First Arduino and Upload

Configure 2nd Arduino to Send CAN messages

5. Open a new Arduino IDE

6. Go to File --> Examples --> SparkFun CAN-Bus --> CAN_Write_Demo

7. Select the appropriate Port of the Second Arduino and Upload

Step 4: Testing

/*Add pictures of working example*/

After uploading the program to the two Arduinos...

1. Open the Serial Monitors of the First and Second Arduino

2. Set the Baud Rate to 9600

3. Check if Data is received by the First Arduino

If no data is received:

1. Check if the appropriate Port and Baud Rate is selected for each Arduino

2. Check the connections of the CAN_H and CAN_L lines

3. Check the connections of the terminating resistors

Step 5: Explore

Create custom CAN messages

Edit the CAN_Write_Demo Program to...

  • change the message ID (message.id)
  • change RTR bit (message.header.rtr)
  • set the data length (message.header.length)
  • input your own data (message.data[x])

Edit the CAN_Read_Demo to customize how you print your data

  • Print the message ID (message.id)
  • Print the message length (message.header.length)
  • Print the message Data (message.data[x])

Step 6: (Additional) Create CAN Bus Using UTP

The CAN Bus used in this diagram is a 8-pin UTP cable.

There are two types of connectors in this diagram namely the (DB9 - to - RJ45) and (RJ45 - to - RJ45)

DB9 - to - RJ45

DB9 (pins 1- 8) = wO, O, wG, Bl, wBl, G, wBr, Br

RJ45 (pins 1-8) = wO, O, wG, Bl, wBl, G, wBr, Br

RJ45 - to - RJ45 (Straight Through)

RJ45 (pins 1-8) = wO, O, wG, Bl, wBl, G, wBr, Br

RJ45 (pins 1-8) = wO, O, wG, Bl, wBl, G, wBr, Br

RJ45 - to - Terminator

RJ45 (pins 1-8) = wO, O, wG, Bl, wBl, G, wBr, Br

Terminator Resistor (wG, wBl)

The nodes can be connected to the CAN Bus according to your preference and the number of nodes used

For a two-node connection, an RJ45 Straight connector is used between the (DB9 - to - RJ45) Cables

For a 3-node connection, a 2-Way splitter coupled is coupled with a straight connector to make a "T" connection between all (DB9 - to - RJ45) Cables

For the 2+ node connection (2 or more nodes), a 2-Way splitter is coupled with a straight connector to make a "T" connection. An (RJ45 - to - RJ45) Cable is used to connect two "T" nodes and a (DB9 - to - RJ45) Cable is used to connect the "T" node to the CAN Bus Shield. A RJ45 - to - Terminator was used at each "T" end of the CAN Bus

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Plastics Contest

      Plastics Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018

    3 Discussions

    0
    None
    AlexT162

    6 months ago

    I am having issues, where the Arduino will successfully init CAN and send 3 messages, but then will stop sending messages. Any idea what might be wrong? Does the code expect messages back?

    Update: My CAN reader is saying that the CAN controller is in bus-off state...

    0
    None
    DIY Hacks and How Tos

    8 months ago

    Great first Instructable. Thanks for sharing with the community.