What is CANBed?CANBed (CAN Bus development board) is an Arduino CAN-Bus development kit containing the following:
- Atmega32U4 chip
The Atmega32U4 chipSource: Wikimedia Commons
- MCP2515 CAN Bus controller
A CAN controller module Source: Clip Art
- MCP2551 CAN Bus receiver
A CAN Bus topologySource: Wikimedia Commons
CANBed v1 PinoutThe CANBed v1 has several connector ports split into the following parts.
18-pin Header with GPIO InterfacesThese include:
- An I2C interface (SCL and SDA) that doubles up as two digital pins
- A UART interface (Rx and Tx) that also doubles up as two digital pins
- Four analog inputs (you can use these for digital I/O)
- Eight digital I/O pins
- Vin (5V)
Micro USB Connector for ProgrammingIf programming via the Arduino IDE, connect this port to a computer via a micro USB cable.
SPI - ICSP ConnectorIf you prefer to program the CANBed using AVR studio, connect the ICSP connector to the SPI port. It is also the ideal port for uploading the bootloader.
CAN RX/TX IndicatorThese LEDs blink when the CAN Bus transmits data.
9-Pin Sub-D Connector (DB9 Connector)The sub-D connector is the CAN Bus terminal. This 9-pin CAN standard pinout contains the following.
Switch for the 120Ω terminal resistor for CAN BusSolder a 120Ω resistor if using the dev kit on the CAN Bus end.
Grove connector for UARTUse Serial1 when coding to access this port. There is also a grove connector for I2C.
ResetThis port resets the onboard Atmega chip.
Features and Specifications
- Arduino development board and CAN Bus shield in one
- Up to 1Mbps CAN V2.0B implementation
- Adopts the MCP2515 CAN Bus controller with an SPI interface
- 4-pin terminal or 9-pin industrial standard sub-D connector
- 18-pin header with analog & digital pins and UART & I2C interfaces
- CAN and OBD-II standard pinout selectable at the sub-D connector
- Two 4-pin grove system compatible connectors
- Up to 10MHz SPI interface
- 11-bit standard and 29-bit extended data and remote frames
- It does not require any other MCU for control
- Arduino IDE compatible
- 9-28V power input
CANBed Application Ideas
- Learning CAN Bus communication
- Building product prototypes
- Read data from cars (car hack and upgrade)
- Build vehicle dynamics control system
- Develop attitude and orbit control system
- CAN Bus and MCU for other products
How to Get Started With a CAN Bed?We will use Arduino for this demonstration, and here's how you get started with the development board.
Arduino IDE SetupDownload and install the latest Arduino IDE version. You'll find the Arduino Leonardo driver in the "Arduino/drivers" folder.
Download and Install the LibraryAfter downloading the IDE, download the CAN Bed Arduino library and import it into the IDE.
Open the Code and Upload it to the Board. Open the library example named "Send" in the IDE, which should look like the code below. This code sends data continuously to the CAN Bus. But before uploading, select Arduino Leonardo on the IDE boards. After that, pick the correct COM port, then upload the code.
Arduino CodeBesides the example above, the library contains Arduino code for receiving a frame (with and without mask & filter settings). There's also a sample code for reading data from a car's OBD-II port. Here is a sample code to get a vehicle's speed and engine revs. You need to have an understanding of a car's OBD technology and the interface. Usually, it has 16 pins, but we only want pins 5, 6, 14, and 16. Connect them as shown below.
OBD connector pins. Note the pin numbersSource: Free SVG Alternatively, you can use a DB9 to OBD-II cable, which is more convenient. After that, open the sample code and upload it to the CANBed.
A female OBD-II connector in a vehicleSource: Wikimedia Commons Please note that you should change the SPI_CS_PIN to 17 in the code for it to work with CAN Bed v1.
APIsThere are six APIs you can use to access the CAN Bed. They include the following.
Set the Baud RateYou can set the baud rate to any of the following 18 figures.
Receive Mask and Filter SettingThe controller chip contains two receive mask registers and five filter registers for getting data from the device. These come in handy in a broad network containing several nodes, and there are two functions to utilize them. For the mask, use For the filter, use
- num shows which register to use (0 or 1 for the mask and 0-5 for the filter).
- ext shows the frame status. 0 implies a standard frame for the mask or filter, while 1 indicates an extended frame.
- ulData represents the content in the mask or filter.
Check ReceiveA CAN Bus controller (MCP2515) can operate in a polled mode or by using extra pins to indicate signal reception or transmission completion. The following function polls for received frames and returns 0 if nothing arrives and 1 if a frame arrives.
Get CAN IDThe following function gets the CAN ID of the "send" node when data arrives.
Send a FrameUse the function below to send data to the bus.
- id is the frame's ID
- ext is the frame's status (0-standard frame, 1-extended frame)
- len shows the frame length
- data_buf is the message content
Receive a FrameThe last API is a function for receiving data on the "receive" node.
- len shows the data length
- buf is the data storage location