Hey guys…
I have a Arduino 2560 mega R3, and a secuduino Can-shield… Setting it up so that I can use a car cluster on the computer with a for games… The cluster that I’m going to be using is from a 2006 BF Falcon XR6… I am trying just to get the gauges to “sweep” before I go and code it up to work in the game, wanna know it works first… the PID’s for can-bus clusters from what I know is a international standard so the code/PID’s from most manufactures should work I would say?.. I found a code on x-sim website and having a few problems…
Heres the code…
#include <SPI.h>
#include <CAN.h>
const int message_id_201 = 0x201;
const int message_id_212 = 0x212;
const int message_id_231 = 0x231;
const int message_id_420 = 0x420;
int message_id ;
byte message_to_send;
int id;
byte b;
int i;
char s[8];
byte my_data[8];
byte BitMap[8];
int RPM;
int mphspeed;
int kmhspeed;
void setup()
{
message_id=0x000;
CAN.begin ();
CAN.setMode (CAN_MODE_NORMAL);
RPM=5500;
mphspeed=100;
}
void loop()
{
/* Convert mph to kmh as all internal speeds are kmh*/
kmhspeed=mphspeed * 160.9344;
delay(10);
/* Turn off steering Warning */
if(steering == 0 ) {
CAN.setMessageID (message_id_300);
CAN.sendByte (0);
}
/* Speedo / tacho */
CAN.setMessageID (message_id_201);
my_data[0] = (RPM * 4) / 256; // rpm
my_data[1] = (RPM * 4) % 256; // rpm
my_data[2] = 0xFF; // Unknown, 0xFF from 'live'.
my_data[3] = 0xFF; // Unknown, 0xFF from 'live'.
my_data[4] = (kmhspeed+10000) / 256; //speed
my_data[5] = (kmhspeed+10000) % 256; //speed
my_data[6] = 0x00; // Unknown possible accelerator pedel if Madox is correc
my_data[7] = 0x00; //Unknown
CAN.sendData(my_data,8);
/* Warning Lights */
CAN.setMessageID (message_id_212);
my_data[0] = 0xFE; //Unknown
my_data[1] = 0xFE; //Unknown
my_data[2] = 0xFE; //Unknown
my_data[3] = 0x34; //DSC OFF in combo with byte 5 Live data only seen 0x34
my_data[4] = 0x00; // B01000000; // Brake warning B00001000; //ABS warning
my_data[5] = 0x40; // TCS in combo with byte 3
my_data[6] = 0x00; // Unknown
my_data[7] = 0x00; // Unused
CAN.sendData(my_data,7);
/* Other gauges / warning lights */
CAN.setMessageID (message_id_420);
my_data[0] = 0x98 ; //temp gauge //~170 is red, ~165 last bar, 152 centre, 90 first bar, 92 second bar
my_data[1] = 0x00; // something to do with trip meter 0x10, 0x11, 0x17 increments by 0.1 miles
my_data[2] = 0x00; // unknown
my_data[3] = 0x00; //unknown
my_data[4] = 0x01; //Oil Pressure (not really a gauge)
my_data[5] = 0x00; //check engine light
my_data[6] = 0x00; //Coolant, oil and battery
my_data[7] = 0x00; //unused
CAN.sendData(my_data,7);
*/
/* Cruise Control Light */
/*
CAN.setMessageID (message_id_650);
my_data[0] = 0xFF; // cruise control light 0x80 is yellow, 0xFF is green
CAN.sendData(my_data,1);
*/
}
}
And this is the errors that I’m getting…
‘CAN’ was not declared in this scope
sketch_nov13c.cpp: In function ‘void setup()’:
sketch_nov13c:26: error: ‘CAN’ was not declared in this scope
sketch_nov13c:27: error: ‘CAN_MODE_NORMAL’ was not declared in this scope
sketch_nov13c.cpp: In function ‘void loop()’:
sketch_nov13c:43: error: ‘steering’ was not declared in this scope
sketch_nov13c:44: error: ‘CAN’ was not declared in this scope
sketch_nov13c:44: error: ‘message_id_300’ was not declared in this scope
sketch_nov13c:51: error: ‘CAN’ was not declared in this scope
sketch_nov13c:87: error: expected primary-expression before ‘/’ token
sketch_nov13c:98: error: expected primary-expression before ‘}’ token
sketch_nov13c:98: error: expected `;’ before ‘}’ token
sketch_nov13c.cpp: At global scope:
sketch_nov13c:101: error: expected declaration before ‘}’ token
Any help would be appreciated, I did get the arduino working with a non-canbus cluster from a 1998 EL Falcon but don’t want to use that…
Cheers in advance guys
Edit: I added the CAN library and noticed that aswell as it being orange in the code it is also in bold. is this normal or do I have a issue somewhere?