1. You must be a registered member to be able to access this page and to download game plugins. Please register here. It´s for free.
  2. 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
  3. 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!
  4. 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
  5. 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
RacingMat

Arduino code: 2DOF and 2 pins direction Hbridge (motomonster and others) 1.2.2 with presets

source code motomonster VNH

  1. RacingMat
    Please find inside the .ino file, the Arduino code needed to run a 2DOF simulator with Hbridge having 2 pins for direction.

    you could use Motomonster
    or Pololu - VNH2SP30 Motor Driver Carrier MD01B
    https://www.pololu.com/product/706
    or
    VNH5019 Motor Driver Carrier https://www.pololu.com/product/1451

    it's the same wiring than motomonster InA and InB for Direction and 1 pin for PWM

    Arduino /..Motomonster1
    ....GND <-> GND pin
    .........5V <-> 5V
    .....pin 4 <-> pin 4 inA motor1
    .....pin 5 <-> pin 5 pwm1
    .....pin 6 <-> pin 6 pwm2
    .....pin 7 <-> pin 7 inA motor2
    .....pin 8 <-> pin 8 inB motor1
    .....pin 9 <-> pin 9 inB motor2

    .....pinA0 <-> center pin of pot 1
    .....pinA1 <-> center pin of pot 2
    .....pinGND <-> 0 ohm's pin potentiometer 1 & 2
    .....pin 5V <-> 10k ohm's pin potentiometer 1 & 2

    2DOF arduino and 1 motomonster.png

    such as Motomonster: motomonster.jpg H-bridge with a pair of VNH2SP30

    This file is a text file that can be loaded in Arduino IDE
    or simply opened with Notepad for viewing purpose.

    about Arduino: www.arduino.cc
    instructions for seting up your arduino and sim tutorial
    about 2DOF simulator building instructions: 2DOF DIY tutorial

    you intent to use 2 motomonsters? it's possible:
    2motomonster.png

    Looking forward driving stronger motors?
    follow Pit's tutorial to use a single Motomonster per motor: this allows twice more current!
    http://www.xsimulator.net/community...cts-as-a-single-motor-driver-more-power.5482/


    Arduino setup
    - install manually the drivers (see the Arduino's specific documentation for Windows Seven installation).
    - After complete installation, find in the Windows system on which COM Port it has been installed : you will need to put this information in SimTools / Interface Settings.
    1.png

    - Double clic on Arduino's line and adjust the default speed :
    2.png

    - In the Arduino plateform, put the right COM Port : if not, you won't be able to upload your program into the Arduino...
    3.png

    - Open the Serial Monitor (magnifying lens on top right ).
    4.png

    - Adjust here as well the same default speed :
    5.png

    Don't mess within the code ;-) or make everything coherent everywhere
    Code:
    ////////////////////////////////////////////////////////////////////////////////
    // INITIALIZATION
    ////////////////////////////////////////////////////////////////////////////////
    void setup()
    {
      // serial initialization
      Serial.begin(115200);
    First hardware tests and WIRING

    First : pot are not mounted onto the motor
    you can see the expected behaviour in this video

    and please find the explanation of the code here :

    The code is written to put the simulator on middle position at start :
    /* init position value*/
    int DataValueL=512; //middle position

    - if your pot is fully turned to max, as Arduino reads potentiometer value as motor position, Arduino believes that motor is in max position.
    - but the order is to be in middle position
    - so the Arduino will ask the motor to go reverse in order to go to middle position
    - your motor is turning
    - but while your pot keeps still, the motor will turn non stop !

    - when you manually turn the pot backward to min, Arduino reads that motor is in min position
    - but the order is still middle position, so Arduino will tell the motor to go forward
    - motor runs non stop until the pot is in middle position

    In the code, you have a tolerance parameter : when the pot is around middle position (<middle+tolerance and >middle-tolerance), the motor stops.
    You can broader Tolerance value to stop your motor more easily manually.

    Second : now checked the wiring
    Once you have played in this manner, now checked the wiring
    simulate the pot mounted onto the motor (back to back or alongside with gears...)
    reduce the speed (pwmMax) to see the direction of motor rotation
    and check if Arduino will behave as expected when you turn the pot

    if your pot is mounted this way :
    6.jpg

    when you turn in a direction, motor has to go the opposite way.
    If not, invert motor wiring or pot wiring.

    Warning ! if you have gears between pot and motor, you'll have to twist your mind :eek: to check the correct behaviour.

    Third : mount the pot onto the motor, the behaviour will be the following :
    - motor goes to middle position and stop
    - if you send order to Arduino via Serial Monitor (say R7FLAE) the left motor will move and stop at his new position ! right motor didn't move.
    - etc...

    2- calibrating the pot boundaries in the Arduino
    const int potMiniRorL=300;
    const int potMaxiRorL=700;

    these values are convenient as they will always constrain the values whatever comes from the simulator software,
    so the arduino will never send over-range value to the motors :) and your hardware will be protected !

    Now without any game running ! send orders from Arduino serial monitor :

    type the following strings in Hexa and press Enter:
    R7FL7F
    -> it should move the playseat in horizontal position

    increase the angulation
    R64L64
    go farther cautiously
    R3FL3F
    if the playseat moves too little, then the potMini and PotMaxi are too close to middle position
    and maybe go to max now : max backward tilt -> R01L01

    - if it's too litlle check how much you can go further and decrease potMiniRorL, reupload and resend R01L01
    and so on, until you found the pot minimal position

    - do the same for potMaxiRorL, send RFFLFF and increase potMaxiRorL, reupload and resend RFFLFF

    (write somewhere else these values that are associated to your particular playseat hardware).

    3- find your pot amplifying ratio
    - increase now the gearMotorRorLPotRatio (line 17)
    - by default, it's equal to 1
    - if you increase to 1,5 : the range will be increased by 50 %

    no worries, if the amplifying ratio is too high :
    - the playseat will not bump over the limits
    - but the mouvments will be fast or jittering

    Now, you can play with your DOFs :
    type the following strings in Hexa and press Enter:
    R7FL7F
    -> it should move the playseat in horizontal position

    increase the angulation
    R64L64
    go farther
    R3FL3F
    max backward tilt -> R01L01

    R9BL9B
    RC1LC1
    RFFLFF (Max !!)
    -> it should tilt the playseat forward and a bit further

    for rolling movment, you have to mix the orders this way :
    R3FLC1
    R01LFF (Max !!)
    -> roll left

    RC1L3F
    RFFL01 (Max !!)
    -> roll right

    SimTools Setup
    - In SimTools : set the same ComPort and same Speed
    7.png

    - my Arduino code needs 8bits Hex data : just setup like this for 1 bridge and 2 motors
    the only change needed for SimTools2.0 is the a designation: Axis1 -> Axis1a
    Ignore the axis b tab, you are not using it.

    8.jpg

    - startup and stop just send the instructions to come to middle
    - and 7F in hex equals 127 in dec