Instrument cluster code too complicated

I've managed to get my hands on a bmw e36 instrument cluster, and the next step is to manage to make the speedometer, rev counter, fuel and coolant temp work. I do believe i have to use the PWM to keep the motor at a given position, although i have not managed yet. I found someone who has managed, and got the code, but it is way to complicated to read or even understand at least 20% of it. My humbly request is if someone is willing to take a look and erase the non essentials (i.e. comunication between other arduinos ) and explain a little what is going on there. all i want for the moment is to manage to move the damn rev counter.

This is the link to the working cluster.

The code is too long to post it as a message.

I have also attached the code as a file, but it can be downloaded from the link also.

DisplayClientV2.ino (62.4 KB)

I guess from your post, the program does not do what you want. Then, what does it do and how have you tried to correct it?

Paul

no, i have not uploaded it on the arduino because i don't understand exactly what it does. what i want to do is use a pin for each motor ( gauge) and move it. the cluster is powered by a 12 v source, it has a common ground with the arduino, and the pins are connected to each responsible pin on the cluster. yes, i have identified the correct pins. the code is too complex, full of many things i do not need. for example, the nokia display code is not useful, but i have not worked with that sort of item, so i can't know what i need/can delete from it

syka2210:
My humbly request is if someone is willing to take a look and erase the non essentials

It is a bit unreasonable to expect someone to study and figure out how 62k of code works.

Can't you ask the guy who wrote it?

...R

Hi syka2210

The tacho seems to be controlled by a function called rpmTone.
The sketch you provided makes a couple of calls:

rpmTone.begin(pinTacho);

and

rpmTone.play(freq);

without having access to the rest of the code (SimHud is big) I would say that rpmTone.begin() sets up the pin mode.
rpmTone.play will both produce a sound on external hardware, and also produce a pulse (freq) on the pin assigned to pinTacho

If you are trying to use this cluster to build your own Hud using SimHud, I would recommend that you spend some time on the forums there.

If you're wanting something else, start by applying pulse frequencies to the pin and see what happens :slight_smile:

Cheers...

@darrob thank you. that's exactly what i wanted to find out. i will start experimenting with PWM, probably using microseconds pause.

I think you’ll find the gauges are driven by stepper motors, you could use some of the stepper library examples to drive them .
I’ve read somewhere on this forum that someone is developing some code specifically for this type of motor.

I think this is the only part of that mess that you need:

#include <Tone.h>  // "Tone by Brett Hagman" in Library Manager


const byte E36TachPin =      2;  // Tone
const byte E36SpeedPin =     3;  // Tone
const byte E36MPGPin =       4;  // PWM  (Not valid PWM pin for Arduino UNO!)
const byte E36FuelGagePin =  5;  // PWM
const byte E36BoostGagePin = 5;  // PWM  (CONFLICT!)
const byte E36TempGagePin =  6;  // PWM


Tone E36SpeedTone;
Tone E36TachTone;


void setup()
{
  E36SpeedTone.begin(E36SpeedPin);
  E36TachTone.begin(E36TachPin);
}


void loop() {}


void E36Cluster(int speed, int tach, int mpg, int fuel, int boost)
{
  // Map some values to new ranges
  int speedoutput = map(speed, 0, 286,   0, 367);  // Tone
  int mpgoutput   = map(mpg,   0, 100, 255,   0);  // PWM
  int fueloutput  = map(fuel,  0, 100,   0, 162);  // PWM


  analogWrite(E36BoostGagePin, boost);


  if (speedoutput > 0)
  {
    E36SpeedTone.play(speedoutput);
  }
  else
  {
    E36SpeedTone.stop();
  }


  if (tach > 0)
  {
    E36TachTone.play(tach);
  }
  else
  {
    E36TachTone.stop();
  }


  analogWrite(E36MPGPin, mpgoutput); // Mpg Gauge
  analogWrite(E36FuelGagePin, fueloutput); // Fuel Gauge
  analogWrite(E36TempGagePin, 50); //Temp Gauge set to Midway
}

johnwasser:
I think this is the only part of that mess that you need:

....

Where did you manage to find that lot? None of that code is in the sketch provided!
Fantastic bit of help. Kudos :slight_smile:

darrob:
Where did you manage to find that lot? None of that code is in the sketch provided!
Fantastic bit of help. Kudos :slight_smile:

It was all in there, just poorly written and widely disbursed. I extracted the useful parts and cleaned up the code to make it readable. I don't know why Pin 5 is being used for two separate PWM outputs or why Pin 4 is being used with analogWrite().

How did you do the wiring, can you please help me understand what pins you connected to the arduino and cluster to get the speed and rpm wokring.