1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. 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!
  3. 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
  4. 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

Question Game Dash Arduino code for two inputs

Discussion in 'SimTools Pro & Entertainment Version' started by RJ Stausebach, May 26, 2023.

  1. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi folks,
    I thought this should be simple but I have been battling with it for days, so please help!
    I am using Game Dash in v.2.6 with the MSFS plugin.
    I am trying to get data into my Arduino Uno but try what I might seem unable to do so.
    I am sending Dash1 and Dash9 info to the Arduino in Hex and (think) I am converting it back on the Arduino side using such examples as are available. My settings look like this (you can see the values are being generated when MSFS is running):

    Screenshot 2023-05-26 154521.png

    I have the hex code set as follows:
    Screenshot 2023-05-26 154552.png

    The interface setting is as follows:

    Screenshot 2023-05-26 154709.png

    My code on the Arduino loads properly but I can not see any printed output on the serial monitor. This is the code below:
    Any help greatly appreciated!


    Code:
    int i;
    
    unsigned int IAS;      // holds the speed data (0-65535 size)
    unsigned int RPM;           // holds the rpm data (0-65535 size)                 
     
    byte speeddata = 0;         // marker that new data are available 
    byte rpmdata = 0;           // marker that new data are available
    
    
    //====================SETUP==================================
    void setup() {
       // serial initialization
      Serial.begin(9600);   
    }
    
    
    //=================LOOP===============================
    void loop() {
     
          readSerialData();
          AirspeedChange(); // and run the Airspeedchange function
          Wind (); // run the Wind function for the fan speed
    }
    
    
    
    //===================SUBROUTINES=============================
            ////////////////////////////////////////////////////////////////////////////////
            // Procedure: read serial data
            ////////////////////////////////////////////////////////////////////////////////
            void readSerialData(){
     
              byte Data[5]={'0','0','0','0','0'};
    
              // parse the buffer
              if (Serial.available()>4){
                Data[0]=Serial.read();                   // read command
                if (Data[0]=='R'){                       // if rpm data
                  Data[1]=Serial.read();                 // store high byte
                  Data[2]=Serial.read();                 //
                  Data[3]=Serial.read();                 //
                  Data[4]=Serial.read();                 // store low byte
                  RPM = NormalizeData(Data);
                  rpmdata=1;                             // we got new data!       
                    if (Serial.available()>4){
                      Data[0]=Serial.read();               // re-read command
                    }
                }
                if (Data[0] == 'S' ){                    // if speed data
                  Data[1]=Serial.read();                 // store high byte
                  Data[2]=Serial.read();                 //
                  Data[3]=Serial.read();                 //
                  Data[4]=Serial.read();                 // store low byte
                  IAS = NormalizeData(Data);
                  speeddata=1;                           // we got new data!
                    if (Serial.available()>4){
                      Data[0]=Serial.read();               // re-read command
                    }
                }
                if (Data[0] == 'Z' ){                      // if Shutdown - Output
                  Serial.flush();
                }             
              }
              if (Serial.available()>60) Serial.flush();
            }
     ///////////////////////////////////////////////////////////////////////////////
            // Function: convert Hex to Dec
            ////////////////////////////////////////////////////////////////////////////////
            unsigned int NormalizeData(byte x[5])
            ////////////////////////////////////////////////////////////////////////////////
            {
            unsigned int result;
     
            for (int i=1; i<5; i++)
            {
              if (x[i]>47 && x[i]<58 ){   //for xA to xF
                x[i]=x[i]-48;
              }                       
              if (  x[i]>64 && x[i]<71 ){ //for x0 to x9
                x[i]=x[i]-55;               
              }
            }   
            result = (x[1]*16*16*16+x[2]*16*16+x[3]*16+x[4]);
            return result;
            }
    ///////////////////////////////////////////////////////////////////////////////////////////
    //------------------Airspeed change for force feedback actuator-------------------
    void AirspeedChange()
      {
       if (speeddata == 1)  {
        Serial.print("You have set the Speed to a Value of:");     
        Serial.println(IAS);
        //do stuff with IAS
          speeddata=0;
       }
    }
    
    void Wind() {
      if (rpmdata ==1) {
        Serial.print("You have set the RPM to a Value of:");     
        Serial.println(RPM);
        //do stuff with RPM
       rpmdata=0;
      }
    }
    
    //-----------------------------------------------------------------
    

    Attached Files:

  2. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    I have posed the following question to ChatGPT, providing a string where RPM is 2500 and Speed is 260 and it came up with the expected result. But nothing happening when I actually run the code on my arduino, so how would I know if anything is being sent at all?
    -----
    In the above code, how would a data string as follows be evaluated for RPM and IAS respectively?: R09C4S0104Z00
    ------
    Let's evaluate the provided data string "R09C4S0104Z00" for RPM and IAS values based on the given code:

    1. Parsing the data string:
      • The code reads the first character of the string, which is 'R', indicating that it is RPM data.
      • The next two characters '09' represent the high byte of the RPM value.
      • The following two characters 'C4' represent the next byte of the RPM value.
      • Then, the code reads 'S' as the command, indicating that it is speed (IAS) data.
      • The next two characters '01' represent the high byte of the IAS value.
      • The subsequent two characters '04' represent the next byte of the IAS value.
      • Finally, the code encounters 'Z', which indicates a shutdown command.
    2. Converting the data to decimal:
      • The NormalizeData() function converts each hexadecimal digit to its decimal equivalent.
      • The high byte of RPM '09' is converted to decimal as 9, and the next byte 'C4' is converted to 196.
      • Similarly, the high byte of IAS '01' is converted to 1, and the next byte '04' is converted to 4.
    3. Updating the variables:
      • The RPM variable is updated with the converted RPM value of 9 * 256 + 196 = 2460.
      • The IAS variable is updated with the converted IAS value of 1 * 256 + 4 = 260.
    4. Flagging new data:
      • The rpmdata flag is set to 1 to indicate that new RPM data is available.
      • The speeddata flag is set to 1 to indicate that new IAS data is available.
    5. Shutdown command:
      • Since 'Z' is encountered in the data string, the serial buffer is flushed.
    6. Function execution:
      • In the AirspeedChange() function, since speeddata is set to 1, it will print the received IAS value and perform actions accordingly.
      • In the Wind() function, since rpmdata is set to 1, it will print the received RPM value and perform actions accordingly.
    Therefore, based on the provided code, the data string "R09C4S0104Z00" would result in the RPM value of 2460 and the IAS value of 260 being evaluated and processed.
    ----------------------------
    But of course nothing is happening...
  3. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,534
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    145,028Coins
    Ratings:
    +10,776 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  4. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks @noorbeast, it’s not like I don't know how the software is supposed to work either,
    • I have motion simulation running quite successfully on both DCS and MSFS2020.
    • I have also tried the same sketch on SimTools 3, also with no serial output being received.
    • I placed print commands at various places and can see the sketch running properly but no serial being received.
    • I ran a sketch designed only to pick up any serial string being received..- nada..
    It probably is something simple but it should not be this hard to find..
    Last edited by a moderator: May 28, 2023
  5. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,534
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    145,028Coins
    Ratings:
    +10,776 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Simplifying user experience is a very worthwhile thing to do and something I know @yobuddy has been focused on as part of the SimTools v3 upgrade, while I appreciate your frustration that is likely useful feedback into the SimTool v3 upgrade, which is still in Beta and open for improvement.
    • Like Like x 1
    Last edited: May 29, 2023
  6. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,161
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    48,159Coins
    Ratings:
    +5,036 / 16 / -0
    • Like Like x 1
  7. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks @yobuddy
    I have based my code on various examples provided and it should work. DCS and MSFS2020 both show their data being received but that is not being sent on to the Arduino. I uninstalled V3 and V2.6 in total and installed V2.6 again and set everything up again from scratch but still nothing. Please try the code I provided and see if it works for you? Ihave also tested everything on a different machine and same effect, so not machine related. Also not serial port related as far as I can see because I can send code strings manually and the sketch will interpret it correctly in the Arduino serial monitor. It just never sees any data coming through. I have double checked that output rates match and baud rates match so should not be that either.
  8. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,161
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    48,159Coins
    Ratings:
    +5,036 / 16 / -0
    Looks like a math overflow is happening?
    [​IMG]

    Can I see an example of what you are sending?

    I don't have a ard here to play with at the moment. But how are trying to check if its working or not? As we can't use the Arduino serial monitor and SimTools at the same time is all.

    (Here is some things that may help, I'll do this with V3 as I have it all setup.)
    First, instead of ToHex , let's use ToBin, this way we get 1 char for any number between 0 and 255.
    (With V3, we can do all this with one command, GetBits(Min value, Max value, bit range, output type)
    Please add this for both Rpm and Speed edits. (instead of the tohex and pad edits.)
    GetBits 0 65535 16 b
    This will take any input number between 0 65535 and outputs is 16bit binary.

    For output let's just put
    R<Rp1><Sp1> (the inputs will always be 2 bytes, Sxyab 5-bytes total)
    (where <Rp1> = xy and <Sp1> = ab)

    And in your app I believe you can simply go:
    if (Serial.available()>=5){
    if (Data[0]=='R'){
    RPM = (x * 256) + y;
    Speed = (a * 256) + b;

    Also note that you can change the dash plugin from Serial to Virtual and see what is getting sent.
    And it's easy to switch back too.
    upload_2023-5-28_16-34-41.png

    Hope this helps.
    yobuddy
    • Like Like x 1
  9. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi @yobuddy, many thanks.
    PM sent.
    Today I reloaded V3 and managed to install the DCS and MSFS2020 plugins, but whereas before I was getting input from MSFS, this time it did not even do that. I will try v.2.6 again tomorrow but right now its late. I will also re-install legacy versions of simconnect (not that I had removed them) as that had previously been the reason MSFS was not working.

    To your comment that a math overflow is happening that could very well be but why?
    The code string used was as follows: R09C4S0104Z00

    Noted that the Ard serial monitor and SimTools do not work together.

    There seems to be code missing ? What is the string supposed to look like if it is in binary and how do I get it back to decimal? You did not mentioned that, also various variables not declared?

    Many thanks,
    Roel
  10. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,161
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    48,159Coins
    Ratings:
    +5,036 / 16 / -0
    • Like Like x 1
  11. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Hi @yobuddy, sorry, did not realise your follow-up post was still referring to the original example, will have a look at it again and let you know how I go. Thanks!
  12. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Ok @yobuddy , so before going to the sketch I ran into a few problems. First, double clicking on the MSFS banner to launch the game resulted in an unhandled exception - game not found. I managed to find your solution on the forums where you stated :"You may find that some game plugins do not set a launch path for a given game plugin, or the path is setup for a different version of the game than what you’re running. To update a launch path for a game plugin, simply drag and drop the games exe or shortcut on the banner for the given game plugin."
    Ok, then it ran. Using virtual output I could see that only RPM was creating an output and the Speed had a pretty weird look first symbol which never changed. There was no output at all going to the virtual interface:
    Screenshot 2023-05-30 102612.png

    These were the settings used:
    Screenshot 2023-05-30 103622.png

    .. ideas?
  13. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,161
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    48,159Coins
    Ratings:
    +5,036 / 16 / -0
    There is no output rate selected yet, for the virtual output plugin, I suggest setting output rate to 50.
    upload_2023-5-30_10-31-49.png
    Last edited: May 30, 2023
  14. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks @yobuddy. Missed it that time. Ok, done and this is the result:
    Screenshot 2023-05-30 191721.png
    So the RPM is coming through with a weird symbol, nothing from Speed, but that is something to do with the plugin I suspect?
  15. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,161
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    48,159Coins
    Ratings:
    +5,036 / 16 / -0
    Change the 'edit' (gitbits command) temporarily for both Speed and Rpm, just to see you are getting data for both.
    From GetBits 0 65535 16 b - to GetBits 0 65535 16 d (change the b at the end to a d)

    It's the ascii chars the arduino uses to store values, I sent you the chart in IM.
    It's from the GetBits command.
    You will always get 2 bits for Rpm and speed when asking for 16bit output (from the GetBits command).
    • Like Like x 1
  16. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Done. I can see that as soon as I launch the game it starts spitting out the following data:
    upload_2023-5-31_14-52-13.png

    Is that usual? Could it be the cause of the math overflow message I get when using V2.6?

    Once the sim is running I get the following (aircraft stationary):
    upload_2023-5-31_14-57-10.png

    So I can see that the first three digits there are for the RPM, and 0 is at the end for Speed.

    When the aircraft is moving the airspeed is now working and coming alive:
    upload_2023-5-31_15-1-42.png

    So here you have RPM at 1429 and Speed at 21 so output = R142921

    Where do we go from here?

    Ok thanks!
  17. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Some progress..
    I changed the output back to my original:
    upload_2023-5-31_15-56-56.png
    and put the following output rules into both RPM and Speed:
    upload_2023-5-31_15-57-58.png
    Running my original Arduino sketch but with an LED activation added I think I see something happening.
    As I need the output for DCS and MSFS and the V.3 DCS plugin does not have Game Dash I now need to get this to work on V2.6
    But before I get there, let me first prove this configuration on the sim, that will be a big step if it works with MSFS.
  18. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    @yobuddy Could you please provide me with the explicit equivalent from your suggestion above pasted into the RPM loop routine. I keep on having to second guess what is meant and am getting nowhere I'm afraid. So where you say:
    Please apply that correctly in the RPM code extract here:
    Code:
    void loop(){  
      if (Serial.available() >= 2){ //if 2 bits available in the serial buffer...    
        bufferArray[0] = Serial.read();  
        if (bufferArray[0] == 'R'){
          bufferArray[0] = Serial.read();
    
          //Set sign    
          bufferArray[1] = map(bufferArray[0], 0, 255, 0, NUM_LEDS);
          if (RpmOld != bufferArray[1]){
            RpmOld = bufferArray[1];        
            Set_Strip(bufferArray[1]);      
            FastLED.show();  
          }
        }
      }
    }
  19. RJ Stausebach

    RJ Stausebach Member Gold Contributor

    Joined:
    Jul 9, 2017
    Messages:
    49
    Location:
    Ireland
    Balance:
    297Coins
    Ratings:
    +12 / 0 / -0
    My Motion Simulator:
    Arduino
    Answering my own question I suppose this should work?
    Code:
     void readSerialData() {
            ////////////////////////////////////////////////////////////////////////////////
         
              byte Data[5]={'0','0','0','0','0'};
              if (Serial.available() >= 5){ //if 5 bits available in the serial buffer...    
                Data[0] = Serial.read();  
                if (Data[0] == 'R'){
                  Data[1]=Serial.read();                 // store high byte
                  Data[2]=Serial.read();                 //
                  Data[3]=Serial.read();                 //
                  Data[4]=Serial.read();
                  RPM = ((Data[1] * 256) + Data[2]);
                  IAS = (Data[3] * 256) + Data[4];
                }
              }
            }
    • Agree Agree x 1