Go Down

Topic: Can-Bus (Read 10176 times) previous topic - next topic

coryjfowler

OBD has two modes when used over CAN, 11bit and 29bit and while I am not familiar with the Arduino OBD library, I am familiar with the fact my vehicle will not work with 11bit mode and required 29bit mode on the scan tool I was using.  You would need to determine what modes the library supports and if only one mode is supported, that is likely why you are not getting any values returned and the library would need updated.
"Taking the time to make a proper, punctuated, post is a mark of courtesy and respect."  http://forum.arduino.cc/index.php?topic=149022.0

Nobel_Tanmay

Hi Guys,

Its a little urgent. Please help.

I have a arduino mkr can bus shield mounted on arduino mkrzero board. I have a can bus device that connects to the can bus shield. I can to read the data received from that CAN device on the arduino IDE serial monitor. How can I read the data recieved. Should I use SPI from mkr zero or some others pins to monitor this data?

Can some one please share the code to read this data somehow?

I have the picture of the assemble attached.


Thanks,

Nobel_Tanmay

#17
Feb 08, 2019, 10:08 pm Last Edit: Feb 08, 2019, 10:10 pm by Nobel_Tanmay
Picture of the assembly

Nobel_Tanmay

I was trying to use this code but the can bus shield always fails to initialize.


// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13


#include <SPI.h>
#include "mcp_can.h"


// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 3;



MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

void setup()
{
    Serial.begin(115200);
   
    while (CAN_OK != CAN.begin(CAN_500KBPS))              // init can bus : baudrate = 500k
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println(" Init CAN BUS Shield again");
        Serial.println("check");
        delay(100);
    }
    Serial.println("CAN BUS Shield init ok!");
}


void loop()
{
    unsigned char len = 0;
    unsigned char buf[8];

    if(CAN_MSGAVAIL == CAN.checkReceive())            // check if data coming
    {
        CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

        unsigned int canId = CAN.getCanId();
       
        Serial.println("-----------------------------");
        Serial.print("Get data from ID: ");
        Serial.println(canId, HEX);

        for(int i = 0; i<len; i++)    // print the data
        {
            Serial.print(buf, HEX);
            Serial.print("\t");
        }
        Serial.println();
    }
}

/*********************************************************************************************************
  END FILE
*********************************************************************************************************/

Les_Collier

Hi the code you have looks very similar to mine, so I don't think it's code.  I found that I got the failed to initialise if there was no power on the board, although I have to say this is clutching at straws as your picture shows what looks like good connections.

amondays

hello how to connect the car? I'm using an OBD2 connector with CAN H and CAN L connectors. DB9 connector with arduino canbus shield. Is that right? Thank you! The codes displayed here do not yield results..

Go Up