I have just started playing around with CAN networks and have been having trouble receiving any data through my Arduino. I have tried three different input methods. I first connected my 2003 VW Jetta through an OBD2 to Serial cable, which yielded no RX light or incoming data. Second, I wired a serial connector directly to some CAN wires in the car which lead to a blinking RX light, but still no output. Finally, I have a temperature sensor that outputs a CANH and CANL signal. When powered up, it causes the RX light to flash rapidly but yields no data in the Serial Monitor. I have desoldered the default resistor as some have suggested, to no avail. I have also tries multiple example codes that people have posted on this forum as well as others. Here is the code that I have currently running, but I have seen the same problem with other iterations of similar coding. This was borrowed from cherkasoff, another user on the forum.
[code] // demo: CAN-BUS Shield, receive data
#include <mcp_can.h>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
MCP_CAN CAN0(9); // Set CS to pin 9
void setup()
{
delay(5000);
Serial.begin(115200);
if(CAN0.begin(CAN_500KBPS) == CAN_OK) Serial.print("can init ok!!\r\n");
else Serial.print("Can init fail!!\r\n"); // init can bus : baudrate = 500k
pinMode(2, INPUT); // Setting pin 2 for /INT input
Serial.println("MCP2515 Library Receive Example...");
}
void loop()
{
if(!digitalRead(2)) // If pin 2 is low, read receive buffer
{
CAN0.readMsgBuf(&len, rxBuf); // Read data: len = data length, buf = data byte(s)
rxId = CAN0.getCanId(); // Get message ID
Serial.print("ID: ");
Serial.print(rxId, HEX);
Serial.print(" Data: ");
for(int i = 0; i<len; i++) // Print each byte of the data
{
if(rxBuf[i] < 0x10) // If data byte is less than 0x10, add a leading zero
{
Serial.print("0");
}
Serial.print(rxBuf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/[/code]
Any help would be greatly appreciated!