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

Mover Simulated Wind Arduino Sketch

Discussion in 'FlyPt Mover' started by pmvcda, Mar 21, 2020.

  1. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    16,775
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    121,899Coins
    Ratings:
    +9,633 / 47 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Check out the wind simulation section in the FAQs: https://www.xsimulator.net/community/faq/fans-wind-simulation.67/
  2. C1500

    C1500 Active Member

    Joined:
    Nov 19, 2018
    Messages:
    165
    Location:
    Germany
    Balance:
    1,054Coins
    Ratings:
    +86 / 1 / -0
    My Motion Simulator:
    AC motor, 6DOF
    Hi folks,

    Does anyone have a software solution to the full power startup problem?
    Every time I start the PC, the fans start up at full speed, even if I don't want to drive.
    I always have to start Mover to stop the fans.
    Let's see if I can find something in the Arduino code.
    But maybe there is already a solution that I do not know?

    greatings
    Peer
  3. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,017
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    10,070Coins
    Ratings:
    +1,962 / 14 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    As I mentioned above, I put a toggle switch to turn them off
  4. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    993
    Location:
    USA
    Balance:
    5,311Coins
    Ratings:
    +994 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    I’m not set up to test with the MM/SeaFlo setups right now but you should just be able to set the PWM registers to zero as part of the setup/initialization and then in the loop code it updates with commanded values when it gets new values.

    I do this on my setup to set the fans to a low speed for use when I’m in sims without fan-enabled plugins. I like just a little wind since I’m in VR.

    I don’t want to throw a wrench in all this but I think there is a code error causing the problem. There are two lines in that code assigning values to the same register, one right after the other. (Pwmpin pinmode assignments) The Arduino only cares about the second one. The first one sets a value then the second overwrites it. I don’t think that is the issue here but it just illustrates this code has some issues. This code also doesn’t set the PWM speed to 0 if the command is speed 0. It turns the bridge outputs off on a zero but doesn’t set the pwm output. In use it doesn’t really matter but the logic isn’t quite right.

    There are multiple versions of the Arduino wind code out in the wild and the version @Historiker posted doesn’t look like uses S codes to set speed. There were some logic errors in the code I reworked but it wasn’t this code but I think it was based on this code. The input method used in this code isn’t very reliable and may not start synched with whatever software is sending the speed values. That could be why it starts at high speed.
  5. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,017
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    10,070Coins
    Ratings:
    +1,962 / 14 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
  6. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    993
    Location:
    USA
    Balance:
    5,311Coins
    Ratings:
    +994 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Hey Historiker, I used to program for my job(s) and it’s easy to introduce bugs. I’ve done a lot of my own along the way. I wasn’t finding fault with Silent Chill’s code. Just trying to help since you guys were talking about the fans waking up at full speed. The code looks like it explicitly is trying to start with the motors stopped (under the initialize braked comment) but isn’t doing that for some reason. I was only trying to show there are some bugs without digging back into the code. I can’t test now with a MM but I think it’s the input code. It starts out initializing the motors stopped, but if the code thinks there is data available it acts on it without checks. In my mod, I found if I did full-blown input checking and built the number one digit at a time until I had a valid command, it just worked.

    I think it just needs some debugging and you guys wouldn’t need to add physical switches.
  7. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,017
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    10,070Coins
    Ratings:
    +1,962 / 14 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Great, thanks
  8. C1500

    C1500 Active Member

    Joined:
    Nov 19, 2018
    Messages:
    165
    Location:
    Germany
    Balance:
    1,054Coins
    Ratings:
    +86 / 1 / -0
    My Motion Simulator:
    AC motor, 6DOF
    Hi @Zed
    This sounds very promising
    I hope you can give us some more of your time here and help us debug the code.
    I can test, programming only conditionally.
    Thanks in advance
    Peer
  9. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    993
    Location:
    USA
    Balance:
    5,311Coins
    Ratings:
    +994 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Hey Peer, I don’t have time right now to dig into it. If you are running with GameDash, this code should work (https://www.xsimulator.net/communit...rmoto-and-arduinouno.6876/page-33#post-213758) but the code in this thread here doesn’t seem to look for a first “S” so I’m guessing your environments just sends values.

    The code in the post I linked wouldn’t work without some marker first character (and changing the code to look for it if it isn’t S, R, or L). But if you are using GameDash to talk to the wind system with an S character to mark each wind speed value, you might try it.

    I may be able to help some otherwise but not for a few days.

    Edited to point to most recent code...
    • Friendly Friendly x 1
    Last edited: Mar 24, 2021
  10. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    993
    Location:
    USA
    Balance:
    5,311Coins
    Ratings:
    +994 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Hey @C1500, just looking at it.

    Serial.available() returns the number of characters available to be read from the buffer.

    GameDash sends 4 byte commands (the way commonly configured) with each character as text. This software is sending single byte values as bytes. It doesn’t have the same input issues as I first thought.

    I wonder if it wakes up with a value in the receive register, thinks it is a valid command, sets the fans, and then waits for subsequent bytes. I’m guessing it goes full speed on power up but as soon as the PC software starts sending bytes, it settles down?

    If so, try adding the 3 extra lines below in the setup stanza that are called out with // comments.

    Code:
    void setup()
    {
      Serial.begin(115200);
     
      while (Serial.read() != -1);   // add this line to flush the buffer by reading until empty
    
      pinMode(statpin, OUTPUT);
    
      // Initialize digital pins as outputs
      for (int i=0; i<2; i++)
      {
       pinMode(inApin[i], OUTPUT);
       pinMode(inBpin[i], OUTPUT);
       pinMode(pwmpin[i], OUTPUT);
       pinMode(pwmpin[i], 0);
       analogWrite(pwmpin[i], 0);
      }
    
      // Initialize braked
      for (int i=0; i<2; i++)
      {
       digitalWrite(inApin[i], LOW);
       digitalWrite(inBpin[i], LOW);
      }
    
      motorGo(0, CW, 0);      // add these lines to explicitly set motors to 0 speed
      motorGo(1, CW, 0);
    }
    
    I don’t know this will fix it but bet it has a chance. I suspect it’s one of these issues. Please let us know if it made a difference.

    The first line reads anything in the serial buffer and drops it on the floor until there is nothing left.

    The second and third lines use the motorGo routines to set things up for the motors being off.

    If the motors wake up on after these changes, we can keep looking.

    Also, ninja edited a mistake. Should be correct now. I hope.
    • Useful Useful x 1
    Last edited: Dec 27, 2020
  11. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    993
    Location:
    USA
    Balance:
    5,311Coins
    Ratings:
    +994 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Is anyone going to test this?
  12. darkknight

    darkknight New Member Gold Contributor

    Joined:
    Feb 1, 2021
    Messages:
    21
    Balance:
    31Coins
    Ratings:
    +15 / 0 / -0
    My Motion Simulator:
    4DOF
    Ditto here. Uploaded the sketch and connected the arduino to my com port but no movement. Works via simhub though
  13. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    993
    Location:
    USA
    Balance:
    5,311Coins
    Ratings:
    +994 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    • Informative Informative x 1