Can Bus Shield project to get RPM and Speed!!!

Hey guys i am trying to do this project with the Can-Bus-shield to read the RPM and the speed from a car. I am using the Can Bus from sparkfun with the Arduino Uno, and a SerLCD. I have the can bus shield on top of the Uno and the LCD connect to the Can Bus. No code seems to work i cant even get “Hello World” to the LCD; i am 100% sure with my connections so its gotta be the codes. Can anyone help me please, or any subjection?
Thank you so much!!!

If you take CanBus out of the equation, can you get the display to work? Presumably you have some examples of how to do this.

No code seems to work

Show us the code that don't work!

i found this code it is as more then i need, i still couldnt get anything to the LCD.


/**
*
*

  • Copyright (c) 2008-2009 All rights reserved.
    */
    #include “WConstants.h”
    #include <stdio.h>
    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <util/delay.h>
    #include “pins_arduino.h”
    #include <inttypes.h>
    #include “global.h”
    #include “mcp2515.h”
    #include “defaults.h”
    #include “Canbus.h”

/* C++ wrapper */
CanbusClass::CanbusClass() {

}
char CanbusClass::message_rx(unsigned char *buffer) {
tCAN message;

if (mcp2515_check_message()) {

// Lese die Nachricht aus dem Puffern des MCP2515
if (mcp2515_get_message(&message)) {
// print_can_message(&message);
// PRINT("\n");
buffer[0] = message.data[0];
buffer[1] = message.data[1];
buffer[2] = message.data[2];
buffer[3] = message.data[3];
buffer[4] = message.data[4];
buffer[5] = message.data[5];
buffer[6] = message.data[6];
buffer[7] = message.data[7];
// buffer = message;
// buffer = message;
// buffer = message;
// buffer = message;
}
else {
// PRINT(“Kann die Nachricht nicht auslesen\n\n”);
}
}

}

char CanbusClass::message_tx(void) {
tCAN message;

// einige Testwerte
message.id = 0x7DF;
message.header.rtr = 0;
message.header.length = 8;
message.data[0] = 0x02;
message.data[1] = 0x01;
message.data[2] = 0x05;
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), (1<<REQOP1));
mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);

if (mcp2515_send_message(&message)) {
// SET(LED2_HIGH);
return 1;

}
else {
// PRINT(“Fehler: konnte die Nachricht nicht auslesen\n\n”);
return 0;
}
return 1;

}

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);
// SET(LED2_HIGH);
if (mcp2515_send_message(&message)) {
}

while(timeout < 4000)
{
timeout++;
if (mcp2515_check_message())
{

if (mcp2515_get_message(&message))
{
if((message.id == PID_REPLY) && (message.data[2] == pid)) // Check message is the reply and its the right PID
{
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);

case THROTTLE: // Throttle Position
engine_data = (message.data[3]*100)/255;
sprintf(buffer,"%d %% ",(int) engine_data);
break;

}
message_ok = 1;
}

}
}
if(message_ok == 1) return 1;
}

return 0;
}

char CanbusClass::init(unsigned char speed) {

return mcp2515_init(speed);

}

CanbusClass Canbus;

First: You haven't used code tags, please edit your post and include code tags to make the post readable.

The code you posted is a class library, not a sketch. The library was written for a pre-1.0 IDE version and won't compile as-is on a current IDE. I'm not surprised that a library for itself won't display anything on an LCD, especially if the library doesn't include any LCD code.

To give you a start: http://www.openhardwarehub.com/projects/40-Arduino-CAN-BUS-OBD-Gas-Gauge this is a project, that does use more or less the same hardware components although arranged differently. Nevertheless you should be able to use some of the code.

Supercool: i found this code it is as more then i need, i still couldnt get anything to the LCD.

Yeah, but the word 'Canbus' appears all over the place in that code.

Physically take the Canbus shield off your Arduino, write or find a sketch that just displays on your LCD, and make sure you know how to do that before you add Canbus back into the equation.

/**
 * 
 *
 * Copyright (c) 2008-2009  All rights reserved.
 */
#include "WConstants.h"
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "pins_arduino.h"
#include <inttypes.h>
#include "global.h"
#include "mcp2515.h"
#include "defaults.h"
#include "Canbus.h"




/* C++ wrapper */
CanbusClass::CanbusClass() {

 
}
char CanbusClass::message_rx(unsigned char *buffer) {
      tCAN message;
   
      if (mcp2515_check_message()) {
      
         
         // Lese die Nachricht aus dem Puffern des MCP2515
         if (mcp2515_get_message(&message)) {
         //   print_can_message(&message);
         //   PRINT("\n");
            buffer[0] = message.data[0];
            buffer[1] = message.data[1];
            buffer[2] = message.data[2];
            buffer[3] = message.data[3];
            buffer[4] = message.data[4];
            buffer[5] = message.data[5];
            buffer[6] = message.data[6];
            buffer[7] = message.data[7];                        
//            buffer[] = message[];
//            buffer[] = message[];
//            buffer[] = message[];
//            buffer[] = message[];                                                                                    
         }
         else {
         //   PRINT("Kann die Nachricht nicht auslesen\n\n");
         }
      }

}

char CanbusClass::message_tx(void) {
   tCAN message;


   // einige Testwerte
   message.id = 0x7DF;
   message.header.rtr = 0;
   message.header.length = 8;
   message.data[0] = 0x02;
   message.data[1] = 0x01;
   message.data[2] = 0x05;
   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), (1<<REQOP1));   
      mcp2515_bit_modify(CANCTRL, (1<<REQOP2)|(1<<REQOP1)|(1<<REQOP0), 0);
      
   if (mcp2515_send_message(&message)) {
      //   SET(LED2_HIGH);
      return 1;
   
   }
   else {
   //   PRINT("Fehler: konnte die Nachricht nicht auslesen\n\n");
   return 0;
   }
return 1;
 
}

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);
//      SET(LED2_HIGH);   
   if (mcp2515_send_message(&message)) {
   }
   
   while(timeout < 4000)
   {
      timeout++;
            if (mcp2515_check_message()) 
            {

               if (mcp2515_get_message(&message)) 
               {
                     if((message.id == PID_REPLY) && (message.data[2] == pid))   // Check message is the reply and its the right PID
                     {
                        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);
                     
                           case THROTTLE:            // Throttle Position
                           engine_data = (message.data[3]*100)/255;
                           sprintf(buffer,"%d %% ",(int) engine_data);
                           break;
                     
                        }
                        message_ok = 1;
                     }

               }
            }
            if(message_ok == 1) return 1;
   }


    return 0;
}






char CanbusClass::init(unsigned char speed) {

  return mcp2515_init(speed);
 
}

CanbusClass Canbus;