CANhack.de CAN-Interface RKS+CAN
Diesel technology, engine technology, vehicle diagnostics, repair & maintenance.

My golf5 custom dashboard

 
New Topic 🔒 Locked 🔗 🖨 CANhack.de - Index » Microcontrollers and Electronics, Programming
Author Message
muurman



Joined: 07/24/2016
Posts: 14
Karma: +4 / -1   Thank you, like it!


Free account, no CAN development support

Post21-09-2016, 20:47    Subject: My golf5 custom dashboard Translating...

[Translating...]

I have put an 3.5inch tft in my dashboard.
Back to top Profile PM
CAN-Diagnose
Administrator
Administrator
Avatar-CAN-Diagnose

Joined: 06/07/2011
Posts: 573
Karma: +29 / -0   Thank you, like it!
Location: Ländle



Post21-09-2016, 20:57    Subject: My golf5 custom dashboard Translating...

[Translating...]

Hi, that is nice, but isn't the sense of a forum to put the information there instead of using it as link farm?

You are invited to use the "Datei auswählen" button below to upload your things. icon_razz.gif
Dipl.-Ing. (FH) Rainer Kaufmann - Embedded Software Freelancer
System RKS+CAN: CANHack.de CAN-Bus Interface
Back to top Profile PM WWW
muurman



Joined: 07/24/2016
Posts: 14
Karma: +4 / -1   Thank you, like it!


Free account, no CAN development support

Post22-09-2016, 20:50    Subject: foto and arduino code Translating...

[Translating...]

I thought a link is better because this doesn't take resources on the server.
And there is a button to add an imaga as a link so... ?

but attached foto and arduino code.



You are not permitted to view these file(s), please log in or register for extended rights or status updates.

Back to top Profile PM
muurman



Joined: 07/24/2016
Posts: 14
Karma: +4 / -1   Thank you, like it!


Free account, no CAN development support

Post22-09-2016, 20:51    Subject: My golf5 custom dashboard Translating...

[Translating...]

Code:


#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
#define GREY    0x5AEB

#define Achtergrond BLACK
#define Voorgrond   WHITE
#define Labels      MAGENTA
#define Waarden     WHITE

#include <mcp_can> // can-bus

#include <SPI>          // f.k. for Arduino-1.5.2
#include "Adafruit_GFX.h"// Hardware-specific library
#include <MCUFRIEND_kbv>


MCUFRIEND_kbv tft;


int KleurMeterRand = GREY;
int KleurMeterStreep = WHITE ;

int LaatsteTurboWaarde = 0 , LaatsteRPMWaarde = 0 , LaatsteSnelheidWaarde = 0;

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];

unsigned char rxBufSerieel[16];
//int Ypos=5;
int WaardenGrote=3;

long KmStand=0;
String strSerial="";
String tijd="00:00:00";
String Melding, KnipperLicht,Rem, HexString;
int coolant=0,coolantnew=0, tdruk=0, rpm=0,rpmnew=0 , snelheid=0, SnelheidVorig=0, olie=0,olienew=0 , brandstof=0;
int teller35b ,  teller351 ;
int uur , minuut , seconde ;
int Scherm=1;

// Meter

float M_SIZE=1;
float Yoffset=3.5;
float Xoffset=1;

float ltx = 0;    // Saved x coord of bottom of needle
uint16_t osx = M_SIZE*120, osy = M_SIZE*120; // Saved x & y coords
uint32_t updateTime = 0;       // time for next update

int MeterMin=-90 ,MeterMax=90;

int old_analog =  -999; // Value last displayed

int value[6] = {0, 0, 0, 0, 0, 0};
int old_value[6] = { -1, -1, -1, -1, -1, -1};
int d = 0;

int NeedleMin=-180;
int NeedleMax=180;
int i2 ;
int j=0;



MCP_CAN CAN0(10);                               // Set CS to pin 10

void drawBarTurbo (int nPer){
  int y = 136;
  if(nPer < LaatsteTurboWaarde){
    tft.fillRect(10 + nPer, y , LaatsteTurboWaarde - nPer, 10,  Achtergrond);     
  }
  else{
    tft.fillRect( 10 + LaatsteTurboWaarde, y , nPer - LaatsteTurboWaarde, 10 ,  WHITE);
  }   
  LaatsteTurboWaarde = nPer;   
}

void drawBarRPM (int nPer){
  int y = 211;
int   factor = 1;
  if(nPer < LaatsteRPMWaarde){
    tft.fillRect(10 + nPer, y , LaatsteRPMWaarde / factor - nPer / factor, 10,  Achtergrond);     
  }
  else{
    tft.fillRect( 10 + LaatsteRPMWaarde / factor, y , nPer - LaatsteRPMWaarde / factor, 10 ,  WHITE);
  }   
  LaatsteRPMWaarde = nPer;   
}


void drawBarSnelheid (int nPer){
  int y = 270+1;
  float factor = 1;
  if(nPer < LaatsteSnelheidWaarde){
    tft.fillRect(10 + nPer, y , LaatsteSnelheidWaarde * factor - nPer * factor, 10,  Achtergrond);     
  }
  else{
    tft.fillRect( 10 + LaatsteSnelheidWaarde * factor, y , nPer - LaatsteSnelheidWaarde * factor, 10 ,  WHITE);
  }   
  LaatsteSnelheidWaarde = nPer;   
}

void TFTprint(int X, int Y,  uint16_t Kleur ,int tsize, String txt)
{
     tft.setTextSize(tsize);
     tft.setTextColor(Kleur);
     tft.setCursor(X, Y);
     tft.print(txt);
  }

void plotNaald(int NaaldPunt, float Xoffset, float Yoffset, float M_SIZE  ,char Kleur )
{
   float sx = cos((NaaldPunt - 90) * 0.0174532925 );
   float sy = sin((NaaldPunt - 90) * 0.0174532925 );

   uint16_t x1 = sx * M_SIZE*100 + M_SIZE*120*Xoffset;
   uint16_t y1 = sy * M_SIZE*100 + M_SIZE*140*Yoffset;

   tft.drawLine(120*Xoffset*M_SIZE, 140*Yoffset*M_SIZE, x1, y1, Kleur);
}

void plotKorteNaald(int NaaldPunt, float Xoffset, float Yoffset, float M_SIZE  ,char Kleur )
{
    float sx = cos((NaaldPunt - 90) * 0.0174532925 );
    float sy = sin((NaaldPunt - 90) * 0.0174532925 );
    int tl = 20;
    uint16_t x0 = sx * (M_SIZE*100 - tl) + M_SIZE*120*Xoffset;
    uint16_t y0 = sy * (M_SIZE*100 - tl) + M_SIZE*140*Yoffset;
    uint16_t x1 = sx * M_SIZE*100 + M_SIZE*120*Xoffset;
    uint16_t y1 = sy * M_SIZE*100 + M_SIZE*140*Yoffset;
    tft.drawLine(x0, y0, x1, y1, Kleur);
 
}

void streepMeter(float Xoffset,float Yoffset,float M_SIZE,int i,int tl)
{

    float sx = cos((i - 90) * 0.0174532925 );
    float sy = sin((i - 90) * 0.0174532925 );
    //tl = +
    uint16_t x0 = sx * (M_SIZE*100 + tl) + M_SIZE*120*Xoffset;
    uint16_t y0 = sy * (M_SIZE*100 + tl) + M_SIZE*140*Yoffset;
    uint16_t x1 = sx * M_SIZE*100 + M_SIZE*120*Xoffset;
    uint16_t y1 = sy * M_SIZE*100 + M_SIZE*140*Yoffset;
    tft.drawLine(x0, y0, x1, y1, KleurMeterStreep);
}

void WaardeMeter(float Xoffset,float Yoffset,float M_SIZE,int i,String txt)
{
   int tl=15;
    float sx = cos((i - 90) * 0.0174532925 );
    float sy = sin((i - 90) * 0.0174532925 );
   
    uint16_t x0 = sx * (M_SIZE*100 + tl) + M_SIZE*120*Xoffset;
    uint16_t y0 = sy * (M_SIZE*100 + tl) + M_SIZE*140*Yoffset;
    uint16_t x1 = sx * M_SIZE*100 + M_SIZE*120*Xoffset;
    uint16_t y1 = sy * M_SIZE*100 + M_SIZE*140*Yoffset;
    int x = x0-txt.length()/2*18;
    TFTprint( x, y0-20,Waarden,2,txt);
   
}



void analogMeter(float Xoffset,float Yoffset,float M_SIZE)
{


  // Draw ticks every 5 degrees from -50 to +50 degrees (100 deg. FSD swing)
  for (int i = MeterMin; i <MeterMax> vorig)
 
  for ( int j = vorig; j < huidig; j +=1 )
  {
   
   //int jj = j * 0.036 - MeterMax;
   int jj = j  - MeterMax;
    plotKorteNaald(jj,Xoffset,Yoffset,M_SIZE,BLUE); }

if (huidig <vorig> huidig; j -=1 )
  {
    //int jj = j * 0.036 - MeterMax;
   
    int jj = j  - MeterMax;
    plotKorteNaald(jj,Xoffset,Yoffset,M_SIZE,Achtergrond); }

 
}






void setup()
{

  Serial.begin(115200);
// Serial.println("MCP2515 Library Receive Example...");


  tft.reset();

uint16_t identifier = tft.readID();

  // tft.begin(37697);
   //tft.begin(37672);  //test
   //tft.begin(0x9325);  //test
  //  tft.begin(0x9481); // 0x9488 3.5inch
   tft.begin(identifier);
   
  tft.fillRect(0,0,320,480,Achtergrond);
  TFTprint(10,10,Labels,2,"Welkom Bestuurder");
  TFTprint(10,30,Labels,2,"Gaspedaal zit rechts");
  TFTprint(10,50,Labels,2,"Koppeling zit links");
  TFTprint(10,70,RED,2,"Rem .. afblijven");
 
  delay(6000);
  CAN0.begin(CAN_100KBPS);                       // init can bus :
 
  scherm1Opbouw();
 
   
teller35b = 10;
teller351=10;

  KnipperLicht = "<>";
  TFTprint(196,430,YELLOW,3,KnipperLicht);
  delay(1000);
  TFTprint(196,430,Achtergrond,3,KnipperLicht);
analogWrite(A5,1023);
 
 
   
}
void scherm1Opbouw()
{
  tft.fillRect(0,0,320,480,Achtergrond);
 
  TFTprint(5,50,Labels,2,"Coolant/Oil");
  TFTprint(5,85,Labels,2,"Turbo");
  TFTprint(130,85,Labels,2,"Fuel");
  TFTprint(5,125,Labels,2,"RPM");
  M_SIZE=1;
  Yoffset=2.9;
  Xoffset=1.2;
  analogMeter(Xoffset,Yoffset,M_SIZE);

  for (int i = 0; i < 5000; i += 100)
  {
  j = i * 0.036 - MeterMax;
  int tl = 10;
  if ( i == 1000 or i == 1500 or i == 2000 or i == 2500 or i == 3000 or i == 3500 or i == 4000 ) {tl=20;}
  if ( i == 2500) {WaardeMeter(Xoffset,Yoffset,M_SIZE,j,"2500");}
  streepMeter(Xoffset,Yoffset,M_SIZE,j,tl);
  } 
}

void scherm1Waarden()
{
   
      CAN0.readMsgBuf(&len, rxBuf);              // Read data: len = data length, buf = data byte(s)
      rxId = CAN0.getCanId();                    // Get message ID
if ( rxId == 0x10 )
{   
    // vanaf andere arduino


if ( rxId == 0x621 )
{   
  // byte 0 handrem geeft 20
  // ook wellicht deur
   
    TFTprint(190,85,Achtergrond,WaardenGrote,String(brandstof));
     brandstof = rxBuf[3] ;
    bitWrite(brandstof,7,0);
     TFTprint(190,85,Waarden,WaardenGrote,String(brandstof));
    TFTprint(210,150,Achtergrond,6,"T");
    if ( brandstof <6> 1 )
   {
    teller35b = 0;
    coolantnew = (rxBuf[3]-32)/1.8;
    if (coolant-coolantnew>2 or coolant-coolantnew<2>20 or rpmnew-rpm<20 )
      {
        TFTprint(60,125,Achtergrond,WaardenGrote,String(rpm));
        MeterWaarde(rpm * 0.036,rpmnew * 0.036);
        rpm=rpmnew;
        if ( rpm <4000> 1700) {TFTprint(60,125,Waarden,WaardenGrote,String(rpm));}
        if ( rpm <1700> 4000 ) {TFTprint(60,125,MAGENTA,WaardenGrote,String(rpm));}
       
      }
   }
  }

if ( rxId == 0x555 )
{
   
      TFTprint(70,85,Achtergrond,WaardenGrote,String(tdruk));
      tdruk = rxBuf[4];
      TFTprint(70,85,Waarden,WaardenGrote,String(tdruk));
     
      olienew = (rxBuf[7]-32)/1.8;
      if (olienew-olie>2 or olienew-olie<2> 1)
    // if ( SnelheidVorig != snelheid )
     {
      teller351=0;

      snelheid=(rxBuf[2]*256+(rxBuf[1]-1))/200;
      //MeterWaarde(SnelheidVorig,snelheid);
      TFTprint(100,350,Achtergrond,6,String(SnelheidVorig));
      TFTprint(100,350,Waarden,6,String(snelheid)); 
      SnelheidVorig = snelheid;
      }
   
   }



if ( rxId == 0x65D )
{
    TFTprint(5,12,Achtergrond,3,String(KmStand));
    KmStand=(rxBuf[3]*65536+rxBuf[2]*256+rxBuf[1]);
    TFTprint(5,12,Waarden,3,String(KmStand));

  uur=00 ; minuut=00 ; seconde=00 ;
  bitWrite(uur,4,bitRead(rxBuf[6],0));
  bitWrite(uur,3,bitRead(rxBuf[5],7));
  bitWrite(uur,2,bitRead(rxBuf[5],6));
  bitWrite(uur,1,bitRead(rxBuf[5],5));
  bitWrite(uur,0,bitRead(rxBuf[5],4));

  bitWrite(minuut,5,bitRead(rxBuf[6],6));
  bitWrite(minuut,4,bitRead(rxBuf[6],5));
  bitWrite(minuut,3,bitRead(rxBuf[6],4));
  bitWrite(minuut,2,bitRead(rxBuf[6],3));
  bitWrite(minuut,1,bitRead(rxBuf[6],2));
  bitWrite(minuut,0,bitRead(rxBuf[6],1));

//  bitWrite(seconde,5,bitRead(rxBuf[7],4));
//  bitWrite(seconde,4,bitRead(rxBuf[7],3));
//  bitWrite(seconde,3,bitRead(rxBuf[7],2));
//  bitWrite(seconde,2,bitRead(rxBuf[7],1));
//  bitWrite(seconde,1,bitRead(rxBuf[7],0));
//  bitWrite(seconde,0,bitRead(rxBuf[6],7));

TFTprint(216,12,Achtergrond,3,tijd);
tijd = String(uur) + ":" + String(minuut)   ;
TFTprint(216,12,Waarden,3,tijd);
}

if ( rxId == 0x531  )
  {
    TFTprint(6,430,Achtergrond,4,Melding);
    TFTprint(196,430,Achtergrond,6,KnipperLicht);

    if ( ( rxBuf[1] == 0x11 ) or ( rxBuf[1] == 0x51 ) )
    {
     KnipperLicht = "<TFTprint> 1 )
   {
    teller35b = 0;
    coolantnew = (rxBuf[3]-32)/1.8;
    if (coolant-coolantnew>2 or coolant-coolantnew<2>20 or rpmnew-rpm<20 )
      {
        TFTprint(60,160,Achtergrond,6,String(rpm));
        rpm=rpmnew;
        if ( rpm <4000> 1700) {TFTprint(60,160,Waarden,6,String(rpm));}
        if ( rpm <1700> 4000 ) {TFTprint(60,160,MAGENTA,6,String(rpm));}
        drawBarRPM(rpm/20);
       
      }
   }
  }

if ( rxId == 0x555 )
{
   
      TFTprint(70,85,Achtergrond,6,String(tdruk));
      tdruk = rxBuf[4];
      TFTprint(70,85,Waarden,6,String(tdruk));
      drawBarTurbo(String(tdruk).toInt());
     
      olienew = (rxBuf[7]-32)/1.8;
      if (olienew-olie>2 or olienew-olie<2> 1)
    // if ( SnelheidVorig != snelheid )
     {
      teller351=0;

      snelheid=(rxBuf[2]*256+(rxBuf[1]-1))/200;
      drawBarSnelheid(snelheid);
      //MeterWaarde(SnelheidVorig,snelheid);
      TFTprint(80,350,Achtergrond,10,String(SnelheidVorig));
      TFTprint(80,350,Waarden,10,String(snelheid)); 
      SnelheidVorig = snelheid;
      }
   
   }



if ( rxId == 0x65D )
{
    TFTprint(5,12,Achtergrond,3,String(KmStand));
    KmStand=(rxBuf[3]*65536+rxBuf[2]*256+rxBuf[1]);
    TFTprint(5,12,Waarden,3,String(KmStand));

  uur=00 ; minuut=00 ; seconde=00 ;
  bitWrite(uur,4,bitRead(rxBuf[6],0));
  bitWrite(uur,3,bitRead(rxBuf[5],7));
  bitWrite(uur,2,bitRead(rxBuf[5],6));
  bitWrite(uur,1,bitRead(rxBuf[5],5));
  bitWrite(uur,0,bitRead(rxBuf[5],4));

  bitWrite(minuut,5,bitRead(rxBuf[6],6));
  bitWrite(minuut,4,bitRead(rxBuf[6],5));
  bitWrite(minuut,3,bitRead(rxBuf[6],4));
  bitWrite(minuut,2,bitRead(rxBuf[6],3));
  bitWrite(minuut,1,bitRead(rxBuf[6],2));
  bitWrite(minuut,0,bitRead(rxBuf[6],1));

//  bitWrite(seconde,5,bitRead(rxBuf[7],4));
//  bitWrite(seconde,4,bitRead(rxBuf[7],3));
//  bitWrite(seconde,3,bitRead(rxBuf[7],2));
//  bitWrite(seconde,2,bitRead(rxBuf[7],1));
//  bitWrite(seconde,1,bitRead(rxBuf[7],0));
//  bitWrite(seconde,0,bitRead(rxBuf[6],7));

TFTprint(216,12,Achtergrond,3,tijd);
tijd = String(uur) + ":" + String(minuut)   ;
TFTprint(216,12,Waarden,3,tijd);
}

if ( rxId == 0x531  )
  {
    TFTprint(6,430,Achtergrond,4,Melding);
    TFTprint(196,430,Achtergrond,6,KnipperLicht);

    if ( ( rxBuf[1] == 0x11 ) or ( rxBuf[1] == 0x51 ) )
    {
     KnipperLicht = "<";
     TFTprint(196,430,YELLOW,6,KnipperLicht);
    }

    if (( rxBuf[1] == 0x12 ) or ( rxBuf[1] == 0x52 ) )
    {
     KnipperLicht = ">";
     TFTprint(196,430,YELLOW,6,KnipperLicht);
    }
   
     
    if ( rxBuf[0] == 0x0 )
    {
     Melding = "L";
     TFTprint(6,430,RED,4,Melding);
    }

    if ( rxBuf[0] == 0xc3 )
    {
     Melding = "L";
     TFTprint(6,430,GREEN,4,Melding);
    }
  }
   
 
}



void logserieel()
{
  Serial.println("");
  Serial.print(rxId,HEX);
  Serial.print(",");
      for(int i = 0; i<len; i++)                // Print each byte of the data
      {
        if(rxBuf[i] < 0x10)                     // If data byte is less than 0x10, add a leading zero
        {
          Serial.print("0");
        }
       Serial.print(rxBuf[i],HEX);
       Serial.print(",");
      }
}

void logscherm()
{
//     TFTprint(0,265,Achtergrond,2,HexString);
//     HexString = String(rxBuf[0], HEX) + " "+String(rxBuf[1], HEX) + " "+String(rxBuf[2], HEX) + " "+String(rxBuf[3], HEX) + " "+String(rxBuf[4], HEX) + " " + String(rxBuf[5], HEX) + " " + String(rxBuf[6], HEX) + " " + String(rxBuf[7], HEX) ;
//     TFTprint(0,265,Waarden,2,HexString);
}

void loop()
{

if ( analogRead(A5) == 0 )
  {
    Scherm++ ;
    delay(500);
    analogWrite(A5,1023);
     tft.fillRect(0,0,320,480,Achtergrond);
    if ( Scherm == 3 ){Scherm = 1;}
    if (Scherm == 1 ) { scherm1Opbouw(); }
    if (Scherm == 2 ) { scherm2Opbouw(); }
  }

if (Scherm == 1 ) { scherm1Waarden() ; }
if (Scherm == 2 ) { scherm2Waarden() ; }



}


Back to top Profile PM
CAN-Diagnose
Administrator
Administrator
Avatar-CAN-Diagnose

Joined: 06/07/2011
Posts: 573
Karma: +29 / -0   Thank you, like it!
Location: Ländle



Post22-09-2016, 21:46    Subject: My golf5 custom dashboard Translating...

[Translating...]

Looks very nice, which information do/can you show on your TFT?

Best, Rainer
Dipl.-Ing. (FH) Rainer Kaufmann - Embedded Software Freelancer
System RKS+CAN: CANHack.de CAN-Bus Interface
Back to top Profile PM WWW
muurman



Joined: 07/24/2016
Posts: 14
Karma: +4 / -1   Thank you, like it!


Free account, no CAN development support

CAN-Diagnose likes this.
Post23-09-2016, 14:00    Subject: My golf5 custom dashboard Translating...

[Translating...]

I can show everything which i would if i know what all can-bus messages mean.
At this moment i show:
km's the car has driven
time
coolant temp
oil temp
turbo pressure
fuel status
rpm
speed
Back to top Profile PM
Mackhack



Joined: 10/10/2012
Posts: 17
Karma: +0 / -0   Thank you, like it!
Location: Offline

CAN Support

Post01-01-2017, 5:09    Subject: My golf5 custom dashboard Translating...

[Translating...]

Very interesting. Kudos to you for your ingenuity and work.
Mackhack
Back to top Profile PM
irobles



Joined: 06/13/2017
Posts: 3
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post14-06-2017, 14:31    Subject: My golf5 custom dashboard Translating...

[Translating...]

Hello,

Which can-bus shield do you use? It has 2 can interfaces or only one?

Thanks
Back to top Profile PM
jeroenveer



Joined: 07/23/2014
Posts: 3
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post13-11-2017, 16:52    Subject: My golf5 custom dashboard Translating...

[Translating...]

Cool
Back to top Profile PM
Splasher



Joined: 02/02/2018
Posts: 1
Karma: +0 / -0   Thank you, like it!


Free account, no CAN development support

Post02-02-2018, 11:15    Subject: My golf5 custom dashboard Translating...

[Translating...]

Wow! Looks very nice!

Respect for your work and thanks a lot for the code!
Back to top Profile PM
New Topic 🔒 Locked 🔗 🖨 CANhack.de - Index » Microcontrollers and Electronics, Programming
Similar articles and topics
Topic Forum
No new posts Golf 7 instrument cluster, gaming dashboard CAN Bus General
No new posts VW Golf 5 interior fan Interior / Comfort CAN
No new posts Suche Aufzeichnung von GOLF5 Komfortcan Interior / Comfort CAN
No new posts Welcher CAN-Bus wird im Golf5 verwendet? CAN Bus General
Jump to:  
You cannot post new topics in this forum.