1. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  2. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  3. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Driving real gauges

Discussion in 'DIY peripherals' started by fastdruid, Jun 16, 2011.

  1. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    First a quick introduction, I'm not building a simulator, I'm building a real car but found your site while looking for information on driving gauges. I see there are many projects here attempting to create their own set of gauges, involving various attempts to hack, re-engineer etc etc.

    Why go through that effort, it's easy to use real gauges, you just need to pick the right ones.

    Get yourself a set of modern instruments off something decent where the instruments are driven by CAN-bus, BMW's, Mazda's, probably Fords all have them. You'll have to research yourself which ones work but I'll show you how to use a set of Mazda RX-8 clocks.

    Get yourself an Arduino (if you haven't already got one).
    Get yourself a CAN shield (either from sparkfun or the cheaper diy one from http://www.fazjaxton.net/products/canshield/ )
    If you haven't already got 12v then get yourself an old PC power supply and hack it to provide your 12v

    Wire up the clocks to 12v (note that in the case of the RX-8 there are two power feeds, one permanent, one switched with the ign, you may want to stick a switch on the 'switched' feed).

    Now if you have the connectors then just wire up CAN-L and CAN-H to the correct pins, if you don't then you may as well take the back off the clocks and solder direct to the connector pins as its nearly impossible to get hold of the connectors.

    Now you just need to program the Arduino, exactly how you do it depends on how you want your PC to send it data but its very easy to send speed and rpm.

    The CAN-bus id's in the case of the RX-8 (and likely Mazda6 / MX-5)

    ID 300 is turn off Steering Warning Light, minimum 0.5 sec timing.
    ID 212 is abs, dsc off, traction control warning and brake warning, minimum 0.5 sec timing.
    ID 420 is temp, oil pressure gauge, coolent level, battery (alternator), oil warning and check engine light, minimum 5 second timing.
    ID 201 is Speed (Max 300.00 Km/h, 186mph [9C 40] and RPM (Max 16382 [FF FE], although scale goes non-linear after 10k), minimum 0.5 sec timing.

    [​IMG]

    If anyone is interested in more details just ask.
    • Like Like x 4
    • Informative Informative x 3
    • Winner Winner x 1
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    Forgot to mention, the Km/h and MPH display is switched purely on the button, the feed however is in Km/h, so send the speed in Km/h and use the button on the front to swap between MPH and Km/h depending on your country/preferences.
    Trip meter is *not* driven off the speedo but triggered by another CAN id.

    I can post arduino code for the RX-8 clocks if wanted.
  4. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    Here we go, this is arduino code for the RX-8 with the fazjaxton CAN shield and will 'rev' the tacho to 5500 and set speed to 100mph adjust as appropriate and enjoy.

    All you would need to do is set some way to get the speed from the PC and you are away.

    Code:
    #include <SPI.h>
    #include <CAN.h>
    
    const int message_id_201 = 0x201;
    const int message_id_212 = 0x212;
    const int message_id_231 = 0x231;
    const int message_id_420 = 0x420;
    int message_id ;
    
    
    byte message_to_send;
    
    int id;
    byte b;
    int i;
    char s[8];
    byte my_data[8];
    byte BitMap[8];
    int RPM;
    int mphspeed;
    int kmhspeed;
    
    
    void setup()
    {
      message_id=0x000;
      CAN.begin ();
      CAN.setMode (CAN_MODE_NORMAL);
       RPM=5500;
      mphspeed=100;
    
    }
    
    void loop()
    {
    
    /* Convert mph to kmh as all internal speeds are kmh*/
       kmhspeed=mphspeed * 160.9344;
       
    delay(10);
    
    /* Turn off steering Warning */
    
    if(steering == 0 ) {
       CAN.setMessageID (message_id_300);
       CAN.sendByte (0); 
    }
    
    
    /* Speedo / tacho */
    
       CAN.setMessageID (message_id_201);
       my_data[0] = (RPM * 4) / 256; // rpm
       my_data[1] = (RPM * 4) % 256; // rpm
       my_data[2] = 0xFF; // Unknown, 0xFF from 'live'.
       my_data[3] = 0xFF; // Unknown, 0xFF from 'live'.
       my_data[4] = (kmhspeed+10000) / 256; //speed
       my_data[5] = (kmhspeed+10000) % 256; //speed
       my_data[6] = 0x00; // Unknown possible accelerator pedel if Madox is correc
       my_data[7] = 0x00; //Unknown
       CAN.sendData(my_data,8); 
    
    /* Warning Lights */
    
       CAN.setMessageID (message_id_212);
       my_data[0] = 0xFE; //Unknown
       my_data[1] = 0xFE; //Unknown
       my_data[2] = 0xFE; //Unknown
       my_data[3] = 0x34; //DSC OFF in combo with byte 5 Live data only seen 0x34
       my_data[4] = 0x00; // B01000000; // Brake warning B00001000;  //ABS warning
       my_data[5] = 0x40; // TCS in combo with byte 3
       my_data[6] = 0x00; // Unknown
       my_data[7] = 0x00; // Unused
       CAN.sendData(my_data,7);
    
    /* Other gauges / warning lights */
    
       CAN.setMessageID (message_id_420);
       my_data[0] = 0x98 ; //temp gauge //~170 is red, ~165 last bar, 152 centre, 90 first bar, 92 second bar
       my_data[1] = 0x00; // something to do with trip meter 0x10, 0x11, 0x17 increments by 0.1 miles
       my_data[2] = 0x00; // unknown
       my_data[3] = 0x00; //unknown
       my_data[4] = 0x01; //Oil Pressure (not really a gauge)
       my_data[5] = 0x00; //check engine light
       my_data[6] = 0x00; //Coolant, oil and battery
       my_data[7] = 0x00; //unused
       CAN.sendData(my_data,7); 
    */
    
    /* Cruise Control Light */
    
    /*
      CAN.setMessageID (message_id_650);
      my_data[0] = 0xFF; // cruise control light 0x80 is yellow, 0xFF is green
      CAN.sendData(my_data,1); 
    */
    
    
    }  
    
    
    }
    
    
    I also know how to read the steering position sensor from the Mazda RX-8 if anyone wants to know that too just ask.
  5. abs

    abs Active Member Gold Contributor

    Joined:
    Mar 3, 2011
    Messages:
    331
    Occupation:
    consultant
    Location:
    Montreal
    Balance:
    775Coins
    Ratings:
    +64 / 0 / -0
    My Motion Simulator:
    3DOF, SCN5
    Hello, I was reading what you wrote . what about oil and water gauges?
  6. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    What about them? In the case of the RX-8 the oil gauge is tragically a fake (CAN ID 420 byte 4) but the water works a treat (CAN ID 420 byte 0). The only one that doesn't work off can is the petrol gauge which is driven essentially via two resistors.
  7. eaorobbie

    eaorobbie Well-Known Member Staff Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,582
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,005Coins
    Ratings:
    +1,662 / 22 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    ya can drive most oil and water guages ya pwm from the arduino just like making an led brighten and dim.
  8. Mexwall

    Mexwall New Member

    Joined:
    Jun 5, 2009
    Messages:
    22
    Location:
    Netherlands
    Balance:
    345Coins
    Ratings:
    +0 / 0 / -0
    Can all Rx8 gauges work with this or just a specific year?
  9. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    Short answer: No, Not like that.

    Long answer: I've got one of those ELM327 based OBD readers and you cannot send the data though it as its not designed for that.
    You could create a 'raw' RS232<=>CAN adapter, you'd need the two chips from the shield along with an RS232<=>SPI interface (and possibly a USB<=>RS232) but by the time you've designed and built it, plus then programmed it on the PC (IMO trickier than using and arduino) you'll have spent far more time on it (unless you're already used to doing such things). Its then dead easy to use USB (or RS232) to essentially tell the arduino for example 100mph,4000rpm, 100degrees and it just takes care of it.

    The advantage of this is you could be up and running in an afternoon. I could see 'rolling your own' as taking far longer.

    Well the 2003-08 certainly. Not sure about later models although I believe them to be the same. Take into consideration there are 2 models, the 9500rpm '231' and 7500rpm '192'. Plus the instruments are different for the manual and auto models (although it might be nice to get the auto ones as you could also show what gear you were in).


    Well that depends, that would be by giving a varying voltage to the gauge, I'm not sure if that is how the petrol gauge works or if its a very simple resistance meter (in which case its a bit tricker but still easy).
  10. Mexwall

    Mexwall New Member

    Joined:
    Jun 5, 2009
    Messages:
    22
    Location:
    Netherlands
    Balance:
    345Coins
    Ratings:
    +0 / 0 / -0
    How did you get those message id's? Did you tap them of a car? If you did, what did you use?

    Correct me if I'm wrong, after reading this I get the impression that your code can only set the needle at a fixed point, not make it go up and down like in a car when you rev the engine.
  11. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    I used an ELM327 to read the codes from the car then fed them back into the clocks and mapped what they did. I needed to bump up the data rate of the ELM327 though, waaay too many messages to cope at 38k!

    The code I posted does just set it at a 'fixed' point, I posted it as a starter, you'd need to read the speed/RPM from the RS232 and set accordingly
  12. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    I took a look at the chips and all are straight forwards apart from one which is by the maker of the clocks. It might just be rebadged it might be custom but there are no details available either way. :-/
  13. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    You're miss-understanding how these work.

    OBD is for DIAGNOSTICS, not for 'normal' use. There is zero OBD traffic on the bus normally.

    Yes there is a PID for speed, rpm etc and an agreed mechanism to get that from the PCM/ECU but that's not how the clocks work and no use to you. The way these and in likelyhood all others work is that the PCM/ECU constantly pushes speed and rpm out onto the bus, the instruments then just pick this up (along with anything else that wants it).
  14. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    No. Nothing is universal.
  15. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Sirnoname, he means that all clocks speedometers have different ID's and most of the time different protocols although they still sent data over CAN network.

    So to be able to start even working on a clocks/speedometer you must know:
    1. Year of the make of the car that the clocks belong, so you can find the protocol.
    2. Using the protocol to scan the data that the REAL car sends while working and extract the useful ID's.'
    3. Emulate the car pulses on the CAN bus to fool the clocks that they are still in a real car.

    So unless Car companies could provide us with such information, we are swimming in the dark.

    Or you end up making custom air-core driving circuits... ;-)
  16. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  17. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    Nah, that's still not going to do it as that will be obd or similar. Its easy if time consuming to scan the can ids for ones that give a response and then work from there.
  18. Mexwall

    Mexwall New Member

    Joined:
    Jun 5, 2009
    Messages:
    22
    Location:
    Netherlands
    Balance:
    345Coins
    Ratings:
    +0 / 0 / -0
    You need something like this http://www.peak-system.com/Product-...rce_pi1[catUid]=6&tx_commerce_pi1[showUid]=17 and connect it directly to the canbus wires. If everthing is set right you can record every message that is send. The hardest thing is finding out which message does what.

    I have such a device and played around with it. I connected it to the OBD connector and could identify some messages and put them back on the canbus to operate doorlocks and electric windows through the laptop.
  19. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    Ouch, 195EUR!?

    I used one of these http://www.ebay.co.uk/itm/USB-V1-4-ELM3 ... 5264wt_905

    I think I paid about £10 for mine, then a few minutes reading the ELM327 data sheet, plug it into the OBD-2 port, start logging to a file then go for a short drive. Need the arduino (+CAN Shield) for writting back to the bus (as the ELM327 only does OBD, it doesn't do 'raw' CAN).

    I did find however that while the CAN stuff is not OBD the bytes used stuck to the same formats, ie temp is +40, rpm is 4* etc.
  20. Mexwall

    Mexwall New Member

    Joined:
    Jun 5, 2009
    Messages:
    22
    Location:
    Netherlands
    Balance:
    345Coins
    Ratings:
    +0 / 0 / -0
    I didn't buy a new one, I got mine from Ebay, second hand.
  21. fastdruid

    fastdruid New Member

    Joined:
    Jun 16, 2011
    Messages:
    22
    Balance:
    57Coins
    Ratings:
    +8 / 0 / -0
    Whew! Its a neater solution but unless you get one cheap a very expensive one!

    You can use the arduino to scan as well as write but I found it easier to use something with a build in OBD-2 port which could just be plugged into the car.