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. dureiken

    dureiken Active Member

    Joined:
    Sep 28, 2016
    Messages:
    251
    Location:
    France
    Balance:
    1,248Coins
    Ratings:
    +170 / 2 / -0
    Hi

    sorry to digout this post, could someone post the wiring arduino diagram ? thanks :)
  2. sallerding

    sallerding Member

    Joined:
    Jul 12, 2019
    Messages:
    67
    Location:
    Perth, Western Australia
    Balance:
    344Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    AC motor, Motion platform, 6DOF
    I'm having some trouble adding a wind sim via FLYPT. I have managed to get it going via SIMHUB so I know its not hardware related. SIMHUB doesn't do flying sims however so I am adding via FLYPT. I've added the simple direct and Serial Output per instructions and uploaded the Arduino code to the Arduino Uno. I'm just trying to test using the actuator slider for now. Whilst the serial port is connected, there is no movement of the fan actuator.

    Probably my lack of arduino ability. I am using an adafruit shield v2 with the arduino but have ensured the serial speed in the code is the same as in the serial output. Most people seem to use Monster Moto boards. Not sure if that makes any difference to the sketch code. I've used the same as FLYPT's above so I haven't copied it here.(*other than adding the adafruit motor shield library at the top of the code)

    Given its a shield, I'm not sure if I need to assign specific pin outputs that are different from the standard ones in FLYPT's sketch code. Any help pointing in the right direction would be great.

    Attached Files:

    Last edited: Jan 3, 2023
  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
    @sallerding did you use the sketch from post #6, that one works?
  4. sallerding

    sallerding Member

    Joined:
    Jul 12, 2019
    Messages:
    67
    Location:
    Perth, Western Australia
    Balance:
    344Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    AC motor, Motion platform, 6DOF
    Thx @Historiker Just double checked again then and yes

    #include <Adafruit_MotorShield.h>
    #define BRAKEVCC 0
    #define CW 1
    #define CCW 2
    #define BRAKEGND 3
    #define CS_THRESHOLD 100

    int inApin[2] = {7, 4}; // INA: Clockwise input
    int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
    int pwmpin[2] = {5, 6}; // PWM input
    int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
    int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)
    int statpin = 13;


    void setup()
    {
    Serial.begin(115200);
    pinMode(statpin, OUTPUT);

    // Initialize digital pins as outputs
    for (int i=0; i<2; i++)
    {
    pinMode(inApin, OUTPUT);
    pinMode(inBpin, OUTPUT);
    pinMode(pwmpin, OUTPUT);
    pinMode(pwmpin, 0);
    analogWrite(pwmpin, 0);
    }

    // Initialize braked
    for (int i=0; i<2; i++)
    {
    digitalWrite(inApin, LOW);
    digitalWrite(inBpin, LOW);
    }
    }

    void loop()
    {
    //TCCR0B = TCCR0B & B11111000 | B00000001; // set timer 0 divisor to 1 for PWM frequency of 62500.00 Hz
    TCCR0B = TCCR0B & B11111000 | B00000010; // set timer 0 divisor to 8 for PWM frequency of 7812.50 Hz

    if (Serial.available())
    {
    uint8_t Speed=Serial.read();
    if(Speed>0)
    {
    motorGo(0, CW, Speed);
    motorGo(1, CW, Speed);
    }
    else if(Speed==0)
    {
    motorOff(0);
    motorOff(1);
    }
    }
    }

    void motorOff(int motor)
    {
    digitalWrite(inApin[motor], LOW);
    digitalWrite(inBpin[motor], LOW);
    analogWrite(pwmpin[motor], 0);
    }

    void motorGo(uint8_t motor, uint8_t direct, uint8_t Speed)
    {
    if (motor <= 1)
    {
    if (direct <=4)
    {
    // Set inA[motor]
    if (direct <=1) digitalWrite(inApin[motor], HIGH);
    else digitalWrite(inApin[motor], LOW);

    // Set inB[motor]
    if ((direct==0)||(direct==2)) digitalWrite(inBpin[motor], HIGH);
    else digitalWrite(inBpin[motor], LOW);

    analogWrite(pwmpin[motor], 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
    So it works now?
  6. sallerding

    sallerding Member

    Joined:
    Jul 12, 2019
    Messages:
    67
    Location:
    Perth, Western Australia
    Balance:
    344Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    AC motor, Motion platform, 6DOF
    No unfortunately not. It compiles and loads onto the arduino. But nothing functions
  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
    Check your PM
    • Like Like x 1
  8. sallerding

    sallerding Member

    Joined:
    Jul 12, 2019
    Messages:
    67
    Location:
    Perth, Western Australia
    Balance:
    344Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    AC motor, Motion platform, 6DOF
    I am assuming it is because I am using the adafruit shield which may requires specific referencing in the code. Or that the pin referencing needs to be different. When I was testing years back with small servos, I would connect them direct to the pin output and reference that in the sketch. With a shield, I'm not sure how that works differently
  9. sallerding

    sallerding Member

    Joined:
    Jul 12, 2019
    Messages:
    67
    Location:
    Perth, Western Australia
    Balance:
    344Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    AC motor, Motion platform, 6DOF
    OK I thought I would write up my experience of trying to get the wind sim to work with FLYPT using an adafruit v2 shield. I just couldn't get it to work with the code provided above no matter what settings I changed.

    Thx to ChatGPT I was able to have it create a new sketch for me which I'll attach below specifically for adafruit shield if it helps others who also use that shield. I didn't think it worthy of a separate topic so have just added it here under wind sim.

    To make it work properly I also had to add some filters using the add and logistic function per below image, which was similar to the solution from FLYPT for another user in the community to solve what was essentially a hardware problem to do with the cheap fans. I have no coding ability, and I was amazed that I could create the code so easily with ChatGPT. But it also means its probably not perfect for those experienced with arduino code. But it worked for me :). Hope this helps others

    Attached Files:

    • Informative Informative x 1
  10. sallerding

    sallerding Member

    Joined:
    Jul 12, 2019
    Messages:
    67
    Location:
    Perth, Western Australia
    Balance:
    344Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    AC motor, Motion platform, 6DOF
    Here is the code that worked for me for the adafruit shield v2


    #include <Wire.h>
    #include <Adafruit_MotorShield.h>

    // Create the motor shield object with the default I2C address
    Adafruit_MotorShield AFMS = Adafruit_MotorShield();

    // Select the 'port' for the motor
    Adafruit_DCMotor *motor = AFMS.getMotor(1);

    // Set the threshold value for starting the motor
    const uint8_t THRESHOLD = 0;

    void setup() {
    AFMS.begin(); // Initialize the shield
    Serial.begin(115200); // Initialize serial communication
    }

    void loop() {
    // Read serial input and set the speed and direction of the motor accordingly
    if (Serial.available()) {
    uint8_t speed = Serial.read();
    // Scale the input value to the range of 0 to 100
    uint8_t scaled_speed = map(speed, 0, 255, 0, 100);
    if (scaled_speed >= THRESHOLD) {
    motor->setSpeed(speed);
    motor->run(FORWARD);
    } else if (scaled_speed < THRESHOLD) {
    motor->run(RELEASE); // Release the motor
    }
    }
    }
    • Like Like x 1
  11. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,151
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,602Coins
    Ratings:
    +10,907 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Added to the FlyPT FAQ section, with credit to yourself, thanks for sharing your experience and solution :thumbs: https://www.xsimulator.net/community/faq/wind-sim-adafruit-shield-v2-for-flypt.398/
  12. smitty

    smitty Active Member

    Joined:
    Aug 24, 2021
    Messages:
    135
    Balance:
    841Coins
    Ratings:
    +183 / 2 / -0
    My Motion Simulator:
    6DOF
    that's so great, what exactly did you ask ChatGPT?
    • Like Like x 1
  13. sallerding

    sallerding Member

    Joined:
    Jul 12, 2019
    Messages:
    67
    Location:
    Perth, Western Australia
    Balance:
    344Coins
    Ratings:
    +37 / 0 / -0
    My Motion Simulator:
    AC motor, Motion platform, 6DOF
    I took the code that flypt added above and asked if it could convert this code to be used with an adafruit version 2 shield.

    I then had to refine it because the first version was just fan on and fan off. So I asked for it to modify the code to base motor speed with serial input. With a couple of minor tweeks and questions it produced what I uploaded. I also asked for it to prepare a version for two motors. I was happily stunned by what it produced.

    Also and separately in the code I left threshold to zero, because the need for that depends on peoples hardware. I now have mine set to 50 and so it is working perfectly. I am just playing with filter settings now. The 50 isn't a percentage, it is a bit value, so roughly 20%.

    I also don't have the toggle switch issues that other members seem to have, the fan only turns on when serial data from the sim is running through it
    • Like Like x 2
    Last edited: Jan 8, 2023
  14. smitty

    smitty Active Member

    Joined:
    Aug 24, 2021
    Messages:
    135
    Balance:
    841Coins
    Ratings:
    +183 / 2 / -0
    My Motion Simulator:
    6DOF
    I'm building a version of this using Pololu's arduino clone and their motor shield. So far its working, except for disconnecting from Mover. ONCE after clicking disconnect, it made it to "Stopping". But now it remains at "Disconnecting 0%" with a yellow border and completely hangs Mover until i unplug the usb. After that, Mover cannot reconnect to it after plugging back in, i have to quit the program. I am using the code from Example 2 on https://www.flyptmover.com/outputs/the-binary-output-string (changed to use the pololu DualMC33926 library)
    Is there some command i could listen for to disconnect it gracefully? would this go in the serial output Stop box?
  15. smitty

    smitty Active Member

    Joined:
    Aug 24, 2021
    Messages:
    135
    Balance:
    841Coins
    Ratings:
    +183 / 2 / -0
    My Motion Simulator:
    6DOF
    I got it working! Interval loop too low and something with the byte stream was goofy.

    Working sketch: https://pastebin.com/N1aZehrN
    This is for a Pololu A-Star 32U4 with their 3A DualMC33926 controller. Using 24V 3A SEAFLO 4" fans.

    I use a SPDT switch to go from manual mode to serial reader mode. Center is off.
    A potentiometer controls speed directly in manual mode, and sets the top speed for serial mode.

    in FlyPT, set as follows:
    upload_2024-3-3_16-29-17.png

    Attached Files:

    • Like Like x 2
    Last edited: Mar 3, 2024
  16. smitty

    smitty Active Member

    Joined:
    Aug 24, 2021
    Messages:
    135
    Balance:
    841Coins
    Ratings:
    +183 / 2 / -0
    My Motion Simulator:
    6DOF
    .Mover file for above sketch.

    Attached Files:

    • Informative Informative x 1
  17. dureiken

    dureiken Active Member

    Joined:
    Sep 28, 2016
    Messages:
    251
    Location:
    France
    Balance:
    1,248Coins
    Ratings:
    +170 / 2 / -0
    Hi experts
    I achieved to make fly pt and arduino working together with 12V pwm noctua fans, but only 1/10 time : it connects but don't drive my wind simulator.

    Here are and arduino and mover file if someone could check ?

    thanks

    Attached Files:

  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
    I had some difficulty getting a similar sketch working properly but managed to get the attached sketch and configuration working well with FlyPT. The sketch allows for separate Left and Right wind speed, has a button to toggle the fans off when you don't want them to activate with telemetry and works with 4 pin PWM fans like the ones you have linked. The fans are wired to the power supply, share a Gnd with the arduino and don't require a separate arduino shield. Hope this helps some!

    Attached Files:

    • Useful Useful x 1
  19. dureiken

    dureiken Active Member

    Joined:
    Sep 28, 2016
    Messages:
    251
    Location:
    France
    Balance:
    1,248Coins
    Ratings:
    +170 / 2 / -0
    Hi, thanks for your help
    with your file, nothing happens until slider to 170, after it works, is that normal ? thanks

    edit : same with my file, it's strange because I didn't notice that before
  20. 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
    I found that I needed a 3 digit number as a minimum as mine didn't respond until 100 (Due to my arduino sketch expecting 001 rather than just 1) so I used the following FlyPT Actuator filter for both fans:

    REMAP(VALUE;0;255;100;255)

    If your doesn't kick in till 170, you may wish to try something like this instead:

    REMAP(VALUE;0;255;165;255)

    Some fans need a minimum signal so it may be that your fans need a certain level before switching on. In my case, the fans run very slowly at zero and then ramp up smoothly if I use the remap function in Mover.

    I've attached the updated Mover file (The previous one must have been an older file prior to adding the filter, I need to be more organised!)

    Attached Files: