Toyota-Prius CAN Bus Message Monitor:

This project based on the  GitHub- coryjfowler/MCP_CAN_lib: MCP_CAN Library.

Needs the following Parts:

1. OBDII connector
2. 
DB9 (Female Connector)
3. Arduino UNO
4. Arduino CAN Shield

Lets make the OBD Cable:

It is easy to make a simple OBDII cable using   2-core audio cable, OBDII & D9 Female connectors.
Using about 3m of Audio cable, hookup two ends of the cable to the connectors as shown below.
Actually, GND connection is not necessary, only CAN-H and CAN-L connections are adequate for the
following example. 



Connect the OBDII connector to the CAR diagnostic port and D9 side to the Arduino CAN shield.



Once both ends of the cable are correctly connected, the RX and INT LEDs on the CAN Shield should
light up!!  



Download the Zip library and install it on Arduino IDE.
https://github.com/coryjfowler/MCP_CAN_lib


From Examples, load the CAN_Receiver.ino .


Arduino Code:

// CAN Receive Example
//No filters

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

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128];                       // Array to store serial string

#define CAN0_INT 2                         // Set INT to pin 2(MCP2515 INT pin connected to Pin-2 of Arduino UNO)
MCP_CAN CAN0(10);                          // Set CS to pin 10(MCP2515 CS pin connected to Pin-10 of Arduino UNO)


void setup()
{
  Serial.begin(115200);
  
  // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
  if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else
    Serial.println("Error Initializing MCP2515...");
  
  CAN0.setMode(MCP_NORMAL);              // Set operation mode to normal so the MCP2515 sends acks to received data.

  pinMode(CAN0_INT, INPUT);             // Configuring pin for /INT input
  
  Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
  if(!digitalRead(CAN0_INT))                   // If CAN0_INT pin is low, read receive buffer
  {
    CAN0.readMsgBuf(&rxId, &len, rxBuf);      // Read data: len = data length, buf = data byte(s)
    
    if((rxId & 0x80000000) == 0x80000000)     // Determine if ID is standard (11 bits) or extended (29 bits)
      sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
    else
      sprintf(msgString, "Standard ID: 0x%.3lX       DLC: %1d  Data:", rxId, len);
  
    Serial.print(msgString);
  
    if((rxId & 0x40000000) == 0x40000000){    // Determine if message is a remote request frame.
      sprintf(msgString, " REMOTE REQUEST FRAME");
      Serial.print(msgString);
    } else {
      for(byte i = 0; i<len; i++){
        sprintf(msgString, " 0x%.2X", rxBuf[i]);
        Serial.print(msgString);
      }
    }
        
    Serial.println();
  }
}

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

Compile and upload to Uno board.

You should see the following output on Arduino COM Port Monitor:
ID field shows the CAN message ID following 8bytes of Data.

It is possible to filter the messages by Message ID.


List of Toyota Prius CAN IDs:

In the next example, we will discuss how to filter messages and display required data like State of Charge (SOC) etc.





0Comments

For Comment you need to Login