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

Problem Sending Data To Arduino

Discussion in 'DIY Motion Simulator Projects' started by MagicMike, Feb 10, 2014.

  1. MagicMike

    MagicMike New Member

    Joined:
    Jan 26, 2014
    Messages:
    24
    Balance:
    961Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino, Motion platform
    I am trying to send data to my arduino but with no chance. I made a Circuit with arduino and 3 leds on pins 2,3,4. I want to dim the leds according to the game data but i had no chance. How i can setup my SimTool to send data safety to arduino board? Also i am trying to write a small piece of code to send the data to leds. Thanks!

    My arduino board receives only 255 ,255,255
    Last edited: Feb 11, 2014
  2. 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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok heres a code that I wrote for controlling a fan with the speed value from gamedash.
    This too can be used to recieve an axis information.
    Ok from this the interface setting need to look like this below.
    Interface for one axis.png

    Plus dont forget to be able to test this with SimTools GameEngine - Output Testing you need to set Axis 1 in the default Axis Assignments to be at least one force.
  3. MagicMike

    MagicMike New Member

    Joined:
    Jan 26, 2014
    Messages:
    24
    Balance:
    961Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino, Motion platform
    // This just works with one axis from SimTools.
    int Axis1 ;
    int Axis1SimTools = 0;
    int bufferArray[4];
    int LedA=2;
    int LedB=3;
    int LedC=4;

    void setup(){

    Serial.begin(9600);

    pinMode(LedA,OUTPUT);
    pinMode(LedB,OUTPUT);
    pinMode(LedC,OUTPUT);

    }

    void loop(){
    //****************************** READ DATA FROM SERIAL ******************************
    ReadData();
    }

    void ReadData(){
    if (Serial.available() == 4); { //if 4 bits available in the Serial buffer...

    int x;
    for (x=0; x<4; x=x+1) { // read and label each byte.
    bufferArray[x] = Serial.read();
    }

    if (bufferArray[0] == 'A'){
    Axis1SimTools = ((bufferArray[1]-48)*100) + ((bufferArray[2]-48)*10) + ((bufferArray[3]-48)*1);

    analogWrite(LedA,Axis1SimTools);
    analogWrite(LedB,Axis1SimTools);
    analogWrite(LedC,Axis1SimTools);
    }
    }
    }

    And nothing happens again :( .. any idea? thank you guys!

    Attached Files:

  4. prilad

    prilad Well-Known Member SimAxe Beta Tester SimTools Developer

    Joined:
    Apr 29, 2012
    Messages:
    380
    Location:
    Dubna, Russia
    Balance:
    9,639Coins
    Ratings:
    +512 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, 4DOF
    For @eaorobbie's sketch you should set "Output Type" as "Decimal"
    • Useful Useful x 1
  5. MagicMike

    MagicMike New Member

    Joined:
    Jan 26, 2014
    Messages:
    24
    Balance:
    961Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino, Motion platform
    void loop(){
    Axis1=Serial.read();
    }

    This returns -1 .. :(
    Last edited: Feb 12, 2014
  6. 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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Thanks @prilad yes decimal is needed in order for the above sketch to work properly, and depending on the speed of you machine you might find that slowing it down to say 20ms might result in smoother running of code.
    From my original code you can invoke the serial communication and test via the serial monitor in Ard IDE to make sure it works before testing in simtools.

    Opps your using more than one axis, each axis contains 4 bits so you need to increase the array in order to read all the correct axis info coming in , should be 12 for your code.
    Will make changes and test and come back with a solution mate.

    Plus I made a booboo this code is for Gamedash use. Sorry will post a better one soon
    • Like Like x 1
    • Useful Useful x 1
    Last edited: Feb 14, 2014
  7. 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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok fixed the above code.

    Now you can test this in the Ard IDE serial monitor with A255B255C255 and all leds should light up changing the values to smaller values should now dim the lights, once confirmed you can use your above interface settings but use decimal not binary. And output string needs to be A<Axis1>B<Axis2>C<Axis3>
    • Useful Useful x 1
  8. MagicMike

    MagicMike New Member

    Joined:
    Jan 26, 2014
    Messages:
    24
    Balance:
    961Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino, Motion platform
    thank you very much! I finaly got it how it works. Now i have place also an LCD screen and i am watching the 3 axis Roll , Yaw and Pitch! The next step now is to wire 3 stepper motors on my circuit and start working on that! :) :) :)
  9. mirkobastianini

    mirkobastianini Active Member

    Joined:
    Jan 23, 2017
    Messages:
    193
    Occupation:
    informatic
    Location:
    italy
    Balance:
    1,300Coins
    Ratings:
    +77 / 2 / -0
    My Motion Simulator:
    2DOF
    Sorry for my post, but i'm very sad because I cant' get work.... maybe I need to create a new thread, but first I will try to post here.

    My goal is to see on LCD data from simTools with Arduino (like the post of MagicMike). I've configured correctly SimTools and Virtual Axis works. In "1.png" you can see my Interface Settings, in "2.png" my axis assignments and in "3.png" my output testing... But the result on my LCD is useless ("4.png"). I've tried several codes and the results is the same.. in particular, in this case I use this code:

    Code:
    int Axis1 ;
    int Axis1SimTools = 0;
    int bufferArray[4];
    
    #include <LiquidCrystal.h>
    LiquidCrystal lcd(9, 8, 2, 3, 4, 5);
    void setup() {
    // Open serial communications and wait for port to open:
    Serial.begin(9600);
    
    lcd.begin(16, 2); 
    lcd.write("HELLO");
    }
    
    void loop() {
    ReadData();
    }
    
    void ReadData(){
    if (Serial.available() == 4) { //if 4 bits available in the Serial buffer...
    int x;
    for (x=0; x<4; x=x+1) { // read and label each byte.
    bufferArray[x] = Serial.read();
    }
    if (bufferArray[0] == 'A'){
    Axis1SimTools = ((bufferArray[1]-48)*100) + ((bufferArray[2]-48)*10) + ((bufferArray[3]-48)*1);
    lcd.setCursor(0,1);
    lcd.write(Axis1SimTools);
    }
    }
    }
    What is the problem? Where I can find a short guide of how to write correctly the .ino file for simtools?

    Thanks

    Attached Files:

    • 1.png
      1.png
      File size:
      193.9 KB
      Views:
      583
    • 2.png
      2.png
      File size:
      197.3 KB
      Views:
      581
    • 3.png
      3.png
      File size:
      173.9 KB
      Views:
      552
    • 4.jpg
      4.jpg
      File size:
      159.2 KB
      Views:
      484