Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use CAN Bus Shield: Examples, Pinouts, and Specs

Image of CAN Bus ShieldDesign with CAN Bus Shield in Cirkit Designer

Introduction

The CAN Bus Shield by SEEED is an expansion board designed to enable Arduino boards to communicate over a Controller Area Network (CAN). This shield is particularly useful for automotive and industrial applications where multiple microcontrollers need to communicate with each other efficiently without a host computer.

Common applications include:

Explore Projects Built with CAN Bus Shield

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Arduino Sensor Shield with I2C LCD and Bluetooth Interface: A project utilizing CAN Bus Shield in a practical application
Arduino Sensor Shield with I2C LCD and Bluetooth Interface

This circuit features an Arduino Sensor Shield v5.0 interfaced with an I2C LCD Display and an HC-05 Bluetooth Module. The LCD Display is connected for power, ground, and I2C communication, allowing it to display data or messages. The HC-05 Bluetooth Module is wired for serial communication with the Arduino Sensor Shield, enabling wireless data exchange with other Bluetooth-enabled devices.

Open Project in Cirkit Designer

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

Pin Number Function Description
D2 INT Interrupt pin, signals the Arduino of incoming messages
D9 CS Chip Select for SPI communication with MCP2515
D10 Not Connected Reserved for future use
D11 MOSI SPI communication with MCP2515
D12 MISO SPI communication with MCP2515
D13 SCK SPI Clock
GND Ground Ground connection
VCC Power Supply 5V power supply from the Arduino

Usage Instructions

Connecting the Shield to an Arduino

  1. Power off your Arduino board.
  2. Align the shield's pins with the corresponding headers on the Arduino.
  3. Gently press down until the shield is firmly seated on the Arduino.

Initializing the CAN Bus Shield

Before using the shield, you need to initialize the CAN controller and set the desired baud rate for communication. Here's an example of how to do this using the MCP_CAN library:

#include <mcp_can.h>
#include <SPI.h>

// The SPI Chip Select pin for the CAN controller
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN); // Set CS pin for CAN controller

void setup() {
  Serial.begin(115200);

  // Initialize CAN bus at 500 kbps
  if (CAN_OK == CAN.begin(CAN_500KBPS)) {
    Serial.println("CAN Bus Shield initialized at 500 kbps.");
  } else {
    Serial.println("CAN Bus Shield initialization failed.");
  }
}

void loop() {
  // Code to send and receive data goes here
}

Sending CAN Messages

To send data over the CAN bus, you can use the sendMsgBuf function provided by the MCP_CAN library:

unsigned char message[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};

// Send a standard frame with ID 0x100 and length of 8 bytes
CAN.sendMsgBuf(0x100, 0, 8, message);

Receiving CAN Messages

To receive data, you can use the readMsgBuf and checkReceive functions:

unsigned char len = 0;
unsigned char buf[8];

if (CAN_MSGAVAIL == CAN.checkReceive()) {
  CAN.readMsgBuf(&len, buf); // Read data: len = data length, buf = data byte(s)
  unsigned long canId = CAN.getCanId();

  Serial.print("Message received with ID: ");
  Serial.print(canId, HEX);
  Serial.print(" Data: ");
  for (int i = 0; i < len; i++) {
    Serial.print(buf[i], HEX);
    Serial.print(" ");
  }
  Serial.println();
}

Best Practices

Troubleshooting and FAQs

Common Issues

Solutions and Tips

FAQs

Q: Can I use multiple CAN Bus Shields on the same network? A: Yes, you can use multiple shields on the same CAN network, but each device must have a unique ID.

Q: What is the maximum length of the CAN bus? A: The maximum length depends on the baud rate; for example, at 500 kbps, the maximum length is typically around 100 meters.

Q: How do I know if my CAN Bus Shield is working? A: You can test the shield by sending messages and checking if they are received by another CAN device. The onboard LED indicators can also provide a visual indication of activity.

For further assistance, consult the SEEED forums or contact technical support.