Arduino real car cluster

Hello there, i am trying to connect an BMW e46 cluster to arduino+can bus. I watched all the youtube and google everywhere but i don`t know how to get far afther connecting the can high and can low to can bus. I also tryed some arduino codes but still nothing.I am trying to play racing games.

THX!

Post your program so we can see what you can see.

And please use the code button </>so your code looks like thisand is easy to copy to a text editor

...R

int rpm;
int Speed;
int fuel;
int turbo;
char kind_of_data;

void setup(){

 Serial.begin(115200); 

 pinMode(0, OUTPUT);
 pinMode(1, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT);

 calibration();
}



void loop()
{
 //****************************** READ DATA FROM SERIAL ******************************
 while(Serial.available() > 0)
 {

   kind_of_data = Serial.read();
   //if (kind_of_data == 'R' ) Read_Rpm();
   if (kind_of_data == 'S' ) Read_Speed();
   if (kind_of_data == 'F' ) Read_Fuel();
   if (kind_of_data == 'T' ) Read_Turbo();
   //if (kind_of_data == 'E' ) Read_EBrake();
   //if (kind_of_data == 'B' ) Read_Brake();

 }
 //****************************** READ DATA FROM SERIAL END ******************************
}

void  Read_Rpm(){

 delay(1);
 int Rpm100 = Serial.read()- '0';
 delay(1);
 int Rpm10 = Serial.read()- '0';
 delay(1);
 int Rpm1 = Serial.read()- '0';

 int rpm = 100*Rpm100 + 10*Rpm10 + Rpm1;
}

void Read_Speed(){

 delay(1);
 int Speed100 = Serial.read()- '0';
 delay(1);
 int Speed10 = Serial.read()- '0';
 delay(1);
 int Speed1 = Serial.read()- '0';

 Speed = 100*Speed100 + 10*Speed10 + Speed1;
 analogWrite(9,map(Speed,127,255,17,155)); 
}

void Read_Fuel(){
 delay(1);
 int Fuel100 = Serial.read()- '0';
 delay(1);
 int Fuel10 = Serial.read()- '0';
 delay(1);
 int Fuel1 = Serial.read()- '0';

 fuel = 100*Fuel100 + 10*Fuel10 + Fuel1;
 analogWrite(10,map(fuel,127,255,110,255)); 
} 

void Read_Turbo(){
 delay(1);
 int Turbo100 = Serial.read()- '0';
 delay(1);
 int Turbo10 = Serial.read()- '0';
 delay(1);
 int Turbo1 = Serial.read()- '0';

 turbo = 100*Turbo100 + 10*Turbo10 + Turbo1;
 analogWrite(11,map(turbo,127,255,30,255)); 
} 

void setAircore(float pos){
 pos = pos/40.58;

 float sinCoilValue = 255*sin(pos);
 float cosCoilValue = 255*cos(pos);

 if (sinCoilValue<=0) {
   digitalWrite(0, LOW); 
   digitalWrite(1, HIGH); 
 } 
 else {
   digitalWrite(0, HIGH);
   digitalWrite(1, LOW); 
 }
 if (cosCoilValue<=0) {
   digitalWrite(8, LOW); 
   digitalWrite(4, HIGH); 
 } 
 else {
   digitalWrite(8, HIGH); 
   digitalWrite(4, LOW); 
 }

 sinCoilValue = abs(sinCoilValue);
 cosCoilValue = abs(cosCoilValue);

 analogWrite(6, sinCoilValue);
 analogWrite(5, cosCoilValue);
}

void Leds(int leds){

 digitalWrite(12, LOW);
 if ( leds == 0 ) shiftOut(7, 13, MSBFIRST, B00000000);  
 if ( leds == 1 ) shiftOut(7, 13, MSBFIRST, B00000001);  
 if ( leds == 2 ) shiftOut(7, 13, MSBFIRST, B00000011);  
 if ( leds == 3 ) shiftOut(7, 13, MSBFIRST, B00000111);  
 if ( leds == 4 ) shiftOut(7, 13, MSBFIRST, B00001111);  
 if ( leds == 5 ) shiftOut(7, 13, MSBFIRST, B00011111);  
 if ( leds == 6 ) shiftOut(7, 13, MSBFIRST, B00111111);  
 if ( leds == 7 ) shiftOut(7, 13, MSBFIRST, B01111111);  
 if ( leds == 8 ) shiftOut(7, 13, MSBFIRST, B11111111);  
 digitalWrite(12, HIGH);
}

void calibration(){

 for( int calib=0; calib<256; calib++ ){
   analogWrite(9,map(calib,0,255,17,165)); 
   analogWrite(10,map(calib,0,255,110,255)); 
   analogWrite(11,map(calib,0,255,30,255)); 
   Leds(map(calib,0,255,0,8));

   delay(15);
 }

 for( int calib=255; calib>=0; calib-- ){
   analogWrite(9,map(calib,0,255,17,165)); 
   analogWrite(10,map(calib,0,255,110,255)); 
   analogWrite(11,map(calib,0,255,30,255)); 
   Leds(map(calib,0,255,0,8));

   delay(15);
 }

 analogWrite(9,0); 
 analogWrite(10,0); 
 analogWrite(11,0); 
}

P.S It is not myne

What does your program actually do and what do you want it to do that is different.

Although you say it is not your program code, may we assume that you understand it?

...R

I dont know how to work with arduino, i am a beginer :) thats the reason i ask for help. I did a lot of research and just found what i need to buy (and i have them) but i don`t know how to make the dashboard to work for games.

Sorry...

If you have any tips or a code that should work, please tell me. I am trying to make it to work from 2 months.

If you don't know enough to describe the problem I can't see how I can help. It sounds like someone buying all the ingredients without ever having learned to cook.

I think your first step is to learn the Arduino system (learn basic cooking). There are lots of example programs with the Arduino IDE (the programming system) and there are lots of online tutorials.

...R

I saw on youtube like everybody used something different, like X-Sim but i dont know how to use because doesnt recognise my cluster. I would like a special training only for clusters but theres no such of tutorials

The problem is that nothing it is happening when i upload the code... i recieve data from can high+low but nothing it is happening

So how do you know that it's receiving? There must be something that happens to show you this.

Looking at the code you posted, it's highly dependent on the data coming in at a consistent rate. If the sender falters for even a millisecond, then your fixed delays will cause you to read the wrong thing. All of those delay(1); lines should be replaced with while(!Serial.available()); although even that is a little too simple for real-world use.

Hi,
Can you tell us your electronics, programming, arduino, hardware experience?

Thankyou.. Tom... :slight_smile:

This looks like a very long running thread :wink:

Unfortunately I couldn't find any information about the cluster, but it looks to me like a RC model car interface?
Please post a link to the data sheet or any other description of the BWMBMW e46 cluster.
Edit: Thanks for finding this typo, my search used the correct term.

First of all, the posted code uses the Serial device, which is also used for uploading sketches to the Arduino. This means that you cannot connect anything to the Rx/Tx pins while uploading a sketch. If your CAN module connects to these pins, you have to disconnect it before any upload, and connect it again afterwards.

For testing the code I'd suggest that you use the Serial Monitor instead of the CAN module. Do you know how to open the Serial Monitor window?
Then you can start entering characters in the Serial Monitor, and see what the code will make of them. As already mentioned in this thread, replace all delay(1) lines by
if (!Serial.available()) ;

Next comes what you expect to see. All input is reflected by analogWrite(), which outputs PWM signals on various pins. You have to connect a meter or LED (and resistor) to these pins, if you want to see something. Can you post a circuit diagram of your hardware setup?

The recognized commands consist of a capital character followed by 3 digits. If you connected a LED to pin 11, you can enter e.g. "S100" (without the quotes) to "S255", to make that LED shine more or less bright. See ReadSpeed() for details.

Can you make that work so far?

Hi,
I think BMW e46 rather than BWM e46.

Tom.. :slight_smile:

Hi,
BMW e64 cluster.


Okay you have a cluster, when you connect canbus to it what do you expect to get?
The cluster on its own, not connected to a car.
You will probably get nothing, as the cluster is a device that relies on input from external sources to use on its display.
So it cannot put speed, fuel etc info on the canbus as that is the job of the speed sensor and fuel level sender.

I think you want to use it to interface with a PC game. the PC game will supply the information, and the arduino canbus will put that info on the canbus for the cluster to use.

Can you tell us your electronics, programming, arduino, hardware experience?

Tom.... :slight_smile:

int rpm;
int Speed;
int fuel;
int turbo;
char kind_of_data;

void setup(){

 Serial.begin(115200); 

 pinMode(0, OUTPUT);
 pinMode(1, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT);

 calibration();
}



void loop()
{
 //****************************** READ DATA FROM SERIAL ******************************
 while(Serial.available() > 0)
 {

   kind_of_data = Serial.read();
   //if (kind_of_data == 'R' ) Read_Rpm();
   if (kind_of_data == 'S' ) Read_Speed();
   if (kind_of_data == 'F' ) Read_Fuel();
   if (kind_of_data == 'T' ) Read_Turbo();
   //if (kind_of_data == 'E' ) Read_EBrake();
   //if (kind_of_data == 'B' ) Read_Brake();

 }
 //****************************** READ DATA FROM SERIAL END ******************************
}

void  Read_Rpm(){

 while(!Serial.available());
 int Rpm100 = Serial.read()- '0';
 while(!Serial.available());
 int Rpm10 = Serial.read()- '0';
 while(!Serial.available());
 int Rpm1 = Serial.read()- '0';

 int rpm = 100*Rpm100 + 10*Rpm10 + Rpm1;
}

void Read_Speed(){

 while(!Serial.available());
 int Speed100 = Serial.read()- '0';
 while(!Serial.available());
 int Speed10 = Serial.read()- '0';
 while(!Serial.available());
 int Speed1 = Serial.read()- '0';

 Speed = 100*Speed100 + 10*Speed10 + Speed1;
 analogWrite(9,map(Speed,127,255,17,155)); 
}

void Read_Fuel(){
 while(!Serial.available());
 int Fuel100 = Serial.read()- '0';
 while(!Serial.available())
 int Fuel10 = Serial.read()- '0';
 while(!Serial.available())
 int Fuel1 = Serial.read()- '0';


 analogWrite(10,map(fuel,127,255,110,255)); 
} 

void Read_Turbo(){
 while(!Serial.available())
 int Turbo100 = Serial.read()- '0';
 while(!Serial.available())
 int Turbo10 = Serial.read()- '0';
 while(!Serial.available())
 int Turbo1 = Serial.read()- '0';


 analogWrite(11,map(turbo,127,255,30,255)); 
} 

void setAircore(float pos){
 pos = pos/40.58;

 float sinCoilValue = 255*sin(pos);
 float cosCoilValue = 255*cos(pos);

 if (sinCoilValue<=0) {
   digitalWrite(0, LOW); 
   digitalWrite(1, HIGH); 
 } 
 else {
   digitalWrite(0, HIGH);
   digitalWrite(1, LOW); 
 }
 if (cosCoilValue<=0) {
   digitalWrite(8, LOW); 
   digitalWrite(4, HIGH); 
 } 
 else {
   digitalWrite(8, HIGH); 
   digitalWrite(4, LOW); 
 }

 sinCoilValue = abs(sinCoilValue);
 cosCoilValue = abs(cosCoilValue);

 analogWrite(6, sinCoilValue);
 analogWrite(5, cosCoilValue);
}

void Leds(int leds){

 digitalWrite(12, LOW);
 if ( leds == 0 ) shiftOut(7, 13, MSBFIRST, B00000000);  
 if ( leds == 1 ) shiftOut(7, 13, MSBFIRST, B00000001);  
 if ( leds == 2 ) shiftOut(7, 13, MSBFIRST, B00000011);  
 if ( leds == 3 ) shiftOut(7, 13, MSBFIRST, B00000111);  
 if ( leds == 4 ) shiftOut(7, 13, MSBFIRST, B00001111);  
 if ( leds == 5 ) shiftOut(7, 13, MSBFIRST, B00011111);  
 if ( leds == 6 ) shiftOut(7, 13, MSBFIRST, B00111111);  
 if ( leds == 7 ) shiftOut(7, 13, MSBFIRST, B01111111);  
 if ( leds == 8 ) shiftOut(7, 13, MSBFIRST, B11111111);  
 digitalWrite(12, HIGH);
}

void calibration(){

 for( int calib=0; calib<256; calib++ ){
   analogWrite(9,map(calib,0,255,17,165)); 
   analogWrite(10,map(calib,0,255,110,255)); 
   analogWrite(11,map(calib,0,255,30,255)); 
   Leds(map(calib,0,255,0,8));

   delay(15);
 }

 for( int calib=255; calib>=0; calib-- ){
   analogWrite(9,map(calib,0,255,17,165)); 
   analogWrite(10,map(calib,0,255,110,255)); 
   analogWrite(11,map(calib,0,255,30,255)); 
   Leds(map(calib,0,255,0,8));

   delay(15);
 }

 analogWrite(9,0); 
 analogWrite(10,0); 
 analogWrite(11,0); 
}

Okay i repleace everything and now it looks like this, I am trying to connect it to the PC for a better racing experience, still nothing.On the serial monitor i don`t get anything. On the can bus i get the RX led on when i turn the cluster power on

Hi,
What canbus shield are you using, link to spec/data would help.
I think you need to run a canbus library to setup the canbus protocol.

Tom... :slight_smile:

http://www.ebay.com/itm/262136734448?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

Hi,
If you read the sellers page you have the equivalent of this.

Check this site for all te information on it,

Look and read this page and download the library for it, there will be example code for you to try.

I don't know where you got the code you have, or how it is supposed to work, even if it is designed for this shield, but I would drop it and check out the examples.

Also have a good readd about canbus, it is not a simple serial comms system, the are many safety and priority protocols that are embedded in it.

Tom.... :slight_smile:
I would not consider this a beginner project, I have used the shield, just to monitor an ABS system on the lab bench and you really need to understand what is going on.
And remember you will not be monitoring the CANBUS, but trying to write to it,

THX i will try my best

Now i am reciving data from cluster and it looks like this:
¸ì>Xr|r¸ðlìÊ<XÁx8X"zèpäm>€¸->€¸4Hxüm>€¨r\r¸z
s¸$tzü<X,x¹Óðýì.XùÊr¸<aðÿm>€¸ùøð[:XùÊz3¸ø¸$tzül>¨x¸ð[:Xl>¨x¸ð[:X|tšÚt›Ú¹ðz
s¸t›Ú¹Óðz3¸t›Ú<XÂzz3¸ðçÚÚàtùùÊÚàpñXùÊðÑÚ$t›Ú8“ðr\r¸ðlìʹðèðôz
s¸8“ðè·1þð[:XàpñXm>€¸8X"zð[8Xùø8Óð¹ðþx¸8 ’ð8 “ðè—Xùø<X,x8X"zà·1þz¸ùÊ8“ðè·1þè·XÚàtùìðôz3¸$t›Ú<Xáxð[8Xr
r¸4Hzü4Hzüm>¨\tÚ8X"zl>¨z¸z3¸z3¸t›Ú¹ðþ¹ðþùø\tÚ8X"zz3¸8 ð8 ’ðìðôz
r¸m>€¸ù¸8“ðz¸t›Úì.X

It is a good sign or...