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

Arduino Uno talk to SimTools ?

Discussion in 'New users start here - FAQ' started by marky000, Sep 8, 2014.

  1. marky000

    marky000 New Member

    Joined:
    Aug 23, 2014
    Messages:
    19
    Balance:
    306Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    Arduino
    Guys,

    I think I need some help in getting simple communication between an Arduino Uno card and Sim Tools?

    I have the exact same setup as seen on this link: http://arduino.cc/en/Tutorial/DueMotorShieldDC

    When I upload the arduino code provided on the above link to Arduino IDE, it causes the attached dc motor to move, so arduino wise, the hardware setup is ok.

    I would now like to get some simple motor movement (even just a twitch) via the Game Engine output testing section.

    I have looked at eaorobbie's post here http://www.xsimulator.net/community/marketplace/communicating-with-an-arduino-and-sim-tools.97/ but am still unable to figure out how to get Simtools talking to Arduino. I uploaded the RC Sim Model code to Arduino IDE and then fed it a command of R100~P100~ in the Arduino serial monitor.

    In the serial monitor I got the following reponse:

    read in R
    which is axis 0
    read in 100
    read in P
    which is axis 1
    read in 100

    So from this I assume that eaorobbie's Sim RC Model Code was sucessfully interpreted by Arduino IDE.

    But how can I use this code but have Simtools send the command to Arduino board and ultimately make the DC motor twitch (or at the very least create output data in the Arduino serial monitor).

    I have used the Axis assignments and interface settings provided by earobbie on the same link. But when I go to output testing in Game Engine, I see no activity in the Arduino serial monitor. I did comment out the debug line as instructed.

    I realise that Arduino code can get complicated and in the end may just be too hard to find the info I need to fully understand it. But right now, if I could just try out a few lines of the simplest code possible that will cause a slight movement of a simple DC motor. Even just some activity in the Arduino serial monitor would be great.

    Hopefully Eaorobbie can respond but anyone else that could give me a few ideas would be great.
    Last edited: Sep 10, 2014
  2. marky000

    marky000 New Member

    Joined:
    Aug 23, 2014
    Messages:
    19
    Balance:
    306Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    Arduino
    I think my first problem is the pin assignments I am using. I have seen a few examples of people using servos and connecting them directly to one of the digital pins (i.e. 4,5,7,8 etc).

    However, I am not using a servo for testing but a more simple dc motor seen here (I have exact setup as seen in image):

    http://arduino.cc/en/Tutorial/DueMotorShieldDC

    As you can see, my motors are connected to the Channel A and Channel B connectors on the Arduino Motor shield.

    It is my understanding that:

    Channel A makes use of these 4 pins:
    PWM_A = 3,
    DIR_A = 12,
    BRAKE_A = 9,
    SNS_A = A0;

    Channel B makes use of these 4 pins:
    PWM_B = 11,
    DIR_B = 13,
    BRAKE_B = 8,
    SNS_B = A1;

    Given this information, what changes do I need to make to eaorobbie's code to suit my setup?

    The line of interest in eaorobbie's code is seemingly:

    const int kPins[kActuatorCount] = {4, 5};

    I tried changing it to:

    const int kPins[kActuatorCount] = {3, 11};

    but still no movement so more changes to code are required.
    Last edited: Sep 10, 2014
  3. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,398Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok forget my code its for servo operation , you will need one that does position control and speed. The servos don't need this, they just need a pulse to represent a position to go to.

    Not sure if the motor board would be suited to run this http://www.xsimulator.net/community...3dof-motor-driver-and-windows-utilities.4957/

    But more what you are looking for. Take a read there sorry , my code is to suit servos. As stated in the title.
  4. marky000

    marky000 New Member

    Joined:
    Aug 23, 2014
    Messages:
    19
    Balance:
    306Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    Arduino
    Yeah like I mentioned in my post, I realised ur code was for servos.

    What you are saying is the motors I am using require 3 pins on the Ard (brake and direction controlling position and pwm (pulse) controlling speed. But servos only require the pwm pin (to set position).

    Pretty much confirms what I was thinking. I will check out that link and see if it helps but I think I might just use servos as it sounds like it will be a lot easier.

    Last question but, is there way of monitoring the commands that are being sent to the ard via simtools. At this stage when I turn on output testing in Simtools, the serial monitor in Ard IDE becomes unavailable (due to port being occupied error message). There must be some way of seeing that simtools is sending the command to the Ard? If not, I guess that means I must have connect the servos to the correct pins to test Simtools.
  5. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,398Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Yes the signal Pin from the servo needs to connected to the pin listed in the code, or change the code to represent the pin that they are connected them to and must be a PWM pin (~) in order to work too.

    Monitoring what SimTools is sending to the ard is a hard one as the Ard will not support two communication at the same time on the single usb port (Jrks can do this , lol), can attach a lcd to the Ard and just have it tell you what it is receiving but have found in the past the update to the lcd slows the motion to the motors down badly.
    Best option is to find a USB sniffer program that will monitor what is being sent to the port, plenty avail , google is a friend there.
    • Like Like x 1
  6. marky000

    marky000 New Member

    Joined:
    Aug 23, 2014
    Messages:
    19
    Balance:
    306Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    Arduino
    Thanks @eaorobbie.

    Two more quick ones.

    I am not really mechanically minded (the mate I am helping is however). Just wondering, how a servo controls speed if it only utilises 1 pin and that is for controlling position. Is a servo only a 1-speed motor?

    Also, in your guide, I see your axis assignments were populated as follows:

    CaptureSim.JPG

    What would happen if I configured as follows:

    CaptureSim1.JPG

    I will have some servos soon so I will be able to test then but am not 100% as to how to interpret the axis assignments table. If we have two servos, we have two axis. If we use Roll and Pitch, we have a 2 DOF Sim right? So we have 2 DOF associated with 2 axis, but we only populate the DOF1 column. Seems a little odd.

    I must be over-thinking things here.

    Attached Files:

  7. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0