CAN Bus - AlandSailingRobots/sailingrobot GitHub Wiki

Overview

CAN Bus (Control Area Network Bus) is a vehicle bus using a message based protocol which allows multiple nodes to transmit and receive prioritized messages universally and asynchronously across the same bus.

In this project the CAN Bus is the communication link between the 5V box and the 12V box as well as the communication connection to the AIS, sail winch and wind vane encoder. In each box there is an Arduino Mega 2560 connected to the bus which may send and receive, forming the link between the two and connecting both ends to all other devices on the bus.

Setting Up

Setting Up the Bus

Cable Bus

For practical use, an NMEA2000 cable network is used as indicated below. TODO:Image

Ensure that the terminal resistors marked in the image are connected.

Breadboard Bus

For debugging, it may sometimes be quicker or easier to use a breadboard bus to connect only the devices needed and check wire voltages. To set up a breadboard bus follow the schematic below. TODO:Schematic

Setting Up an Arduino Mega for a CAN Bus

In order to connect an Arduino to a CAN Bus we use a CAN Bus shield from Sparkfun. The only pins necessary to establish the connection for both ends are listed below.

CAN Bus Shield Arduino Mega
GND GND
+3.3V +3.3V
RST RESET
2 2
10 53
11 51
12 50
13 52

The shield uses a library found here which has modifications specific to this project. The modified library is found in our git repository.

Connecting an Arduino Mega to a CAN Bus

The shield may be connected in two ways, via the DB9 connector and via the direct pins. The DB9 connection is more appropriate for connecting to a sealed cable bus and for practical use. The direct pins are more appropriate for connecting to an breadboard wire bus for debugging.

Using the DB9 Connector

The DB9 connection requires a (TODO: male/female) cable. In order to use this connection, the three solder jumpers marked in the reference image must be set to CAN. They are shipped with OBD11 as the default so this involves carefully cutting the connection between the centre pad and the left hand OBD11 pad before using a small amount of solder to bridge the centre pad with the right hand OBD11 pad.

With this set up, the following pins correspond to the following signals on the shield DB9 pins.

Pin Signal
7 CAN_HI
2 CAN_LO
3 GND
# 5V

Using the Direct Pins

The CAN_HI, CAN_LO, GND and 5V signals can be accessed directly from the board as indicated in the image. The direct pins are marked in the reference image. It is important to ensure that the GND signal on the shield is connected to a common ground shared by all devices connected to the bus. The 5V signal is not necessary and may be left disconnected. The CAN HI and LO signals are simply connected to their corresponding rails on the breadboard bus.

CAN Bus Arduino Library (mcp_can.h)

CAN Bus Devices

Links