Hi,
I have an Arduino Uno with the Sparkfun Canbus shield. I'm currently trying the ECU demo with an ECUsim 2000, however engine speed does not show up in the Serial Monitor. I also have a Kvaser Leaf connected to the CAN, which is able to see both the request and reply message. I have removed the LCD and GPS features from the script.
This is the main part of the loop on the Arduino:
void loop(){
Canbus.ecu_req(ENGINE_RPM,buffer); //Request engine RPM
EngineRPM = buffer;
Serial.print("Engine RPM: "); //Uncomment for Serial debugging
Serial.println(buffer);
delay(1000);
}
This is from Canbus.cpp
char CanbusClass::ecu_req(unsigned char pid, char *buffer)
{
tCAN message;
float engine_data;
int timeout = 0;
char message_ok = 0;
// Prepair message
message.id = PID_REQUEST;
message.header.rtr = 0;
message.header.length = 8;
message.data[0] = 0x02;
message.data[1] = 0x01;
message.data[2] = pid;
message.data[3] = 0x00;
message.data[4] = 0x00;
message.data[5] = 0x00;
message.data[6] = 0x00;
message.data[7] = 0x00;
mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
if (mcp2515_send_message(&message)) {
}
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
switch(message.data[2])
{ /* Details from http://en.wikipedia.org/wiki/OBD-II_PIDs */
case ENGINE_RPM: // ((A*256)+B)/4 [RPM]
engine_data = ((message.data[3]*256) + message.data[4])/4;
sprintf(buffer,"%d rpm ",(int) engine_data);
break;
case ENGINE_COOLANT_TEMP: // A-40 [degree C]
engine_data = message.data[3] - 40;
sprintf(buffer,"%d degC",(int) engine_data);
break;
case VEHICLE_SPEED: // A [km]
engine_data = message.data[3];
sprintf(buffer,"%d km ",(int) engine_data);
break;
case MAF_SENSOR: // ((256*A)+B) / 100 [g/s]
engine_data = ((message.data[3]*256) + message.data[4])/100;
sprintf(buffer,"%d g/s",(int) engine_data);
break;
case O2_VOLTAGE: // A * 0.005 (B-128) * 100/128 (if B==0xFF, sensor is not used in trim calc)
engine_data = message.data[3]*0.005;
sprintf(buffer,"%d V",(int) engine_data);
break;
case THROTTLE: // Throttle Position
engine_data = (message.data[3]*100)/255;
sprintf(buffer,"%d %% ",(int) engine_data);
break;
}
//return buffer;
}
}
}
The Serial monitor shows that it is able to initialise the CAN shield, however only "Engine RPM: " is printed and not the actual RPM.
Monitoring what is happening on the CAN using Kvaser, the following messages are seen:
0 2015 8 2 1 12 0 0 0 0 0 20069.106680 R (Eng RPM request message)
0 2024 8 4 65 12 0 0 0 0 0 20069.107790 R (Eng RPM reply message)
0 2025 8 4 65 12 0 0 0 0 0 20069.108560 R
But the Arduino doesn't seem to be able to pick it up into the buffer.
I've got some experience with Arduino but still learning, any help will be much appreciated.
Thanks
Jonny