Go Down

Topic: code for 2560 R3 and secuduino canshield (Read 1 time) previous topic - next topic

skotty

Nov 13, 2012, 01:25 pm Last Edit: Nov 13, 2012, 01:31 pm by skotty Reason: 1
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...
Code: [Select]
   #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...

Quote
'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?

PaulS

Which version of the IDE are you using? If 1.0.1 or later, try on 1.0.0. I'm guessing that the compiler is not telling you that it can't find the CAN.h file. It will on 1.0.0, if that is the problem. If it is, then fix that problem, then compile on 1.0.1+.

skotty

Thanks Paul I'll have a look for 1.0.0, I currently have 1.0.1 installed.

skotty

Just installed IDE 1.0 and I get the same error message there too.. I can put up a screen shot if that makes any difference?

PaulS


skotty

From http://secuduino.blogspot.com.au/ they e-mailed it to me after I ordered the can-shield from them.

You can see what I mean here by down CAN is in bold. it didn't seem right to me...


PaulS

You're going to need to share the contents of CAN.h if you want help.

skotty

No worries, just posted it, this is the attachment that they sent me.

http://www.users.on.net/~skotty_87/

PaulS

I copied the library to the proper place. Then, I pasted your code into the Arduino 1.0.1 IDE, and tried to compile. I did NOT get the "CAN does not name a type" message, but I did get a whole series of other messages that indicate that the sketch is junk. It bears no resemblance to code that deals with the CAN class.

skotty

ahh ok.. would someone be able to give me a bit of a heads up on how to start a sketh to use the CAN and get needle sweet on the instrument cluster at all please? thanks.

skotty

So I gave this a crack, but didn't make any difference, would someone be able to have a look at this and give me some points? thanks..

Code: [Select]
#include <CAN.h>
int CAN:
int rpm;
int kmh;
void setup(){
  CAN.begin(1);
  Serial.begin(115200);
  CAN_TxMsg.id=0x201;
  CAN_TxMsg.header.rtr=0;
  CAN_TxMsg.header.length=8;
  kmh=175;
  rpm=6250;
}
void loop(){
  CAN_TxMsg.data[0] = (rpm * 4) / 256;
  CAN_TxMsg.data[1] = (rpm * 4) % 256;
  CAN_TxMsg.data[2] = 0xFF;
  CAN_TxMsg.data[3] = 0xFF;
  CAN_TxMsg.data[4] = (kmh+10000) / 256;
  CAN_TxMsg.data[5] = (kmh+10000) % 256;
  CAN_TxMsg.data[6]=0x00;
  CAN_TxMsg.data[7]=0x00;
  CAN.send(&CAN_TxMsg);
  delay(5);
}

PaulS

Quote
but didn't make any difference

One code failed to compile, so you butchered the definition of CAN, and expect that to work better?

The int "class" doesn't have a begin() method. Or a send() method.

The library came with an example. Did you even look at it?

skotty


Quote
but didn't make any difference

One code failed to compile, so you butchered the definition of CAN, and expect that to work better?

The int "class" doesn't have a begin() method. Or a send() method.

The library came with an example. Did you even look at it?


Even the examples give errors that CAN wasnt declared in the scope.

Cybernetician

Reply #5
Quote
From http://secuduino.blogspot.com.au/ they e-mailed it to me after I ordered the can-shield from them.

You can see what I mean here by down CAN is in bold. it didn't seem right to me...

Reply #5  In Picture it is clear you didnot pass any value in CAN.begin() why? you need to pass value.
Code: [Select]
//Let's open the bus. Remember the input parameter:
  //  1: 1Mbps
  // 500: 500Kbps  <--- Most frecuently used
  // 250: 250Kbp
  // 125: 125Kbps
  CAN.begin(1);


Quote
So I gave this a crack, but didn't make any difference, would someone be able to have a look at this and give me some points? thanks..

Reply #10

what do you mean by that line in your code int CAN: if you want to declare any variable please choose another name

Quote
Even the examples give errors that CAN wasnt declared in the scope.


which example you execute show it's snapshot

and finally what i want to say, "check your IDE by executing blink example if IDE is ok where you put CAN library post it's path"
From Idea To Invention

Go Up