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 Download Package Now!
  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 here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

News Build a real car instrument cluster for racing simulation on a PC

Discussion in 'DIY Motion Simulator Projects' started by jjanu, Dec 4, 2017.

  1. jjanu

    jjanu LiveForSim Gold Contributor

    Joined:
    Apr 13, 2013
    Messages:
    66
    Occupation:
    Multimedia
    Location:
    Québec
    Balance:
    480Coins
    Ratings:
    +56 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Hi bud, thanks for these infos. I managed to get the RPM working very smoothly in Assetto Corsa, even better than it was in X-Sim. However, when I add Speed to the string, RPM and Speed needles start to behave erratically. When RPM is alone in the string it behaves normally. When Speed is alone, the needle doesn't budge. I tried several commands: SCALE 0 255 with TOCHR, PERCENT 0 220 (0 to 220km/h), nothing. I will shoot a little video of my dashboard to show you what I mean. I verified my code and it seems all ok. Actually I modified my code slightly to have the minimal vanilla version to make sure that no other functions could affect the speed and rpm behaviors. See below the new version of the code that I'm using for my current tests:

    Code:
    #include <mcp_can.h>
    #include <mcp_can_dfs.h>
    #include <SPI.h>
    #include <TM1638.h> //can be downloaded from http://code.google.com/p/tm1638-library/
    
    const int SPI_CS_PIN;
    
    MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin
    
    // Declare RPM, Speed and Gear
    int RPM;
    int Speed;
    
    char kind_of_data;
    byte my_data[8];
    
    void setup()
    {
      Serial.begin(115200);
      // Send a diagnostic test to the Serial Monitor for the CAN shield
      if(CAN.begin(CAN_500KBPS) == CAN_OK) Serial.print("can init ok!!\r\n");
      else Serial.print("Can init fail!!\r\n");
    }
    
    void loop()
    {
      // Parsers used by X-SIM to send game datas for Gear, RPM, Speed, Temperature and the external LEDs to the cluster over serial port (USB)
      while(Serial.available() > 0)
      { 
        kind_of_data = Serial.read();
        if (kind_of_data == 'R' ) Read_RPM();    // Send RPM data to the cluster and flash RPM red LED when RPM hits 6500
        kind_of_data = Serial.read();
        if (kind_of_data == 'S' ) Read_Speed();  // Send Speed to the cluster
      }
    }
    
    // RPM Data and Maths
    void Read_RPM()
    {
      //Read from Serial
      delay(1);
      int RPM100 = Serial.read()- '0';
      delay(1);
      int RPM10 = Serial.read()- '0';
      delay(1);
      int RPM1 = Serial.read()- '0';
      int RPM = 100*RPM100 + 10*RPM10 + RPM1;
    
      //Set values
      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'.
     
      CAN.sendMsgBuf(0x201, 0, 8, my_data);
      delay(30);
    }
    
    // Speed Data and Maths
    void Read_Speed()
    {  
      //Read from Serial
      delay(1);
      int Speed100 = Serial.read()- '0';
      delay(1);
      int Speed10 = Serial.read()- '0';
      delay(1);
      int Speed1 = Serial.read()- '0';
      int Speed = 100*Speed100 + 10*Speed10 + Speed1;
    
      // Set values
      my_data[4] = (Speed-8000) / 256; //speed
      my_data[5] = (Speed-8000) % 256; //speed
      my_data[6] = 0x00;
      my_data[7] = 0x00;
    
      //Send Message
      CAN.sendMsgBuf(0x201, 0, 8, my_data);
      delay(30);
    }
  2. jjanu

    jjanu LiveForSim Gold Contributor

    Joined:
    Apr 13, 2013
    Messages:
    66
    Occupation:
    Multimedia
    Location:
    Québec
    Balance:
    480Coins
    Ratings:
    +56 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Hi Yobuddy and All, I have it all working except for few cosmetic or non-essential components like temp, fuel gauge, engine lights, etc. That still needs some code fiddling in Arduino. Otherwise, RPM+Speed+Gear on the dashboard as well as on the TM1638 digital display are all working perfectly in Assetto Corsa. It required a lot of tinkering with the Arduino code and the gamedash commands/values but thanks to your help I finally got it all running:thumbs

    I'll make a little video of the setup in action this weekend and share it with the community, along with the codes.
    Cheers!
    • Winner Winner x 2
  3. jjanu

    jjanu LiveForSim Gold Contributor

    Joined:
    Apr 13, 2013
    Messages:
    66
    Occupation:
    Multimedia
    Location:
    Québec
    Balance:
    480Coins
    Ratings:
    +56 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Hi All, I made a little video of my recent progress with Simtools and the Mazda 3 dashboard in Assetto Corsa.



    The test was performed with Mazda-Speed 3 and KTM X-BOW car models. The fuel gauge is still not plugged-in, hence the 0 position. There are some more tweaks that still need to be done to correct an issue with the tacho needle that jumps to max RPM at a certain rev/gear position. I looked through all the codes and commands and can't figure out what is causing the needle to jump that way. There's an example of that occurrence at 00:45 of the video. Anyone has an idea of what's going wrong? I added all the Gamedash commands and Arduino code to this post.

    I also tested my dashboard with my 4-dof simulator running a the same time and from the same pc. I'm pleased to announce that both platforms are performing perfectly without any interference. To the question "Can Simtools run a car dashboard along with a complex simulator platform using multiple micro-controllers and telemetry inputs", the answer is "YES!!!" :o:

    The dashboard is also performing well in ProjectCars but it doesn't work with The Crew. The needles are moving when the game loads but once the map has loaded the needles stay still at mid-position.

    Cheers!

    Attached Files:

    • Like Like x 2
    • Winner Winner x 1
    Last edited: May 7, 2018
  4. Tyrin D Claxton

    Tyrin D Claxton New Member

    Joined:
    Jul 22, 2018
    Messages:
    1
    Balance:
    49Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    SimforceGT
    can't get my can bus to work help?
  5. mattie47

    mattie47 New Member

    Joined:
    Jun 22, 2019
    Messages:
    6
    Balance:
    - 7Coins
    Ratings:
    +3 / 0 / -0
    @jjanu did you mean to delete the folder with instructions etc?
  6. jjanu

    jjanu LiveForSim Gold Contributor

    Joined:
    Apr 13, 2013
    Messages:
    66
    Occupation:
    Multimedia
    Location:
    Québec
    Balance:
    480Coins
    Ratings:
    +56 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Mattie and All. My OneDrive has been recently deleted. I re-uploaded all the information into this new OneDrive folder.
    • Winner Winner x 1
    Last edited: Jan 15, 2020
  7. mattie47

    mattie47 New Member

    Joined:
    Jun 22, 2019
    Messages:
    6
    Balance:
    - 7Coins
    Ratings:
    +3 / 0 / -0
    Hey @jjanu, that's great. Thanks.

    I used some of the code as an example for getting things working with SimHub, and I don't have a license for .

    I don't really have any code to release yet, but I've got it working (RPM/Speed/Temp - My cluster doesn't appear to have Gear) which is nice :)

    I'm also making my arduino use two can buses to get rid of the seat belt, and other dash warning lights on the 125k bus.

    Some bash examples if someone has a USB can adapter like me (canable.io)on the MS Can:

    Left Indicator:
    while true; do cansend can0 265#2000000000000000; sleep 0.5; cansend can0 265#0000000000000000; sleep 0.5; done

    Right Indicator:
    while true; do cansend can0 265#4000000000000000; sleep 0.5; cansend can0 265#0000000000000000; sleep 0.5; done

    High Beam:
    while true; do cansend can0 433#00000040000000; sleep 0.01; done



    My current thing I'm trying to get working is the Fuel gauge. Do you know how it works ? Like would you need something like PWM or the arduino "tone" library to control it ?

    See the attached from the Mazda Wiring Diagram manual. I know it's the first two pins on the connector (2U and 2W) but not too sure what those wires actually equal.

    Thanks,

    Matt

    Attached Files:

    • fuel.png
      fuel.png
      File size:
      138.7 KB
      Views:
      58
  8. jjanu

    jjanu LiveForSim Gold Contributor

    Joined:
    Apr 13, 2013
    Messages:
    66
    Occupation:
    Multimedia
    Location:
    Québec
    Balance:
    480Coins
    Ratings:
    +56 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    @mattie47: thanks for these infos. I'll eventually try your indicator light code. I'm curious to see it performs. I'll come back to you with more info about the fuel gauge but if I remember correctly this indicator is directly connected to the mechanical float inside the fuel tank and receives electrical (non-logic) impulses. So I guess that a PWM signal from the Arduino could make it work. I never actually wired that gauge. Just make sure to wire the proper cable to avoid frying a logic data component of the cluster. Please keep me informed of any other discovery you make. It's been a while since I worked on that project and feel pretty nostalgic about it. I might reinstall it on my sim one day and implement some of the dormant cluster functions, just for fun.

    Cheers!
    Justin
  9. mattie47

    mattie47 New Member

    Joined:
    Jun 22, 2019
    Messages:
    6
    Balance:
    - 7Coins
    Ratings:
    +3 / 0 / -0
    Thanks Justin.

    This is from when I got things working with Simhub last week:

    https://drive.google.com/open?id=1IOFCaohpCtT3Gs9a_o9U-LtbrV91zwSg
    https://drive.google.com/open?id=1PXlsheVeaDRvXLQPM5AoM7JxVX2jypbc

    Only adding the MS Can after having a couple people look at it and say "where's ya seat belt and why do you have your hand brake on!" ;-)

    I just tried a 10k pot between those two wires for the fuel, but sadly no luck getting anything to change. I noticed your code had changing an Arduino pin output High if > 300 rpm, but I wasn't too sure how you wired this. I tried connecting the arduino ground to the cluster gnd and tried tried between those two pins being high but still no luck on the fuel gauge.

    Annoyingly I can't edit my comment above after 60 seconds, so here's a slightly more complete MS Can list using bash and cansend :

  10. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,046
    Location:
    Marseille - FRANCE
    Balance:
    18,528Coins
    Ratings:
    +1,939 / 17 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    following your progress! as I have been stuck some years ago with my mercedes A class dashboard https://www.xsimulator.net/communit...o-drive-a-mercedes-a-class-w176-cluster.7409/

    you may find some useful infos I gathered in the 4 first posts of the topics

    :grin
  11. mattie47

    mattie47 New Member

    Joined:
    Jun 22, 2019
    Messages:
    6
    Balance:
    - 7Coins
    Ratings:
    +3 / 0 / -0

    Yeah I can understand that frustration. I started with a subaru legacy cluster but I own a mazda 3. I got mostly no where with the legacy cluster because I couldn't reverse engineer the CAN messages. The Subaru also has some initialization CAN messages for security.

    I suggest if you're going to persist with the Mercedes to find a "friend" with one and connect a can adapter to the obd port and try record the Canbus data with candump (more info on that in the car hacker book you link to in the other thread.) great book btw...

    This assumes the cluster info is available on the obd port. In the case of the Mazda 3, both the MS Can and HS Can are available on the obd port. So basically I put a raspberry pi in my car running can dump and drove round the block recording both busses :).

    See attached photo for some reference lol:
    3C49E79A-4682-42EC-A14F-C209FE22E230.jpeg
    • Like Like x 1
  12. jjanu

    jjanu LiveForSim Gold Contributor

    Joined:
    Apr 13, 2013
    Messages:
    66
    Occupation:
    Multimedia
    Location:
    Québec
    Balance:
    480Coins
    Ratings:
    +56 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Wow, dude! I'm impressed of how smooth the motion of your gauges is. Nice work. I didn't know about Simhub, seems like a nice program to feed the telemetry. I have some experience with X-Sim and Simtools which I use for my actual 4dof simulator. They work great with car clusters but Simhub looks more specialized for the task.
  13. mattie47

    mattie47 New Member

    Joined:
    Jun 22, 2019
    Messages:
    6
    Balance:
    - 7Coins
    Ratings:
    +3 / 0 / -0
    Cheers. I do have a bug to fix where it seems to jump slightly in-game when increasing over small values, e.g. 50kmph to 55kmph. Hard to explain without an example. Something minor to fix later. I think it's because of the calculation I have on speed to get the dial reporting what's actually on the bus (it seems to be slightly "out").

    Code:
        void Send_Speed(int inputSpeed)
        {
            /* NOTE: This is an equation to ensure for example 50kmph actually shows as
               50kmph on the Instrument Cluster. You may need to fine-tune 1.029 with
               your own cluster to get values correct. */
    
            int speed = inputSpeed /  1.029;   
            // -- Set values -- //
            canDataFrame[4] = (speed * 100 ) / 256; // inputSpeed
            canDataFrame[5] = (speed + 100) % 256; // inputSpeed
            canDataFrame[6] = 0x00;
            canDataFrame[7] = 0x00;
    
            actuallySendData();
    
        }
    
    Tbh I spent 2-3 hours trying to get X-Sim working but got no where. I found it really confusing for setting up, and tried googling for instructions but yeah....

    Haven't tried SimTools as I didn't wanna spend what I thought was quite an expensive amount on a license. So that left SimHub, which has fantastic documentation here:
    https://github.com/SHWotever/SimHub/wiki

    If you have a github account, I can add you to a private repo I've done some stuff on. Nothing public yet cause I'm ashamed of the code lol.
  14. mattie47

    mattie47 New Member

    Joined:
    Jun 22, 2019
    Messages:
    6
    Balance:
    - 7Coins
    Ratings:
    +3 / 0 / -0
    @jjanu thought I'd give an update.

    I've got it working with dual speed can bus now. I had both a Can Shield (clone from Aliexpress), and the smaller MCP CAN adaptor.

    See attached.

    Here's a quick vid with data from Dirt 3 :) - https://drive.google.com/open?id=1YugTIoAATD0jCyOnfMgvdUqCdpXG7Yy8


    Also - I figured out my problem with the Fuel Gauge. Originally when I used a potentiometer, it was a 10k Pot. The Fuel gauge seems to be from about 10 ohm to I think 270 or 300 ohm.

    The Pot would do nothing unless I had it in that range *AND* in that range when first turning on the cluster. Which makes sense, I mean if it gets no value when the cluster first turns on, it can only assume there's a fault and it's better to report no fuel than something else.

    If I twist the pot while it's on, it can take a few minutes for the gauge to actually change. This also makes sense since it probably doesn't to constantly be polling the fuel resistor for details... I was thinking about getting a programmable digital resistor or something but to be honest it feels like overkill, and I think just getting the gauge to show fuel makes it feel "real enough"....

    Thanks,

    Matt

    Attached Files:

    • Like Like x 1
    • Winner Winner x 1
  15. jjanu

    jjanu LiveForSim Gold Contributor

    Joined:
    Apr 13, 2013
    Messages:
    66
    Occupation:
    Multimedia
    Location:
    Québec
    Balance:
    480Coins
    Ratings:
    +56 / 1 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Great job @mattie47 . Impressive electronic setup! I'm glad that some of my work could help you out in getting to that point. In my case Dirt serie was the best to study the cluster reactions. The telemetry was spot on. Assetto Corsa is good too but it came later. This is when I started putting together my 4dof motion seat.

    Best,
    Justin