Tuesday 24 November 2020

Arduino dash control

To get started with the arduino dash control I first controlled the dash using the Arduino with set values rather than values read from the CAN bus of the imiev.
This video here shows the startup sweep I made the tacho do, unfortunately there isnt a quick enough response from the temp and fuel gauges to do this to them too.

 
Here is the code I made to run the Tacho gauge, unfortunately I wasn't able the get the MPG gauge working at all and struggled to get the fuel gauge to be consistent so i wont be using them and instead will be using an LCD screen later on to display the data. The code to run the Temp gauge is in there its just not currently being used.
 
#include <Tone.h>  // "Tone by Brett Hagman" in Library Manager


//const byte E36TachPin =      2;  // Tone
//const byte E36MPGPin =       9;  // PWM  (Not valid PWM pin for Arduino UNO!)
//const byte E36FuelGagePin =  5;  // PWM
//const byte E36TempGagePin =  6;  // PWM



void setup()
{

  pinMode(5, OUTPUT); //Fuel
  pinMode(6, OUTPUT); //Temp
  pinMode(9, OUTPUT); //MPG
 
  //#####FUEL#####
   analogWrite(5, 165); //sets fuel to Full
    // 0=EMPTY, 10=E, 55=15L, 95=30L, 125=45L, 165=FULL
 
  //#####TEMP##### 
  analogWrite(6, 50); //sets temp to middle pos
   // 6=HOTFlashing 10=HighesTemp 15=HOTLightOn, 50=MID, 100=COLD
    // Use 10 - 100 for temp range, set 6 as a value for flashing HOT
 
  //#####TACH#####
    Tone E36TachTone;
    E36TachTone.begin(2);
    E36TachTone.play(31);
  //35=1k, 129=4k, 222=7k
  //28.5 31 31.53
  
  
  //RPM sweep
    for(int t=31; t<222; t++){
      E36TachTone.play(t);
      delay(2);
    }
    delay(500);
    for(int t=222; t>31; t--){
      E36TachTone.play(t);
      delay(2);
    }
    E36TachTone.play(31);
 
 
 
  //#####MPG#####
   // Tone E36MPGTone;
   // E36MPGTone.begin(9);
    //E36MPGTone.play(0);

}

void loop() {
  //#####TACH LOOP#####
    Tone E36TachTone;
 
  int RPM = 500;  //input RPM read from CAN here IF car is in ready state else stop RPM gauge
  int RPMt;
 
  RPMt = RPM/30.5;
 
  if (RPMt < 31){ //stops rpm gauge signal going below 31 Hz for idle(causes issues)
    RPMt = 31;
    }
 
  E36TachTone.play(RPMt);
 
 
 
  //#####MPG, TEMP, FUEL LOOP##### 
  //Tone E36MPGTone;
 
  //E36MPGTone.play(00);
      // analogWrite(5, 165); //Fuel
 
    //analogWrite(6, 50); //Temp
   
    //analogWrite(9, 0); //MPG

}





No comments:

Post a Comment