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

Tutorial SMC3 Arduino 3DOF Motor Driver and Windows Utilities

Discussion in 'SimTools compatible interfaces' started by RufusDufus, Dec 1, 2013.

  1. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,029
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,872Coins
    Ratings:
    +10,876 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Are you using the latest version of SMC3: https://xsimulator.net/community/attachments/smc3utils-v1-01-zip.24768/
  2. deeph46

    deeph46 Member

    Joined:
    Mar 17, 2023
    Messages:
    109
    Balance:
    612Coins
    Ratings:
    +15 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF
    I don't know if this help you out but did you install all related libraries with the sketch?

    deeph
  3. Edusfilms

    Edusfilms New Member Gold Contributor

    Joined:
    Jul 13, 2023
    Messages:
    1
    Balance:
    - 54Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    Hello, I have done all the steps in the tutorial and SMC utils works well for me but in SimTools it does nothing for me. Anybody knows what could be the problem?
  4. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,029
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,872Coins
    Ratings:
    +10,876 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Please post pictures of all of your settings.
  5. Murray Bester

    Murray Bester New Member

    Joined:
    Sep 4, 2023
    Messages:
    14
    Balance:
    84Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Hi all, I am pretty new to the world of Sim racing and have been trying to familiarize myself with SimTools and SMC3 for the arduino. I don't have access to a pot but have 3D printed an optical disk that is fixed to the motor shaft. I am using a Photo Interrupt Module (PIM) to effectively count the gaps in the optical disk and this effectively gives me the same outputs as a shaft encoder. I was wondering how I could incorporate this into the SMC3.ino code so that it works the same way as the pots used. I have included a photo of the PIM and my code on the arduino IDE is pasted to the end of this post:

    const int PIM_PIN = A0; // Analog pin for the photo interrupt module
    const int NUM_SLOTS = 20; // Number of slots on the optical disk
    const int SLOT_THRESHOLD = 200;
    const float ANGLE_PER_SLOT = 360.0 / NUM_SLOTS; // Degrees per slot

    unsigned long prevTime = 0;
    int prevVal = 0;
    float motorSpeed = 0;
    long encoderCount = 0;
    float currentAngle = 0; // Current angular position in degrees
    bool clockwiseRotation = true; // Assume clockwise rotation initially

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

    void loop() {
    // Read the analog value from the photo interrupt module
    int val = analogRead(PIM_PIN);

    // Check if the signal is below the threshold
    if (val < SLOT_THRESHOLD) {
    unsigned long currentTime = millis();
    unsigned long elapsedTime = currentTime - prevTime;

    // Calculate motor speed in revolutions per second (RPS)
    motorSpeed = 1000.0 / (elapsedTime * NUM_SLOTS); // 1000 ms in a second
    prevTime = currentTime;

    // Calculate the change in angle based on the slot detected
    float angleChange = ANGLE_PER_SLOT;

    // Update the angular position based on direction (clockwise/anticlockwise)
    if (motorSpeed > 0) {
    // Clockwise rotation
    currentAngle += angleChange;
    clockwiseRotation = true;
    } else if (motorSpeed < 0) {
    // Anticlockwise rotation
    currentAngle -= angleChange;
    clockwiseRotation = false;
    }

    // Print the motor speed, encoder count, angular position, and direction
    Serial.print("Motor Speed (RPS): ");
    Serial.println(motorSpeed, 2); // 2 decimal places
    Serial.print("Encoder Count: ");
    Serial.print(encoderCount);
    Serial.print(" Current Angle (degrees): ");
    Serial.print(currentAngle);
    Serial.print(" Direction: ");
    Serial.println(clockwiseRotation ? "Clockwise" : "Anticlockwise");

    // Update the encoder count
    encoderCount++;
    }

    // Print the analog value
    Serial.print("Analog Value: ");
    Serial.println(val);

    // Delay to stabilize readings (adjust as needed)
    delay(10);
    }

    Any help would be appreciated. Thanks.

    Attached Files:

    • PIM.png
      PIM.png
      File size:
      104.5 KB
      Views:
      103
  6. GT40

    GT40 New Member

    Joined:
    Sep 19, 2023
    Messages:
    4
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    Good Morning,

    I have been lurking for quite a while now and figured after reading enough, I would just get it. I was wrong. I ordered a DOF P3 and uses the orange sensors for feedback (pot?). I want to convert it from the ATMEGA2650 to the Arduino Uno, R3; this requires a rewiring.

    I am a little confused with the code as to why pin 2 and pin 3 from the Arduino are not symmetrical to the IBT-2 H-bridge pins, on the diagram provided by @eaorobbie, while the code looks symmetrical. Specifically pin 3 is wired to both left and right enable, pin 2 is set to L_PWM, and pin 9 is set to R_PWM. I would have expected the following:

    pin 9 set to left and right enable
    pin 2 set to L_PWM
    pine 3 set to R_PWM

    For example, where motors are driven, the code looks "symmetrical from pin 2 and 3 in the Arduino"

    Recalling that:
    const int ENApin1 =2; // ENA output pin for Motor H-Bridge 1 (ie PortD bit position)
    const int ENBpin1 =3; // ENB output pin for Motor H-Bridge 1 (ie PortD bit position)
    const int PWMpin1 =9; // PWM output pin for Motor

    "MyPWMWrite(PWMpin1, PWMrev1);" tell me that pulse-width modulation is sourced from Arduino, Port D, pin 9.

    // Drive Motor Backwards
    PWMout1 = abs(PWMout1);
    PWMout1+=PWMoffset1;
    if(PWMout1 > PWMmax1){PWMout1=PWMmax1;}
    OutputPort &= ~(1 << ENApin1); // Unset Motor1 In 1
    OutputPort |= 1 << ENBpin1;

    // Drive Motor Backwards
    PWMout1 = abs(PWMout1);
    PWMout1+=PWMoffset1;
    if(PWMout1 > PWMmax1){PWMout1=PWMmax1;}
    OutputPort &= ~(1 << ENApin1); // Unset Motor1 In 1
    OutputPort |= 1 << ENBpin1;

    I would have expected something like:
    // Drive Motor Backwards
    pin 9 to send a PWM to left and right enable on IBT_2
    pin 2 set to low on L_PWM
    pin 3 set to high on R_PWM

    // Drive Motor Forwards
    pin 9 to send a PWM to left and right enable on IBT_2
    pin 2 set to high on L_PWM
    pin 3 set to low on R_PWM

    Am I missing something in my logic or some part of the code? Or this a misunderstanding of how the IBT_2 works?

    Thank you kindly, this is an awesome site and a lot of incredible builds out there. It blows my mind how much detail people put into their designs and appreciate your letting me join your community.
  7. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,029
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,872Coins
    Ratings:
    +10,876 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    The SMC3 code, set to Mode 2 for IBT2, is by @RufusDufus, not @eaorobbie, as per the first page of this thread.
  8. Murray Bester

    Murray Bester New Member

    Joined:
    Sep 4, 2023
    Messages:
    14
    Balance:
    84Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Hi, I have a MD13S 13A motor driver that I'd like to use for my sim rig, you can find the specs for the driver here: 13Amp 6V-30V DC Motor Driver (cytron.io)
    I'd like to know how I would connect the DIR and PWM pins to the arduino. I assume that the PWM pin can be connected to pin D9 on the arduino but I'm not sure whether to connect the DIR pin to D2 or D3 on the arduino? Do I only connect it to one of them or perhaps both? Additionally, am I correct in assuming that I would use the SMC3 software in mode 1 for this particular driver?
    Thanks!
  9. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,029
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,872Coins
    Ratings:
    +10,876 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Check out the specific Cytron modded SMC3 code and associated wiring diagram in the FAQs: https://xsimulator.net/community/faq/cytron-md13s-for-smc3.358/
  10. GT40

    GT40 New Member

    Joined:
    Sep 19, 2023
    Messages:
    4
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    I am running in mode2 and completely agree that it is by @RufusDufus, not @eaorobbie. @RufusDufus credited his diagram on page1 to @eaorobbie.

    My question is either an electrical engineering question or a programming question as I am trying to understand why Arduino pin 3 is treated differently in the wiring diagram than pin 2, when in the code they seem equivalent. There is either a typo in the diagram or the code (neither is likely). It is more likely that my mental model for how the IBT_2 works for the enable and PWM pins is incorrect and I just need to understand why they are treated differently. Is it like putting a NPN and an PNP transistors in series as a totem pole connection of two complementary BJT's, also known as Push/Pull? Is there a reason for the difference to how pin 2 and pin 3 is wired in the Arduino?

    I was able to assign Arduino pin 9 on the IBT to both R/L enable pins on the IBT_2 and use pins, 1 and 2 of Arduino for drive the motor bidirectionally through R_PWM and L_PWM. I realize in SMC3 we don't want to use pin 1 (Arduino) because we want that available for serial communication, so we use 2 and 3 (Arduino).

    Here is my code. You will notice it is very similar in function to SMC3, but my wiring is slightly different in that I treat pins 1 and 2 exactly the same. SMC3 code doesn't work if I do it that way and it is not clear why.

    My code works for driving a motor back and forth, which is most of what I need. Where it fails is that it doesn't incorporate feedback into the system so that two motors in phase eventually, mechanically drift apart.

    #define Pin_D1_L 1 //Arduino pin 1 digital output RPWM
    #define Pin_D2_L 2 //Arduino pin 2 digital output LPWM
    #define Pin_E_L 9 //digital output PWM pin (analog output)

    void setup()
    {
    pinMode(Pin_D1_L, OUTPUT);
    pinMode(Pin_D2_L, OUTPUT);
    pinMode(Pin_E_L, OUTPUT);
    motor_stop();
    }

    void loop()
    {
    motor_stop(); delay(1500);//motor stop
    for (int i = 0; i <= 65; i++)
    {
    analogWrite(Pin_E_L,65*sin(2*PI*i/360)); //drive motor CCW sine wave
    digitalWrite(Pin_D1_L, HIGH);
    digitalWrite(Pin_D2_L, LOW);
    delay(7);
    }
    motor_stop(); delay(1500);
    for (int i = 0; i <= 65; i++)
    {
    analogWrite(Pin_E_L,65*sin(2*PI*i/360)); //drive motor CW sine wave
    digitalWrite(Pin_D1_L, LOW);
    digitalWrite(Pin_D2_L, HIGH);
    delay(7);
    }

    }

    void motor_stop()
    {
    digitalWrite(Pin_D1_L, LOW);
    digitalWrite(Pin_D2_L, LOW);
    analogWrite(Pin_E_L, 0);//0-255
    }
  11. GT40

    GT40 New Member

    Joined:
    Sep 19, 2023
    Messages:
    4
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
  12. GT40

    GT40 New Member

    Joined:
    Sep 19, 2023
    Messages:
    4
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    Ok this might be what I was looking for:

    In essence, I am not sure why PMW is assigned to pin 9 in the Arduino code, and 2,3 nominally should be on equal footing in the code, but are wired differently. It is almost like 1.RPW 2. LPW should have been physically swapped with 3. and 4. R_EN and L_EN tracing back to PWM pin 9.

    Mode 2 is probably running in "usage two" below
    http://www.hessmer.org/blog/2013/12/28/ibt-2-h-bridge-with-arduino/

    [​IMG]

    This paradox may be resolved in the following comment unfiltered:

    "These boards definitely can’t be used with a single PWM pin. The half-wit chinese board torturer who designed this thing named the enable pins R and L but there is no relation to the driving direction. They are just the enable pins for each of the two half-bridges on the board. (The L pin for the right of them and vice versa) Unless you activate them both, there is no function at all.
    Therefore, it is not possible using only one PWM pin without further parts. With some additional logic you could easily use one PWM pin and one direction select pin.

    I can’t even articulate my anger against such people. This board must have consumed thousands of hours of good people trying to figure out why the directional enable pins do not enable any direction, bringing despair to beginners and spoiling a nice hobby for so many."
  13. hansvdm

    hansvdm Member

    Joined:
    Sep 21, 2023
    Messages:
    57
    Occupation:
    Freelance
    Location:
    leiden Netherlands
    Balance:
    107Coins
    Ratings:
    +10 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Hi, all I followed the tutorial but got stuck at the end.
    I got the motors working and used the smc3 tool to test it. The only thing i see is that not my green line is moving but the yellow line is moving when adding pwmmax. Is this an issue? When i use motion to test it also does work.
    But when using the simtool program i cant seem to get it working. I used the settings provide. See screenshots. But when testing with the output the motors wont move. I cant figure it out.
    20230929_180109.jpg 20230929_175641.jpg 20230929_175654.jpg
  14. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,029
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,872Coins
    Ratings:
    +10,876 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    In SMC3 when tracking it whould look something like this:
    [​IMG]
  15. hansvdm

    hansvdm Member

    Joined:
    Sep 21, 2023
    Messages:
    57
    Occupation:
    Freelance
    Location:
    leiden Netherlands
    Balance:
    107Coins
    Ratings:
    +10 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    THanks it seems like it works. What i am confused about is using the utility software and the game engine. Am i correct that you configure the motors in the utility and those settings are saved somewhere? And then the game just adjusts the position slider? I first thought the utility was just to test the eniges not to use the to configure the motors. Are there any recommended settings for the utility program?
  16. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,029
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,872Coins
    Ratings:
    +10,876 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    The SMC3 Utility configures the Arduino settings for your particular hardware. Once that is done you don't need to do anything else with it. Don't run SMC3 Utility and SimTools at the same time, as it will cause a port conflict.

    The initial base SMC3 setup is:

    Initial Setup

    I strongly recommend you follow the steps below if this is the first time you are using SMC3 with your simulator to reduce the risk of damaging anything.

    1. Disconnect the motor power supply
    2. Make sure Simtools is not running – we’re not ready for that yet!
    3. Wire up the Arduino (with SMC3 installed) to your H-Bridges and connect to your computer via USB
    4. Run the Windows SMC3 Utility software and make sure it communicates with the Arduino (There is no need to set baud rates, they are not configurable)
    5. Set the Kp, Ki, Kd, PWMmin, PWMmax, PWMrev to 0 for ALL motors (This will make sure the motors don’t move)
    6. Set Clip to 255 (you need to do this first) and Limit to 255 (This will give you plenty of margin if something goes wrong while setting up)
    7. Turn on the power to your motors – nothing should move at this stage!
    8. Set Kp to about 400
    9. Now slowly, increase PWMmax… at some point the motor should start to move. When it does check the “Green” feedback line is moving toward the “Blue” target position.
      • If it is then that motor and feedback is wired correctly - proceed to test other motors.
      • If it is moving away turn off motor power immediately (or quickly reduce PWMmax again). In this case you need to either reverse the wires to the motor being tested –OR– reverse the +5V and GND wires to your feedback pot for the motor being tested (do not do both). Restart the test from the beginning.
    10. Do the above for each motor
    After the basic configuration the settings need to be refined so that tracking is robust for your particular hardware, what the settings need to be depends on your particular hardware, but each of the setting are explained here: https://www.xsimulator.net/communit...driver-and-windows-utilities.4957/#post-48121

    While written with other hardware in mind the basics are the same, so here is a simplified introduction to PID tuning: https://xsimulator.net/community/faq/a-laymans-analogy-guide-to-pids-pid-tuning.219/
  17. Airbas72

    Airbas72 Member

    Joined:
    Oct 20, 2019
    Messages:
    37
    Balance:
    - 7Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    Hello, the other day I purchased an IBT-2, assembled two drives from what I had in the garage to test the firmware, configured it using the utility and attached it all to an old office chair. In the utility everything works well, in SimTools 1.3 it works well, but in SimTools 3 it works jerkily and when entering the settings menu the axes shift by 40 percent in pitch
  18. Airbas72

    Airbas72 Member

    Joined:
    Oct 20, 2019
    Messages:
    37
    Balance:
    - 7Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    This is what the trial version looks like IMG_20231010_221830.jpg
  19. Airbas72

    Airbas72 Member

    Joined:
    Oct 20, 2019
    Messages:
    37
    Balance:
    - 7Coins
    Ratings:
    +4 / 0 / -0
    My Motion Simulator:
    3DOF, Arduino
    I have a question: has anyone tested the firmware with SimTool 3?
  20. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,029
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    147,872Coins
    Ratings:
    +10,876 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    • Like Like x 1