CANBED V1
Introduction¶
CANBed V1 is a development board for the CAN Bus protocol with an Atmega32U4 microcontroller at its core. It has 32KB of flash memory and 2.5KB of RAM, with an operating frequency of 16 MHz, making it suitable for most embedded applications. It also has an Arduino Leonardo bootloader pre-installed on the Atmega32U4, allowing users familiar with the Arduino Integrated Development Environment (IDE) to easily program the board. In addition to the Arduino IDE, the board can also be programmed using AVR Studio, and an ICSP interface is provided for this purpose.
CANBed V1 uses the MCP2515 as its CAN controller and the MCP2551 as its CAN receiver, both of which are high-performance chips that support the CAN 2.0 protocol. The board has a Micro USB connector that can be used for programming and power supply. It also has an I2C interface, a UART interface, an SPI interface, 3 analog input interfaces, and 8 digital I/O interfaces.
The CAN interface on the board is flexible and can be connected using either a 4-pin terminal or a DB9 connector. The DB9 connector is set to OBD-II mode by default, but can also be configured for CAN Open mode through hardware. The input voltage range for the CAN interface is 9-28V and it can provide a stable 5V/1A output.
If you want to use CANBed V1 to develop applications related to the OBD system, you can purchase a DB9 to OBD-II cable here.
Note
- The components in the kit are not soldered by default due to transportation considerations. After receiving the kit, you will need to do some soldering. If you prefer, you can contact info@longan-labs.cc after purchasing the board to request that it be soldered before being shipped to you.
- The price of chips may change frequently in the coming year, leading to modifications of the product, including the package of Atmega32U4 and the power chip. These changes will not affect the performance of the circuit board, and it can be used with confidence.
Version Track¶
V1.1:
- Changed the package of Atmega32U4 from MU to AU
- Changed the package of the 16 MHz crystal from SMD5032 to DIP
V1.2:
- Changed the package of Atmega32U4 from AU to MU
- Changed the package of the 16 MHz crystal from DIP to SMD3215
V1.2c:
- Atmega32U4 is available in two packages, AU and MU, which are used selectively during production. You may receive either the AU or MU version. The only difference is the package of Atmega32U4, and both versions have the same functions and performance.
V1.2d:
- Changed the DCDC chip to SCT2330
V1.2e:
- Changed the DCDC chip to TPS54202(or TPS54202)
Possible Applications¶
CANBed dev board can be used for the following purposes:
- Learning about CAN Bus communication
- Building product prototypes, and integrating the completed prototype into a final product with assistance from the manufacturer
- Reading data from a car's systems
- Incorporating into a final product as a complete MCU and CAN Bus solution, requiring only external hardware design.
CANBed Family¶
There are currently six different versions of CANBed available, each with different features and capabilities. You can choose the one that best suits your needs from the following options:
VRESION | CANBed V1 | CANBed FD | CANBed M0 | CANBed M4 | CANBed RP2040 | CANBed Dual |
---|---|---|---|---|---|---|
MCU | Atmega32U4 | Atmega32U4 | ATSAMD21G18 | ATSAME51G19A | RP2040 | RP2040 |
CORE | AVR 8 bit | AVR 8 bit | ARM Cortex M0+ 32bit | ARM Cortex M4 32bit | Dual ARM Cortex-M0+ | Dual ARM Cortex-M0+ |
PROTOCOL | CAN2.0 | CANFD & CAN2.0 | CAN2.0 | CANFD & CAN2.0 | CAN2.0 | CANFD & CAN2.0 |
CLOCK | 16MHz | 16MHz | 48MHz | 133MHz | 133MHz | 133MHz |
FLASH | 32KB | 32KB | 256KB | 2MKB | 2MKB | 2MKB |
RAM | 2.5KB | 2.5KB | 32KB | 192KB | 264KB | 264KB |
PRICE | $24.9 | $29.9 | EoL | $49.9 | $15.9 | $24.9 |
LINK | GET ONE | GET ONE | GET ONE | GET ONE | GET ONE | GET ONE |
Note
The prices listed above may not be the most recent and should be checked on the product page for accuracy.
CAN BUS PRODUCTS LIST OF LONGAN LABS¶
We offer a range of CAN Bus products that may be suitable for your needs. You can find more information about these products in the list below and choose the one that best meets your requirements.
PRODUCT NAME | LINK | PRICE | MCU | CHIP | PROTOCOL |
---|---|---|---|---|---|
Serial CAN Bus Module | LINK | $19.9 | ATMEGA168PA | MCP2515 | CAN2.0 |
I2C CAN Bus Module | LINK | $19.9 | ATMEGA168PA | MCP2515 | CAN2.0 |
OBD-II Serial CAN Bus Dev Kit | LINK | $20.9 | ATMEGA168PA | MCP2515 | CAN2.0 |
OBD-II CAN Bus GPS Dev Kit | LINK | $29.9 | ATMEGA32U4 | MCP2515 | CAN2.0 |
OBD-II CAN Bus Basic Dev Kit | LINK | $24.9 | ATMEGA32U4 | MCP2515 | CAN2.0 |
CAN-FD Shield | LINK | $19.9 | NO MCU | MCP2517FD | CAN-FD |
CAN Bus Shield | LINK | $9.9 | NO MCU | MCP2515 | CAN2.0 |
CANBed | LINK | $24.9 | ATMEGA32U4 | MCP2515 | CAN2.0 |
CANBed-FD | LINK | $29.9 | ATMEGA32U4 | MCP2517FD | CAN-FD |
CANBed M4 | LINK | $49.9 | ATSAME51 | - | CAN-FD |
OBD-II RF Dev Kit | LINK | $19.9 | ATmega168PA | MCP2515 | CAN2.0 |
Note
The prices listed above may not be the most recent and should be checked on the product page for accuracy.
Features¶
- Supports CAN V2.0B at speeds up to 1 Mb/s
- Industrial standard 9-pin sub-D connector or 4-pin terminal available
- OBD-II and CAN standard pinouts can be selected through the sub-D connector
- 2x4-pin connector compatible with the Grove system from Seeedstudio
- SPI interface with speeds up to 10 MHz
- Supports standard (11 bit) and extended (29 bit) data and remote frames
- Power input range of 9-28V
Specifications¶
Parameter | Value |
---|---|
MCU | Atmega32U4 (with Arduino Leonardo bootloader) |
Clock Speed | 16MHz |
Flash Memory | 32KB |
SRAM | 2.5KB |
EERROM | 1KB |
Operate Voltage | 9-28V |
Output Current @ 5V | 1A |
Input Interface | sub-D |
Hardware Overview¶
Part List¶
Note
For transportation purposes, the plug-in components of the kit are not soldered by default. You will need to perform some soldering work after receiving the kit. If you require soldered components, you can contact info@longan-labs.cc after purchasing the board and request that it be sent to you after soldering is completed.
- CANBed PCBA
- sub-D connector
- 4PIN Terminal
- 4PIN HY2.0 Connector x 2
- 9x2 2.54 Header x 1
- 3x3 2.54 Header x 1
- Switch for 120Ω terminal resistor
Pin out¶
Note
Click to get larger image.
1. GPIO - 9x2 I/O Pin OUT:
The I/O of Atmega32U4 is list out here, which is consist of,
- 1 x UART (Serial1)
- 1 x I2C
- 4 x Analog Input(can be used us Digital IO)
- 8 x Digital I/O
2. Micro USB connector for programming
If you use Arduino IDE program the board, you need a micro USB cable to connect the board to PC.
3. SPI - ICSP connector
If you use AVR Studio to program the board, you can use this ICSP connector, and it can be used as SPI interface.
4. CAN RX/TX Indicator
When CAN Bus is transmitting data, these two leds blink.
5. DB9 connector or Terminal for CAN Bus
6. Switch for the 120Ω terminal resistor for CAN Bus
If you use this board on the end of the CAN bus, please put this switch to 120Ω. For more detail about the CAN bus protocol, please refer to the NI CAN Physical Layer and Termination Guide
7. Grove connector for UART
Use Serial1 in the code
8.Grove connector for I2C
9. Reset
Click to reset the board.
DB9 connector¶
OBD (On-Board Diagnostics) is a system used in vehicles to diagnose and report on the performance of various components and systems. It consists of a standard set of diagnostic connectors and protocols that allow a mechanic or diagnostic tool to communicate with the vehicle's computer systems and retrieve diagnostic information.
CAN Open is a higher-layer protocol built on top of the CAN (Controller Area Network) protocol, which is a communication protocol used in vehicles to allow different electronic systems to communicate with each other. CAN Open is used in a variety of applications, including industrial automation, building automation, and medical equipment. It is defined by the CiA (CAN in Automation) organization and is used to define a standardized way for devices to communicate with each other over a CAN network.
pin# | OBD(default) | CAN OPEN |
---|---|---|
1 | GND | N.C |
2 | GND | CAN_L |
3 | CANH | GND |
4 | N.C | N.C |
5 | CANL | GND |
6 | N.C | N.C |
7 | N.C | CAN_H |
8 | N.C | N.C |
9 | CAN_V+ | CAN_V+ |
If you want to use the OBD protocol, you don't need to make any changes to the hardware.
If you need to use the CAN Open protocol, take a look at the back side of the PCB board. You will see the pads below:
Note
The picture shows another board, but the operation method is the same.
By default, these pads are connected to the OBD side. To use the CAN Open protocol, use a knife to carefully disconnect the OBD side and then use an electric soldering iron to solder the CAN Open side of the pads.
Getting Started¶
In this section, we will demonstrate how to get started with CANBed using the Arduino IDE. You will need a micro USB cable to connect the CANBed development board to your computer.
IDE and Driver¶
There is an Arduino Leonardo bootloader on the board.
To get the latest Arduino IDE, click here.
The Arduino Leonardo driver can be found in the folder: Arduino/drivers.
Download the install the library¶
Click to get the Arduino Library for CANBed Dev board.
In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library to install the Library.
Open the code and upload it to the board¶
Open the Arduino IDE, here we open the send example. This example can continuously send data to the CAN Bus.
#include <mcp_can.h>
#include <SPI.h>
const int SPI_CS_PIN = 17; // CANBed V1
// const int SPI_CS_PIN = 3; // CANBed M0
// const int SPI_CS_PIN = 9; // CAN Bus Shield
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
while(!Serial);
// below code need for OBD-II GPS Dev Kit
// pinMode(A3, OUTPUT);
// digitalWrite(A3, HIGH);
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS FAIL!");
delay(100);
}
Serial.println("CAN BUS OK!");
}
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(100); // send data per 100ms
}
// END FILE
You need to select Arduino Leonardo on the Arduino IDE boards and select the correct COM port. Then you can upload the program to the CANBed Dev board by pressing the Upolading button on Arduino IDE.
Get data from a Vehicle¶
We can use CANBed to get data from a vehicle, we take the vehicle speed for an example here.
You can use our products to read data from cars. Here we provide a simple example by which you can read the speed and revs from a car. This is the OBD-based PIDs protocol. Regarding the deeper technology of OBD, we can't provide support at present. You may need to have some understanding of the car's protocol. After all, we are more of a hardware supplier.
Using CANBed, you can retrieve data from a vehicle. For example, you can read the speed and revs of a car using our products and the OBD-based PIDs protocol. While we can provide hardware support, we are unable to offer support for the deeper technology of OBD at this time. It is recommended to have some understanding of the car's protocol before attempting to retrieve data.
The interface of OBD is as follows,
There're 4 pins we need to connect.
OBD Pin | CANBed PIN |
---|---|
5. Signal Ground | GND |
6. CAN(J-2234) High | CANH |
14. CAN(J-2234) Low | CANL |
16. Battery Power | VIN |
You can also use our OBD-II to DB9 Cable, which is very convenient to connect to OBD.
To retrieve the speed from a car using the development board, upload the following code and open the serial monitor.
#include <SPI.h>
#include "mcp_can.h"
/* Please modify SPI_CS_PIN to adapt to different baords.
CANBed V1 - 17
CANBed M0 - 3
CAN Bus Shield - 9
CANBed 2040 - 9
CANBed Dual - 9
OBD-2G Dev Kit - 9
Hud Dev Kit - 9
*/
#define SPI_CS_PIN 17
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
#define PID_ENGIN_PRM 0x0C
#define PID_VEHICLE_SPEED 0x0D
#define PID_COOLANT_TEMP 0x05
#define CAN_ID_PID 0x7DF
void set_mask_filt()
{
// set mask, set both the mask to 0x3ff
CAN.init_Mask(0, 0, 0x7FC);
CAN.init_Mask(1, 0, 0x7FC);
// set filter, we can receive id from 0x04 ~ 0x09
CAN.init_Filt(0, 0, 0x7E8);
CAN.init_Filt(1, 0, 0x7E8);
CAN.init_Filt(2, 0, 0x7E8);
CAN.init_Filt(3, 0, 0x7E8);
CAN.init_Filt(4, 0, 0x7E8);
CAN.init_Filt(5, 0, 0x7E8);
}
void sendPid(unsigned char __pid) {
unsigned char tmp[8] = {0x02, 0x01, __pid, 0, 0, 0, 0, 0};
CAN.sendMsgBuf(CAN_ID_PID, 0, 8, tmp);
}
bool getSpeed(int *s)
{
sendPid(PID_VEHICLE_SPEED);
unsigned long __timeout = millis();
while(millis()-__timeout < 1000) // 1s time out
{
unsigned char len = 0;
unsigned char buf[8];
if (CAN_MSGAVAIL == CAN.checkReceive()) { // check if get data
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
if(buf[1] == 0x41)
{
*s = buf[3];
return 1;
}
}
}
return 0;
}
void setup() {
Serial.begin(115200);
while(!Serial);
// below code need for OBD-II GPS Dev Kit
// pinMode(A3, OUTPUT);
// digitalWrite(A3, HIGH);
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
Serial.println("CAN init fail, retry...");
delay(100);
}
Serial.println("CAN init ok!");
set_mask_filt();
}
void loop() {
int __speed = 0;
int ret = getSpeed(&__speed);
if(ret)
{
Serial.print("Vehicle Speed: ");
Serial.print(__speed);
Serial.println(" kmh");
}
delay(500);
}
// END FILE
To retrieve other data using PIDs, you can refer to the example provided and to this link.
Arduino Code¶
We provide an Arduino library for CANBed.
Note
Please change the SPI_CS_PIN to 17 for CANBed V1
The library includes several examples, including:
- OBDII-PIDs - retrieve data from the OBD-II interface
- send - send a frame to the CAN bus
- recv - receive a frame from the CAN bus
- set_mask_filter_recv - receive a frame from the CAN bus with mask and filter settings
APIs¶
1. Set the Baud rate¶
This function is used to initialize the baud rate of the CAN Bus system.
The available baud rates are listed as follows:
#define CAN_5KBPS 1
#define CAN_10KBPS 2
#define CAN_20KBPS 3
#define CAN_25KBPS 4
#define CAN_31K25BPS 5
#define CAN_33KBPS 6
#define CAN_40KBPS 7
#define CAN_50KBPS 8
#define CAN_80KBPS 9
#define CAN_83K3BPS 10
#define CAN_95KBPS 11
#define CAN_100KBPS 12
#define CAN_125KBPS 13
#define CAN_200KBPS 14
#define CAN_250KBPS 15
#define CAN_500KBPS 16
#define CAN_666kbps 17
#define CAN_1000KBPS 18
2. Set Receive Mask and Filter¶
The controller chip has 2 receive mask registers and 5 filter registers that can be used to ensure that data is received from the targeted device. These registers are particularly useful in large networks with many nodes. We have provided two functions that allow you to utilize these mask and filter registers.
Mask:
init_Mask(unsigned char num, unsigned char ext, unsigned char ulData);
Filter:
init_Filt(unsigned char num, unsigned char ext, unsigned char ulData);
- num represents which register to use. You can fill 0 or 1 for mask and 0 to 5 for filter.
- ext represents the status of the frame. 0 means it's a mask or filter for a standard frame. 1 means it's for a extended frame.
- ulData represents the content of the mask of filter.
3. Check Receive¶
The MCP2515 controller chip has the ability to operate in either a polled mode or an interrupt mode. In polled mode, the software regularly checks for a received frame. In interrupt mode, additional pins can be used to signal that a frame has been received or transmit has completed. This allows for more efficient use of resources as the processor does not need to constantly check for incoming data.
This function is used to check if there are any received frames waiting in the receive buffer. If there are, the function will return true, otherwise it will return false. You can use this function in a loop to continuously check for received frames.
INT8U MCP_CAN::checkReceive(void);
4. Get CAN ID¶
You can use the following function to get the length of the data received from the "send" node.
INT32U MCP_CAN::getCanId(void)
5. Send a frame¶
CAN.sendMsgBuf(INT8U id, INT8U ext, INT8U len, data_buf);
This function is used to send data onto the CAN Bus. The parameters are as follows:
- id - The ID of can frame.
- ext - A boolean value representing the status of the frame. '0' means standard frame. '1' means extended frame.
- len - The length of the frame.
- data_buf - The content of the message.
For example, In the 'send' example, we have:
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
CAN.sendMsgBuf(0x00, 0, 8, stmp); //send out the message 'stmp' to the bus and tell other devices this is a standard frame from 0x00.
6. Receive a frame¶
The following function is used to receive data on the 'receive' node:
CAN.readMsgBuf(unsigned char len, unsigned char buf);
In conditions that masks and filters have been set. This function can only get frames that meet the requirements of masks and filters.
- len represents the data length.
- buf is where you store the data.
FAQ¶
I can't upload code to CANBed
- Make sure that the correct COM port and board type are selected in the Arduino IDE.
- Try unplugging and replugging the USB cable to reset the connection.
- Try restarting the Arduino IDE.
- Make sure that you are using the correct driver for the board. If you are using a Windows computer, you may need to install the driver manually. The driver can usually be found in the Arduino installation folder under "drivers".
- If you are still unable to upload code to the board, there may be a hardware issue. Try using a different micro USB cable or testing the board on a different computer. If the issue persists, please contact support@longan-labs.cc for further assistance.
The RX/TX led light up and never turn off
- Check if the baud rate of the CAN Bus is set correctly. The baud rate should match the baud rate of the other devices on the CAN Bus.
- Try turning the switch for the 120Ω terminal resistor on and off.
- Check that the connections for CANH and CANL are correct. They should be connected to the corresponding lines on the other devices on the CAN Bus.
- Make sure that the frame being sent or received is properly formatted and does not have any errors.
How to find technical support
If you are experiencing any issues with the CANBed board or have any technical questions, please contact support@longan-labs.cc for assistance. In your email, please include as much detail as possible about the problem you are experiencing, including when and how you purchased the product, the version of the product you are using, and any relevant pictures or error messages. Our technical support team will do their best to help you resolve any issues and get your project up and running as quickly as possible.