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

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:
    21,155
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,616Coins
    Ratings:
    +10,909 / 54 / -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,119Coins
    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 Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,161
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,201Coins
    Ratings:
    +2,164 / 19 / -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:
    1,040
    Location:
    USA
    Balance:
    5,841Coins
    Ratings:
    +1,040 / 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 Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,161
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,201Coins
    Ratings:
    +2,164 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    • Like Like x 1
  6. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    1,040
    Location:
    USA
    Balance:
    5,841Coins
    Ratings:
    +1,040 / 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 Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,161
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,201Coins
    Ratings:
    +2,164 / 19 / -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,119Coins
    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:
    1,040
    Location:
    USA
    Balance:
    5,841Coins
    Ratings:
    +1,040 / 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:
    1,040
    Location:
    USA
    Balance:
    5,841Coins
    Ratings:
    +1,040 / 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:
    1,040
    Location:
    USA
    Balance:
    5,841Coins
    Ratings:
    +1,040 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Is anyone going to test this?
  12. darkknight

    darkknight New Member

    Joined:
    Feb 1, 2021
    Messages:
    27
    Location:
    London
    Balance:
    61Coins
    Ratings:
    +19 / 0 / -0
    My Motion Simulator:
    6DOF
    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:
    1,040
    Location:
    USA
    Balance:
    5,841Coins
    Ratings:
    +1,040 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    • Informative Informative x 1
  14. Zeeflyboy

    Zeeflyboy New Member

    Joined:
    Feb 26, 2016
    Messages:
    14
    Location:
    UK
    Balance:
    125Coins
    Ratings:
    +10 / 0 / -0
    Hey guys

    Does anyone have a working sketch for FlyPT, an arduino uno and a dual channel VNH5019 with 2 fans?

    I've tried all the sketches posted here with no success, and the FlyPT configurations posted on the mover website... I'm assuming perhaps maybe because of pins/terminology for the dual VNH5019 I'm not having any joy? I've also tried adding the VNH library with
    #include <DualVNH5019MotorShield.h> but not sure what else is needed.

    The hardware setup is definitely fine, as it all works perfectly with the simhub sketch so there are no concerns there, but I need it to work with FlyPT for my flying games which simhub doesn't support. I'm either messing up something regarding the sketch or something regarding FlyPT setup with the direct and/or serial output. I believe the direct is all set correctly, as on the serial output I can see a value changing between 0 and 255 so it's more likely an issue with the serial output setup if it's a FlyPT issue.

    Would greatly appreciate any help as I've been trying to sort it for hours and got nowhere... all I've learned is I know absolutely nothing about arduino lol.
    Last edited: Feb 1, 2022
  15. Zeeflyboy

    Zeeflyboy New Member

    Joined:
    Feb 26, 2016
    Messages:
    14
    Location:
    UK
    Balance:
    125Coins
    Ratings:
    +10 / 0 / -0
    Some progress with my issues - I've managed to change most pin assignments (although couldn't find anything for
    int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)
    int statpin = 13;
    ) but given it's working I assume not important.

    I can now get my fans to spin using serial monitor and sending eg L255 or R255 or indeed S255

    Now my last remaining hurdle is that I can't figure out how to get FlyPT to do what I want.

    If I set the serial to digital then I can get some joy with for example S<Wind>

    However the problem I am running into it seems is that the code Zed kindly posted is always looking for all digits of the value in the serial string.

    Mover however only obliges this above a certain point here once the fan speed is 3 digits long.... for example instead of 000 it sends 0 so rather than outputting "083 48 48 48" for "S000" it is actually only outputting "083 48", which causes it to not complete. This means the fan doesn't turn on until we hit a bit output of 100 and all four digits are sent "083 049 48 48", after which it works as expected. However of course if we then come below 100 it won't reduce or turn off as it's seeing invalid commands again.

    Is there any way to make Mover output all 3 digits at all times - ie have zero fan speed as "083 48 48 48" rather than "083 48"? Am I doing something daft?
    Last edited: Feb 5, 2022
  16. GWiz

    GWiz Active Member

    Joined:
    May 12, 2019
    Messages:
    188
    Occupation:
    Dentist
    Location:
    Aberdeenshire, Scotland
    Balance:
    1,510Coins
    Ratings:
    +121 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Hi Zeeflyboy, I encountered a similar issue when I was using Mover when I used a sketch that was not sending a 3 digit number i.e. sending '50' and not '050'.

    One possible work around is to use a REMAP filter in Mover to remap, for example, 0 to 255 to a new range of 100 to 255. It will reduce your resolution a little, but it won't be particularly noticeable for a wind sim. This will allow a value of 100 to be effectively zero and then remap the remaining over the full range of your fan speed so that it still works below a value of 100 and allows the fan to be at minimum speed/off.
    • Friendly Friendly x 1
  17. Zeeflyboy

    Zeeflyboy New Member

    Joined:
    Feb 26, 2016
    Messages:
    14
    Location:
    UK
    Balance:
    125Coins
    Ratings:
    +10 / 0 / -0
    Thanks for the reply bud.

    Hmmm, that could maybe work if the arduino sketch was changed from for example

    if (Speed == 0) motorOff(1);

    to

    if (Speed == 100) motorOff(1);

    Otherwise the fans will still fail to shut off. I'm not sure however how to change the sketch for the fans to begin their ramp from 0% at 100 though, I imagine otherwise it will kick straight into ~40% (255/101 x 100) the moment mover sends a signal above 100 since it is the sketch that controls fan speed and not mover directly... we'd just be changing it so they shut off at 40%.

    // Now turn that into a number and clip to 255 - rely on Game Dash for proper scaling
    Speed = ((bufferArray[1]-48)*100) + ((bufferArray[2]-48)*10) + ((bufferArray[3]-48)*1);
    //Serial.println(SpeedGameDash);
    if (Speed > 255)
    Speed = 255;

    All that we would in effect achieve with just the remap is that mover won't send anything below 100, which solves one aspect of the problem, but the Arduino will still be interpreting that as speed 100 I think? I can, I think, change motor off at 100 easily enough but the remapping on the arduino side so that 101 is 0.6% rather than 39.6% I'm not sure how to achieve.

    edit - I take it back... setting if (Speed == 100) motorOff in the sketch seems to take care of the ramp too. Think we might have a solution here buddy! Just going to have a play with it and see what's what. I can't get them to spin quite as slowly as on the simhub sketch but they definitely aren't at 40% immediately as I feared.

    edit 2 - seems like only problem is that when I disconnect the serial output it starts the fans up again during the disconnection process and keeps them running, other than that it seems to work. I just have to quit Mover without disconnecting the serial first to work around that.

    I look forward to having a proper go with this once my rig is back together - the only thing I'd love now is to be able to add RPM based wind but multiplied by canopy position 0 or 1 so one could fine tune the effect of prop wash independent of wind speed, but I think that's going to be possible in mover 4.0 so I can wait! Thanks for the suggestion of the workaround, it's definitely good enough for now.
    • Like Like x 1
    Last edited: Feb 6, 2022
  18. GWiz

    GWiz Active Member

    Joined:
    May 12, 2019
    Messages:
    188
    Occupation:
    Dentist
    Location:
    Aberdeenshire, Scotland
    Balance:
    1,510Coins
    Ratings:
    +121 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    You might be able to fix that by inserting a 'Stop string' in Mover to set the fan speed to zero on exit. Something like <0><0><0><0> underneath the Output string. Also worth having a Speed=0 in the Arduino sketch at the start of the sketch if you don't already.

    Glad you have it working, I fiddled around with some sketches to try and get some cross compatibility between the programs I use. I managed to get Simtools and FlyPT to work nicely off the same sketch but the Simhub sketches are a bit too complicated for me to follow well enough so I have difficulty in customising these ones. Still, every day is a school day and this forum has really helped me expand my knowledge.
    • Like Like x 1
  19. Zeeflyboy

    Zeeflyboy New Member

    Joined:
    Feb 26, 2016
    Messages:
    14
    Location:
    UK
    Balance:
    125Coins
    Ratings:
    +10 / 0 / -0
    Yeah I had tried putting S<49><48><48> in the stop string to send S100 as an "off" but that didn't seem to have any effect. Not sure why.

    Simhub Sketch is a monster.... thankfully their configurator is really well set up and easy for ignorant asses like me to use. Not much use for flight sims as yet though! I've decided to just have two arduinos in the end, one set up for simhub and one set up for others, using DPDT switch to change the inputs to the fans. Getting them to all play nice on a single sketch is far beyond me.
  20. Zed

    Zed VR Simming w/Reverb Gold Contributor

    Joined:
    Apr 4, 2017
    Messages:
    1,040
    Location:
    USA
    Balance:
    5,841Coins
    Ratings:
    +1,040 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, JRK
    Hey guys, replied to Zee by PM before I saw this here. I don’t have the FlyPoint but you may be able to terminate the command just by timing out. The time between digits should be much shorter than the time between commands. You can use the Arduino itself to time things or an oscilloscope if you have one. Or FlyPoint may even publish the timing. But if you time out waiting for a digit, you could take the digits you do have and turn those into the fan value, update the fan outputs, and return to waiting for the first digit.

    There would be no timeout on the first digit but you’d want to timeout if a second or third digit doesn’t come. That’s all I can think of right off since there isn’t any kind of termination to the command.