Cover image

Biblioteca de autobuses Arduino CAN, MCP2515/MCP2551

3 years

Works with Finder

15

Github Watches

387

Github Forks

140

Github Stars

CAN Bus Library

GitHub Installation instructions GitHub version GitHub Release Date GitHub Repo stars GitHub issues

Arduino library for MCP2515, it's available for most of theArduino boards, we test it with Arduino UNO, Leonardo, Mega as well as Zero.

With this library, you can,

  1. Send a CAN2.0 frame
  2. Receive a CAN2.0 frame
  3. Get data from OBD-II
  4. Set the masks and filters, there're 32 masks and filters.

Installation

You can install it similiar to any other Arduino libraries, using the Library Manager or from a Zip file in the Arduino IDE.

  • Install using the Library Manager
  1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries...
  2. Search for "mcp_canbus" to find this library
  3. Click "INSTALL"
  • Install from a Zip file
  1. Download this library
  2. Extract the zip file
  3. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library

You can also read how to install mcp_canbus library for a reference.

Respository Contents

  • /examples - Example sketches for the library (.ino). Run these from the Arduino IDE.
  • /src - Source files for the library (.cpp, .h).
  • keywords.txt - Keywords from this library that will be highlighted in the Arduino IDE.
  • library.properties - General library properties for the Arduino package manager.

How to use

Header

#include <mcp_canbus.h>

Functions

  • begin()
  • init_Mask()
  • init_filt()
  • checkReceive()
  • readMsgBufID()
  • readMsgBuf()
  • getCanId()
  • sendMsgBuf()
  • isRemoteRequest()
  • isExtendedFrame()

Examples

here are many examples implemented in this library. One of the examples is below. You can find other examples here

/*  send a frame from can bus
    support@longan-labs.cc
    
    CAN Baudrate,
    
    #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
    
    CANBed V1: https://www.longan-labs.cc/1030008.html
    CANBed M0: https://www.longan-labs.cc/1030014.html
    CAN Bus Shield: https://www.longan-labs.cc/1030016.html
    OBD-II CAN Bus GPS Dev Kit: https://www.longan-labs.cc/1030003.html
*/
   
#include <mcp_canbus.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

Get a Dev Board

If you need a Dev board, plese try,

Contact us

If you have any question, please feel free to contact support@longan-labs.cc

相关推荐

  • GreenPepper Consulting India Private Limited
  • Formal yet conversational interview questions

  • av
  • Ejecute sin esfuerzo LLM Backends, API, frontends y servicios con un solo comando.

  • 1Panel-dev
  • 🔥 1Panel proporciona una interfaz web intuitiva y un servidor MCP para administrar sitios web, archivos, contenedores, bases de datos y LLM en un servidor de Linux.

  • GeyserMC
  • Una biblioteca para la comunicación con un cliente/servidor de Minecraft.

  • awslabs
  • Servidores AWS MCP: servidores MCP especializados que traen las mejores prácticas de AWS directamente a su flujo de trabajo de desarrollo

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 llM 资料总结(数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Resumen de los mejores recursos del mundo.

  • rulego
  • ⛓️Rulego es un marco de motor de regla de orquestación de componentes de alta generación de alto rendimiento, de alto rendimiento y de alto rendimiento para GO.

  • GLips
  • Servidor MCP para proporcionar información de diseño de figma a agentes de codificación de IA como Cursor

  • Byaidu
  • Traducción de papel científico en PDF con formatos preservados - 基于 Ai 完整保留排版的 PDF 文档全文双语翻译 , 支持 支持 支持 支持 支持 支持 支持 支持 支持 支持 支持 支持 等服务 等服务 等服务 提供 提供 提供 提供 提供 提供 提供 提供 提供 提供 提供 提供 cli/mcp/docker/zotero

  • n8n-io
  • Plataforma de automatización de flujo de trabajo de código justo con capacidades de IA nativas. Combine el edificio visual con código personalizado, auto-anfitrión o nube, más de 400 integraciones.

  • activepieces
  • AI AGENTES & MCPS & AI AUTOMACIÓN DE FLUILES DE TRABAJO • (280+ Servidores MCP para agentes de IA) • Automatización de IA / Agente de AI con MCPS • Flujos de trabajo de IA y agentes de IA • MCP para agentes de IA

    Reviews

    2 (1)
    Avatar
    user_YZwf9eD8
    2025-04-17

    The Arduino_CAN_BUS_MCP2515 by Longan-Labs is an excellent product for anyone looking to integrate CAN bus communication in their projects. Its easy-to-use library and reliable performance make it a must-have for Arduino enthusiasts. Highly recommend checking out their GitHub for documentation and support!