Close

KPH gauge works partially

A project log for CAN BUS Gaming Simulator

Controlling a VW CAN BUS dashboard of a Polo 6R with an Arduino and a CAN BUS shield using the Telemetry API of Euro Truck Simulator 2

leon-batailleLeon Bataille 06/19/2015 at 10:470 Comments

I found out the (or a) register that controls the kph gauge. But it reacts really strange.

The CAN register is 0x5A0.

Here is a script that provides settings for the RPM and KPH gauge as well as turning lights and backlight of the device itself. There are also many other CAN Codes. See also this list.

#include <mcp_can.h>
#include <SPI.h>

int fernlicht = 13;
int nebellicht = 12;
int bremse = 11;

int tempo = 0;
int rpm;
boolean hgb;
int blinker;
int tempBlinker;


// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

void setup()
{
  pinMode(fernlicht, OUTPUT);
  pinMode(nebellicht, OUTPUT); 
  pinMode(bremse, OUTPUT);
  
   //Initialisierung
    digitalWrite(fernlicht, HIGH);
    digitalWrite(nebellicht, HIGH);
    digitalWrite(bremse, LOW);
    delay(1000);               // wait for a second
    digitalWrite(fernlicht, LOW);
    delay(330);
    digitalWrite(nebellicht, LOW);
    
  Serial.begin(115200);
 
   
    
  
START_INIT:

    if(CAN_OK == CAN.begin(CAN_500KBPS))                   // init can bus : baudrate = 500k
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}

void loop()
{  
    tempo = 10;
    rpm = 1000;
    hgb = false;
    blinker = 3;

    //Umrechnung KMH
    tempo = tempo * 0.625 - (tempo*0.05);
    
    //Umrechnung RPM
    rpm = rpm * 0.0155;
    
    
       
  // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
    
    
    //ABS
    unsigned char stmp1[] = {0,128};
    CAN.sendMsgBuf(0x1A0, 0, 8, stmp1);
    
    
    //RPM
    unsigned char stmp4[4] = {1,0,0,rpm};
    CAN.sendMsgBuf(0x280, 0, 8, stmp4);
    
    
    //Lenkradschloss   
    unsigned char stmp6[2] = {0,128};
    CAN.sendMsgBuf(0x3D0, 0, 8, stmp6);
    

    //ESP & KMH enabled
    unsigned char stmp7[5] = {0,0,0,0,0};
    CAN.sendMsgBuf(0xDA0, 0, 8, stmp7);
   
  
    //turning lights and backlight
    unsigned char stmp5[3] = {blinker,0,hgb}; //1,0 = links; 2,0 = rechts; 3,0 = Warn
    CAN.sendMsgBuf(0x470, 0, 8, stmp5);
   
    //repeat kph signal
    for(int i=0;i<5;i++){
      
      unsigned char stmp[] = {1,128,tempo};
      CAN.sendMsgBuf(0x5A0, 0, 8, stmp);
      delay(30);
      //Serial.println(i);
     
    }
   
    
    //Read CAN-Bus
    /*
    unsigned char len = 0;
    unsigned char buf[8];

    if(CAN_MSGAVAIL == CAN.checkReceive())            // check if data coming
    {
        CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

        for(int i = 0; i<len; i++)    // print the data
        {
            Serial.print(buf[i]);Serial.print("\t");
        }
        Serial.println();
    }
    */
    
    delay(30);                       // send data per 100ms
}
The last big excluded code is to check what CAN commands go across the serial connection.

Here's a little video demonstration for this code snippet:

Thank you for your big interest in this project!

Keep following. More updates coming soon.

Discussions