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 and X-Sim

Discussion in 'SimTools compatible interfaces' started by HammerHead, Oct 30, 2010.

  1. HammerHead

    HammerHead New Member

    Joined:
    Oct 30, 2010
    Messages:
    6
    Balance:
    0Coins
    Ratings:
    +1 / 0 / -0
    Hello.
    I'll keep it short - what should I do to export axis data from Force Profiler 2 to Arduino? I've bought it before I first heard of X-Sim and I'm looking for a way to connect Arduino with X-Sim Force Profiler.
    As you can see, I'm a new and inexperienced member, so ask any questions and I'll try to answer them as accurate and soon as possible. :)

    Thanks.
    • Informative Informative x 1
  2. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    Hi HammerHead and welcome.

    You can easily send data out through COM ports (Serial RS232, or USB-Serial adapters) from the USO of the Profiler.

    There are short descriptions beside the settings. Setting up is straight forward:
    -Make sure you have incoming data from Sender (use TestPlugin), and you have your axis properly set up.
    -Add COM port from list (top).
    -Set axis to 8-16-32bit resolution and what type of format you want it to be sent out (~a01~ ~a02~ etc)
    -Set up COM port.
    -Type in the format you want information to be sent out. Example: SY~a01~X~a02~E
    -Click Start.
  3. HammerHead

    HammerHead New Member

    Joined:
    Oct 30, 2010
    Messages:
    6
    Balance:
    0Coins
    Ratings:
    +1 / 0 / -0
    Many thanks, I'll try that. :)
    If I'll encounter any more problems, I'll let everybody know.

    EDIT - I got the hardware up and running and I have successfully exported data from Condor to Arduino (the LED is on, so there is data flow). The format of output is B ~a02~ which means, that a variable B is sent with a value of a02 (which is one of the working axis). I don't know if it is the proper place, but I need to ask - can someone help me with writing a code for Arduino to input the data form X-Sim?

    EDIT2 - Problem solved, moving on. :)
  4. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi Hammerhead! I just ordered Arduino Mega 2560. At first to freshen up my C skills, but later... nobody knows.
    Have you found any code for this purpose already, or have you started from zero?
  5. HammerHead

    HammerHead New Member

    Joined:
    Oct 30, 2010
    Messages:
    6
    Balance:
    0Coins
    Ratings:
    +1 / 0 / -0
    You can say I pretty much started from zero. Arduino comes with a set of example programs, which I modified to make such program:

    Code:
    #include <Servo.h>
    
    Servo myservo;
    int pos=0;
    
    void setup()
    {
      Serial.begin(9600);
      myservo.attach(9);
    }
    
    void loop()
    {
      for(pos = 0; pos < 180; pos=Serial.read())
      {
        myservo.write(pos);
        delay(15);
      }
    }
    It reads the position of axis and spins the electric motor accordingly, so it assumes position sent by X-Sim. For now I can read only one axis, but it shouldn't be a problem to split Serial.read() into more variables - just a little bit of coding. I'm working in a team, and only one person can use Arduino, so I won't be able to help you much further, but making yourself a working slipball (if flightsim) or gear shift helper (if driving sim) with Arduino and some LEDs should be a first priority - lots of fun and it's quite useful. You might also want to use some connector board (or how it is called), and loose wires. Any more questions, just let me know. :)
  6. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi Hammerhead!
    So you already can move servo with data acquired from X-Sim software through serial connection? I think that's a very good start! :)
    As I said earlier I ordered Arduino to freshen up my C -coding skills. First blinking LEDs etc... starting from basics again. (I've studied embedded systems some years ago.)
  7. Silly(c)One

    Silly(c)One New Member

    Joined:
    Oct 11, 2010
    Messages:
    68
    Occupation:
    ex-Web & Industrial Dev/Sysadmin
    Location:
    Brussels, Belgium
    Balance:
    327Coins
    Ratings:
    +0 / 0 / -0
    Hello,

    I'm currently in the process of writing a software chain for the Arduino and X-Sim. It consists of a Desktop application that communicates with the Arduino to setup the dashboard (max rpm, rpm limits for the led bars, rev counter calibration) and of course an Arduino Sketch that can communicate by serial with both the configuration app and X-Sim.
    The desktop app is coded in Titanium (HTML5+CSS3+Javascript+Ruby) and the Arduino app is off course in C/C++.
    Once the code is done, I'll publish it on the forums. It could serve as a code base for anyone using an Arduino to control his dashboard with X-Sim, so maybe I'll publish a generic squeleton of the app instead of my own case. That will depend on the time I can spend on it.

    Cheers,
    Silly(c)One.
  8. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hello again coders! I got my LCD display running and started to learn to use X-Sim software. I used test-tablet to input some values to Arduino. I mapped test-tablet slider to Axis 1 and configured datapacket like this: S~a01~E. Seemed to work guite well. Question: Why 127 is minimum value Arduino can read? Max is 255.
  9. Silly(c)One

    Silly(c)One New Member

    Joined:
    Oct 11, 2010
    Messages:
    68
    Occupation:
    ex-Web & Industrial Dev/Sysadmin
    Location:
    Brussels, Belgium
    Balance:
    327Coins
    Ratings:
    +0 / 0 / -0
    Hi,

    The Arduino is an 8 bit microprocessor, meaning his base unit of calculation is the byte, from 0 to 255.
    Your symptom makes me think of a signing issue : if you declare a char as signed, its value will go from -127 to +127.

    What do you mean by the minimum value the Arduino can read ? on reading an analog pin ? or the values from X-Sim by serial communication ? If so, you have to write your value in ASCII (not digital) and decode it on the Arduino one char by one.
  10. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi,
    I know that Arduino is 8bit controller, so I assumed to see values from 0 to 255 on my LCD screen.
    I mean values read through serial communication.

    I know, that problem here is that I can't use X-Sim USO well enough. I have read that little manual and tutorial various times...

    My X-Sim chain is: test-tablet slider 21 configured like values from 0 to 255. -> I can see values changing in input screen. -> mapped slider 21 to Axis 1 ->
    trying to send those values from 0 to 255 through serial to Arduino.
    Datapacket is configured like: S~a01~E. I read S and E like as chars. What type should I use for value coming in as ~a01~? Byte?

    How I configure X-Sim to write value in ASCII?
  11. Silly(c)One

    Silly(c)One New Member

    Joined:
    Oct 11, 2010
    Messages:
    68
    Occupation:
    ex-Web & Industrial Dev/Sysadmin
    Location:
    Brussels, Belgium
    Balance:
    327Coins
    Ratings:
    +0 / 0 / -0
    In the USO configuration, you can find the format of the numbers sent to serial : you have the choice between byte/word/double word and binary, decimal and hexadecimal. I guess (I'm still having trouble with this part of X-Sim and the math section changing the values to 32 bits) you should chose byte and decimal and try from there.

    You should read ~a01~ as chars and then convert it to an int. That's quite easy to do, just remove '0' from the ASCII values to get the digits.
  12. HammerHead

    HammerHead New Member

    Joined:
    Oct 30, 2010
    Messages:
    6
    Balance:
    0Coins
    Ratings:
    +1 / 0 / -0
    127 should be the middle value I think.
    And I'm absolutly sure, that I've made a slipball connected to stepper electric engine, with min value of 0, mid in 127 and max at 225. The engine could rotate form 0 to 180, with center at 90 degrees. I had to make Arduino calculate it, but it's irrelevant here.

    tl;dr - Arduino can read from 0 to 255 for sure, it can even process negative values.
  13. johnr

    johnr New Member

    Joined:
    Nov 7, 2009
    Messages:
    26
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    When you send data to external interface over USO you are not limited to byte (0-255). You may choose to transform data off the sim into a byte to minimize the data transfer over USB but you do so at the cost of resolution. On the Arduino side you just need to appropriately parse the data.
  14. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi all! Thanks for supporting me! As you can see I am beginner with Arduino and especially with serial data transfer.
    At starters, I just wanted to see number to change from 0 to 255 on my LCD screen as I move slider on test-tablet of X-Sim. I am little confused about that, can I get for example value 255 through serial in one byte, or do I have to parse it like value=hundreds*100+tens*10+5.
  15. Silly(c)One

    Silly(c)One New Member

    Joined:
    Oct 11, 2010
    Messages:
    68
    Occupation:
    ex-Web & Industrial Dev/Sysadmin
    Location:
    Brussels, Belgium
    Balance:
    327Coins
    Ratings:
    +0 / 0 / -0
    You can get a value up to 255 in one byte, chose the binary format in Profiler USO.
    Else indeed, you have to parse it like value = hundreds*10^2 + tens*10^1 + units*10^0.

    To get a slider, chose the TestPlugin in Force Sender, and create a math line on the axis you want. To test it, start the Sender and Profiler.

    For debug purposes, as you're working with an LCD, it's easy : just display everything that comes from serial !
  16. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    X-Sim can transmit data in 3 different formats: binary, decimal, hexadecimal. Each of these are suited for different applications.

    If you want to display the numbers on an LCD, transmitting each digit separately in decimal would be better because the LCD has to display each digit separately as well. If you send it as a binary, you will have to strip this binary apart and convert it into separate digits.

    If you want to do calculations with the data, it needs to be in binary.
  17. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Ok, thanks again. I just can't use X-Sim somehow... If I put only for example ~33~ (which is ! ascii) on Datapacket and axis information -row I can get right data trough to my LCD with this code:
    Code:
    #include <LiquidCrystal.h>
    LiquidCrystal lcd(22, 23, 24, 25, 26, 27);
    
    void setup() 
    {
      Serial.begin(9600);
      lcd.begin(20, 4);
      lcd.print(serialport:);
      lcd.setCursor(0, 1);
    }
    
    void loop() 
    {
      
      char data;
      
      
      if(Serial.available())
      {
        data=Serial.read();
        delay(10);
        lcd.print(data);
        lcd.print(data, DEC);
        delay(1000);
        
       }
    }
    So !33 comes to my LCD. But if I start to mess with test-tablet based Axis -information ~a01~ etc... :thbd:
  18. HammerHead

    HammerHead New Member

    Joined:
    Oct 30, 2010
    Messages:
    6
    Balance:
    0Coins
    Ratings:
    +1 / 0 / -0
    Remember one thing - I may have misunderstood you, but it's important anyway.

    If you're transmitting ~33~, you're not transmitting !, but ~, 3, 3 and ~ - so that's four chars at the same time. If you want to transmit 33 which is !, then type ! in datapacket and axis information. And don't use ~ - they're only needed to define a variable I suppose.
  19. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi Hammerhead!
    I know there is no sense to send ~33~. But in USO documentation, there were hint that if you want to send for example linefeed(~10~) or return(~13~) you can use it like this. So for debug reasons, I tried to send something visible like that and it worked properly.
    I read documentation once again, and now I might know what's wrong. (problem only getting values 127-255 through) Because I remapped test-plugin slider values from 0 to 255, in math setup I can get only positive side values in graph. So, if 0 there is middlepoint in output, it makes sense why I only get 127 lowest value...
  20. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    i take a lot of time to figure out USO. now its work in my controller