GithubHelp home page GithubHelp logo

serial_can_arduino's Introduction

Longan Labs Serial CAN Bus Module Library

Actions Status Spell Check codecov

The Serial CAN Bus module provides your Arduino with CAN Bus capabilities and allows you to hack your vehicle. It lets you to read and write messages to the CAN Bus. The Serial CAN Bus module can be connected to your Arduino through the on-board Grove connector.

CAN Bus is a messaging protocol system that lets various microcontrollers and sensors within a vehicle to talk to each other. CAN provides long distance, medium communication speed, and high reliability.

The Serial CAN Bus module is based on MCP2515 CAN controller and MCP2551 CAN transceiver provides speed up to 1Mb/s. It also has a terminal block so you can connect to your vehicle’s OBD-II port with two wires.

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

  1. Download the library
  2. Extract the zip file
  3. In the Arduino IDe, navigate to Sketch > Include Library > Add .ZIP Library

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.

Functions

  • begin()
  • send()
  • recv()
  • canRate()
  • baudRate()
  • setMask()
  • setFilt()
  • factorySetting()
  • debugMode()

Examples

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

// SEND EXAMPLE OF SERIAL CAN MODULE
// unsigned char send(unsigned long id, uchar ext, uchar rtrBit, uchar len, const uchar *buf);
// SUPPORT: [email protected]
#include <Serial_CAN_Module.h>
#include <SoftwareSerial.h>

Serial_CAN can;

#define can_tx  2           // tx of serial can module connect to D2
#define can_rx  3           // rx of serial can module connect to D3

void setup()
{
    Serial.begin(9600);
    can.begin(can_tx, can_rx, 9600);      // tx, rx
    Serial.println("begin");
}

unsigned char dta[8] = {1, 2, 3, 4, 5, 6, 7, 8};

// send(unsigned long id, byte ext, byte rtrBit, byte len, const byte *buf);
void loop()
{
    can.send(0x55, 0, 0, 8, dta);   // SEND TO ID:0X55
    delay(100);
}

// END FILE

Get a Dev Board

If you need a Dev board, plese try,

You can get others CAN Dev board below,

License

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.

Contact us

If you have any question, please feel free to contact [email protected]

Analytics

serial_can_arduino's People

Contributors

ktetsuo avatar stephen1874 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

serial_can_arduino's Issues

error "set can rate fail"

Hello,

I connect the serial CAN bus on an arduino mega 2560 as described in the file recv.ino but I get the message "set can rate fail". I just wanted to test the code without already reading a CAN-bussystem. What is the cause of this message?

Thanks in advance,
Bart

Unable to get running example

Hello,

I have two longan V1.2 micro can boards. I have them simply configured with uno's.

I am using the send and receive examples for testing.

I have changed the pints to 10 and 11 respectively for can tx and rx.

I have a twisted pair of wires connecting CAN_H to CAN_H and CAN_L to CAN_L but I am unable to successfully transmit any data from the send to recv. I added canBus->listen(); to the begin function in order to tell software serial to listen for data on the bus.

Any suggestions?

Serial_CAN_Module.cpp timer_s variable set when it shouldn't

In Serial_CAN_Module.cpp / recv():

In the following lines the return 0 statement will never be reached since time_s is set right before the check.
Probably the timer_s = should be removed since it is also set at the very beginning of recv.

timer_s = millis();
if((millis()-timer_s) > 10)
return 0; // Reading 12 bytes should be faster than 10ms, abort if it takes longer, we loose the partial message in this case

Extra bytes break library

Hi.

I am using this library and the serial CAN module to talk to a race car dashboard that supports custom CAN in and out.

This works 95% of the time, but sometimes the data stream contains extra bytes (anywhere between 3 and 7) that don't make sense to me.
In theory we can just discard those extra bytes, and skip to the beginning of the next CAN message. In practice what happens is this library gets out of sync and starts sending back CAN messages which are offset in the byte stream.

example:

normal message:

0x0 0x0 0x0 0xA1 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8

I receive the above in a loop, no problem. Then all of the sudden this arrives:

0xC1 0xA4 0x3 0x5

(this is an example, can be any random sequence and the number of bytes also varies)

followed by:

0x0 0x0 0x0 0xA1 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8

What happens in the library. It builds the following CAN command:

0xC1 0xA4 0x3 0x5 0x0 0x0 0x0 0xA1 0x1 0x2 0x3 0x4

and sends it back to the caller. Of course I can't do anything with that as I don't understand the command. From there on the entire CAN stream is offset 4 bytes and I never get a correct command again.

What I did to fix this is to check that when reading a sequence of bytes that the first 4 are 0x0 0x0 0x0 0xA1 and the last 2 are 0x7 0x8, but this of course only works because I know that the input data will always start with this and that the last 2 bytes are 2 fixed values. This is in no way a generic solution for the 'out of sync' problem.

Any idea?

How can i get DTC (trouble codes) ?

Hi everyone, i would like to get trouble codes from car, but i have no clue how to do it, can anyone help me?
Thanks in advance.
Sorry for my bad english.

what is the 0x7DF PID code?

I've bought a Serial CAN Bus Module v1.4 and I'm trying to get data from my car OBD port.
I've run the Arduino examples and couldn't get speed and rpm.
I don't know what is the correct PID and how can I use them.
for example, I need to find my car PIDs what is the 0x7DF PID in the examples codes?

CAN Bus dev kit issue with code examples - perhaps baudrate

Hello,

I have recently ordered an OBD II CAN bus dev kit, along with an Arduino Uno. After assembling it I have encountered some issues with this associated repository. For context, I have it connected to my Vauxhall Corsa C (2005), which I have checked is full CAN bus. I am using the Arduino IDE too.

This is the kit: https://coolcomponents.co.uk/products/obd-ii-can-bus-development-kit?currency=GBP&variant=14053842518077&utm_medium=cpc&utm_source=google&utm_campaign=Google%20Shopping&gclid=CjwKCAjw0qOIBhBhEiwAyvVcfzNDx3rhWIP5s0Sm54Jer5jDSxRrLzALLirqVBqXPdg-PCjtGTRekhoCJvIQAvD_BwE

I have been testing the obd_demo example and I believe I have encountered a communication rate issue of some kind (baud rate related perhaps). How should the rates be setup?

At the moment, the output is inconsistent and usually has many question marks.

Thanks,

Flynn

SoftwareSerial library not compatible for >20MHz processors

I am using the Feather M4 Express (ATSAMD51 controller on it) with the Serial CAN board and I am unable to compile the example code due to the error below.

lib/SoftwareSerial/SoftwareSerial.cpp:362:2: error: #error This version of SoftwareSerial supports only 20, 16 and 8MHz processors

obd_demo usage

Hello ,

I have OBD-II CAN-BUS Development Kit. I have prepared kit as in the instructions. Compile and upload the code to the arduino.

When I power on my arduino by plugging usb to pc , if obd2 connected to vehicle , serial monitor wont show any message, If obd2 is not connected serial monitor says

15:11:24.153 -> set can rate ok
15:11:24.856 -> set mask ok
15:11:27.341 -> set filt ok
15:11:27.341 -> begin

after it says begin i plug obd2 socket to the vehicle (opel astra 2013 sedan )
when i send
15:27:54.128 -> SEND PID: 0xC
15:27:54.175 ->
15:27:54.175 -> ------------------------------------------------------------------
15:27:54.175 -> Get Data From id: 0x7E8
15:27:54.175 ->
15:28:05.368 -> SEND PID: 0xD
15:28:05.415 ->
15:28:05.415 -> ------------------------------------------------------------------
15:28:05.415 -> Get Data From id: 0x7E8
15:28:05.415 ->
15:28:12.399 -> SEND PID: 0x5
15:28:12.446 ->
15:28:12.446 -> ------------------------------------------------------------------
15:28:12.446 -> Get Data From id: 0x7E8
15:28:12.446 ->

It show me these responses. How can it get speed , rpm values ?

And why should i need to unplug obd2 connector to make connection well.

sketch/Serial_CAN_Module.cpp: In member function 'unsigned char Serial_CAN::exitSettingMode()':

Hi, could you please help me with the error below;

`
Arduino: 1.8.12 (Mac OS X), Board: "Arduino Nano, ATmega328P"

sketch/Serial_CAN_Module.cpp: In member function 'unsigned char Serial_CAN::exitSettingMode()':
sketch/Serial_CAN_Module.cpp:172:31: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
int ret = cmdOk("AT+Q\r\n");
^
sketch/Serial_CAN_Module.cpp: In member function 'unsigned char Serial_CAN::factorySetting()':
sketch/Serial_CAN_Module.cpp:286:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(cmdOk("AT\r\n"))
^
/Users/yigit/Documents/Arduino/libraries/Serial_CAN_Module/Serial_CAN_Module.cpp: In member function 'unsigned char Serial_CAN::exitSettingMode()':
/Users/yigit/Documents/Arduino/libraries/Serial_CAN_Module/Serial_CAN_Module.cpp:172:31: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
int ret = cmdOk("AT+Q\r\n");
^
/Users/yigit/Documents/Arduino/libraries/Serial_CAN_Module/Serial_CAN_Module.cpp: In member function 'unsigned char Serial_CAN::factorySetting()':
/Users/yigit/Documents/Arduino/libraries/Serial_CAN_Module/Serial_CAN_Module.cpp:286:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if(cmdOk("AT\r\n"))
^
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of canSerial'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::begin(int, int, unsigned long)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::send(unsigned long, unsigned char, unsigned char, unsigned char, unsigned char const*)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::recv(unsigned long*, unsigned char*)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::clear()'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::cmdOk(char*)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::enterSettingMode()'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::exitSettingMode()'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::canRate(unsigned char)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::baudRate(unsigned char)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of make8zerochar(int, char*, unsigned long)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::setMask(unsigned long*)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::setFilt(unsigned long*)'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::factorySetting()'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries/Serial_CAN_Module/Serial_CAN_Module.cpp.o (symbol from plugin): In function canSerial': (.text+0x0): multiple definition of Serial_CAN::debugMode()'
sketch/Serial_CAN_Module.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Nano.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.