We launched the Serial CAN Bus Module years ago, which is very practial and easy to use. Now we have slightly modified the Serial CAN Bus Module, wrote a special firmware, and launched this I2C CAN Bus Module.
The I2C CAN Bus Module uses I2C for communication. The board is small and flexible, which make it can be quickly used in any system with an I2C interface.
The I2C CAN Bus Module is based on the high-performance MCP2515 CAN Bus controller and MCP2551 CAN Bus transceiver, provides a CAN Bus communication rate of up to 1Mb/s.
In addition, there is an Atmega168PA microcontroller on the board, you can also program it through a USB to Serial board, modify the firmware or write your application directly.
With this library, you can,
- Send a CAN2.0 frame
- Receive a CAN2.0 frame
- Get data from OBD-II
- Set the masks and filters, there're 32 masks and filters.
- Download the library
- Extract the zip file
- In the Arduino IDe, navigate to Sketch > Include Library > Add .ZIP Library
- /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.
- begin()
- sendMsgBuf()
- readMsgBuf()
- readMsgBufID()
- init_Mask()
- init_Filt()
- checkReceive()
- getCanId()
- isRemoteRequest()
- isExtendedFrame
here are many examples implemented in this library. One of the examples is below. You can find other examples here
#include <Wire.h>
#include "Longan_I2C_CAN_Arduino.h"
I2C_CAN CAN(0x25); // Set CS pin
void setup()
{
Serial.begin(115200);
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] = {1, 2, 3, 4, 5, 6, 7, 0};
int cnt = 0;
void loop()
{
stmp[7] = cnt++;
if(cnt > 100)cnt = 0;
CAN.sendMsgBuf(0x01, 0, 8, stmp);
delay(5); // send data per 100ms
}
// END FILE
If you need a Dev board, plese try,
You can get others CAN Dev board below,
MIT License
Copyright (c) 2018 @ Longan Labs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
If you have any question, please feel free to contact [email protected]