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. Poppius

    Poppius New Member

    Joined:
    Nov 10, 2010
    Messages:
    14
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Ok, now I got it working like I wanted at this point of my career. :) Only thing which was wrong was test-tablet configuration, where I put max 255 and min 0. In Math setup graph this configuration shows only positive values, and I though it was right. But then I once again read tutorials and there were said that middlepoint is 127 in output... So I conffed test-tablet to max/min 2000 and output 8bit one characer. Then I read that char to unsigned int in Arduino, and it works like I wanted...
    Thanks all! :cheers:
  2. 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
    Nice one !

    Please keep us posted with your project :beta:
  3. Nikka93

    Nikka93 New Member

    Joined:
    Dec 16, 2010
    Messages:
    3
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi I am using a Arduino UNO but I cant display RPM.
    In Force Profiler it read the correct value but I don't know how to send it to Arduino.

    I sent the speed value correctly but RPM don't work :?
  4. xeriv

    xeriv New Member

    Joined:
    Dec 29, 2010
    Messages:
    3
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hello,
    May i know what i need to put into datapacket part of USO to send the data to arduino uno? ~255~~9~~a01~/S~a01~E ?
    Regarding the coding part, how to split the Serial.read() to control 2 servos?
    myservo.attach(9,10);
    Serial.read(x,y)
    Thank you...
  5. Menix

    Menix Member Gold Contributor

    Joined:
    Mar 8, 2010
    Messages:
    76
    Balance:
    99Coins
    Ratings:
    +6 / 0 / -0
    How do you setup the Arduino Card in Force Profiler?
  6. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    You set up Profiler in arduino.. :D

    You have to program arduino to receive data in a certain way, and you have to send this specific data from profiler.
  7. Menix

    Menix Member Gold Contributor

    Joined:
    Mar 8, 2010
    Messages:
    76
    Balance:
    99Coins
    Ratings:
    +6 / 0 / -0
    oh
    hmm has anybody a ready Sketch for programming Arduino Duemillenove?
    For receiving Data?
    Im totally new in Arduino programming
  8. Frakk

    Frakk Active Member

    Joined:
    Apr 15, 2009
    Messages:
    1,144
    Balance:
    328Coins
    Ratings:
    +4 / 0 / -0
    If you are new to arduino, wouldn't it be a good idea to learn the basics before you jump into programming and interfacing?

    There are many tutorials and sample programs around.
  9. Menix

    Menix Member Gold Contributor

    Joined:
    Mar 8, 2010
    Messages:
    76
    Balance:
    99Coins
    Ratings:
    +6 / 0 / -0
    hmm
    means this i have to program evry move from profiler and evry step to Arduino? Or is it only 1 routine to get the data from xsim?
    if its to much to programming Than i will buy a new K8055.
  10. xeriv

    xeriv New Member

    Joined:
    Dec 29, 2010
    Messages:
    3
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    I've used the HammerHead code to programmed the uno...
    S~a01~E for uso...

    the motor keep spinning if stop and it will shaking if i start the profiler...
    i've tried S~a01~~90~(motor spins fast)/S~a01~~1~(motor spins slow)

    i need to know what is the correct format for uso... :sos:
    thank you.
  11. Menix

    Menix Member Gold Contributor

    Joined:
    Mar 8, 2010
    Messages:
    76
    Balance:
    99Coins
    Ratings:
    +6 / 0 / -0
    any news here with Arduino?
  12. juniou

    juniou New Member

    Joined:
    Jan 8, 2011
    Messages:
    12
    Location:
    Brazil
    Balance:
    271Coins
    Ratings:
    +0 / 0 / -0
  13. Menix

    Menix Member Gold Contributor

    Joined:
    Mar 8, 2010
    Messages:
    76
    Balance:
    99Coins
    Ratings:
    +6 / 0 / -0
    very nice.
    can you send me the picture of the profiler setup and the sketch for the arduino please?
  14. juniou

    juniou New Member

    Joined:
    Jan 8, 2011
    Messages:
    12
    Location:
    Brazil
    Balance:
    271Coins
    Ratings:
    +0 / 0 / -0
    Hi,
    the sketch below, it is not a P.I.D sketch yet, is only a servo-control that drives the motor to value mapped from USO (0-255) 8bit resolution. the sketch has a better perform running in 9600bps, because the Read_Lateral (function) uses delay to wait strings from serial... this code is based on http://roamingdrone.wordpress.com/2008/ ... ntiometer/

    xsime-arduino.gif

    ---------------- sketch begin --------------------------
    #define MOTOR_EN_PIN 6
    #define MOTOR_RT_PIN 2
    #define MOTOR_LT_PIN 3
    #define MOTOR_EN_PIN2 9
    #define MOTOR_RT_PIN2 4
    #define MOTOR_LT_PIN2 5

    int motor_speed = 255;
    int motor_cur_pin = MOTOR_RT_PIN;
    int motor_cur_pin2 = MOTOR_RT_PIN2;

    // control indicators
    bool motor_started = false;
    bool first_run = true;
    bool motor_run = false;

    bool motor_started2 = false;
    bool first_run2 = true;
    bool motor_run2 = false;

    int cur_reading = 0;
    int cur_reading2 = 0;

    char kind_of_data;

    int lateral = 0;
    int Lateral1 = 0;
    int Lateral10 = 0;
    int Latreal100 = 0;

    int MAX = 0;
    int MIN = 0;
    int MAX_ant = 0;
    int MIN_ant = 0;

    void setup() {

    Serial.begin(9600);
    // Serial.println(Ready);


    pinMode(MOTOR_EN_PIN, OUTPUT);
    pinMode(MOTOR_EN_PIN2, OUTPUT);
    pinMode(MOTOR_LT_PIN, OUTPUT);
    pinMode(MOTOR_RT_PIN, OUTPUT);
    pinMode(MOTOR_LT_PIN2, OUTPUT);
    pinMode(MOTOR_RT_PIN2, OUTPUT);
    pinMode(A0, INPUT);
    pinMode(A5, INPUT);

    digitalWrite(MOTOR_LT_PIN, LOW);
    digitalWrite(MOTOR_RT_PIN, LOW);

    digitalWrite(MOTOR_LT_PIN2, LOW);
    digitalWrite(MOTOR_RT_PIN2, LOW);

    }

    void loop() {

    //
    //Recebe dados via serial COM
    while(Serial.available() > 0)
    {
    kind_of_data = Serial.read(); //string from USO --> L~a01~ A~a02~ 8bit resolution\decimal output
    if (kind_of_data == 'L' ) Read_Lateral();
    //if (kind_of_data == 'A' ) Read_Aceleracao();
    }

    // ler posicao pot
    cur_reading = analogRead(0);
    cur_reading2 = analogRead(5);

    if( motor_run == true ) {
    if( (motor_cur_pin == MOTOR_RT_PIN && cur_reading >= MAX ) ||
    ( motor_cur_pin == MOTOR_LT_PIN && cur_reading <= MIN ) ) {

    // we've reached our maximum point (don't want to harm our
    // potentiometer

    motor_run = false;
    motor_started = false;
    motor_stop();
    }
    else if( motor_started == false ) {
    analogWrite(motor_cur_pin, motor_speed);
    motor_started = true;
    first_run = true;
    }
    }
    }

    void Read_Lateral(){
    delay(1);
    int Lateral100 = Serial.read()- '0';
    delay(1);
    int Lateral10 = Serial.read()- '0';
    delay(1);
    int Lateral1 = Serial.read()- '0';

    //Verifica se e centena dezena ou decimal... =]
    if (Lateral1 < 0) { lateral = Lateral10 + 10*Lateral100; }
    if (Lateral1 < 0 && Lateral10 < 0) { lateral = Lateral100; }
    if (Lateral100 < 0) { lateral = 127; }
    if (Lateral1 >=0 && Lateral10 >= 0 && Lateral100 >= 0) { lateral = 100*Lateral100+10*Lateral10+Lateral1; }

    // Verifica se o valor anterior é o mesmo ou mudou..
    if (MAX != map(lateral,0,255,100,710)) { MAX = map(lateral,0,255,100,710); }
    if (MIN != map(lateral,0,255,100,710)) { MIN = map(lateral,0,255,100,710); }

    cur_reading = analogRead(0);

    //Seta os limetes para que o motor pare de funcionar..
    if (cur_reading > MAX && map(lateral,0,255,100,710) != MAX_ant) {go_left();} else
    if (cur_reading < MAX && map(lateral,0,255,100,710) != MAX_ant) {go_right();}

    //Atualiza leitura anterior com a atual...
    MAX_ant = MAX;
    MIN_ant = MIN;

    // Serial.println(cur_reading);
    }


    void go_left() {
    digitalWrite(MOTOR_LT_PIN2, HIGH);
    digitalWrite(MOTOR_RT_PIN2, LOW);
    motor_cur_pin = MOTOR_LT_PIN;
    motor_run = true;
    }

    void go_right() {
    digitalWrite(MOTOR_LT_PIN2, LOW);
    digitalWrite(MOTOR_RT_PIN2, HIGH);
    motor_cur_pin = MOTOR_RT_PIN;
    motor_run = true;
    }

    void motor_stop() {
    digitalWrite(MOTOR_LT_PIN2, LOW);
    digitalWrite(MOTOR_RT_PIN2, LOW);
    motor_run = false;
    motor_started = false;
    }


    -- eof ------

    13012011(002).jpg

    Maybe we can change this to a PID control with this: http://www.arduino.cc/playground/Code/PIDLibrary
    See you
  15. Menix

    Menix Member Gold Contributor

    Joined:
    Mar 8, 2010
    Messages:
    76
    Balance:
    99Coins
    Ratings:
    +6 / 0 / -0
    thank you very much.
  16. kubing

    kubing Member

    Joined:
    Sep 27, 2010
    Messages:
    259
    Occupation:
    teacher, Industrial electronic programmer
    Location:
    kelantan Malaysia
    Balance:
    350Coins
    Ratings:
    +0 / 0 / -0
    great work.. :D
  17. EL-CORAZON

    EL-CORAZON New Member Gold Contributor

    Joined:
    Feb 28, 2011
    Messages:
    28
    Location:
    stavanger Norway
    Balance:
    372Coins
    Ratings:
    +1 / 0 / -0
    Hi Menix.. have you got it working?
  18. definal

    definal 2DOF Platform

    Joined:
    May 24, 2011
    Messages:
    6
    Location:
    Bandung
    Balance:
    - 363Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    Dear juniou,

    i'm interesting with your project using arduiono + dsmhb, please send us the layout for connecting? and also the complete coding.

    thank you very much
  19. juniou

    juniou New Member

    Joined:
    Jan 8, 2011
    Messages:
    12
    Location:
    Brazil
    Balance:
    271Coins
    Ratings:
    +0 / 0 / -0
    definal,
    you can define your own layout,
    you just need to declare the variables according to you cable connections... like:

    #define MOTOR_EN_PIN 6
    #define MOTOR_RT_PIN 2
    #define MOTOR_LT_PIN 3
    #define MOTOR_EN_PIN2 9
    #define MOTOR_RT_PIN2 4
    #define MOTOR_LT_PIN2 5


    I sugest you to understand how Dsmhb from Thanos works...
    and check some codes on www.arduino.cc Digital\Analog pins examples...
    If you have some basics of how it works... you can define your own cable pinout between arduino pins and dsmhb pins

    The above code, is the complete sketch, and the cable layout is on the code ;-)
  20. juniou

    juniou New Member

    Joined:
    Jan 8, 2011
    Messages:
    12
    Location:
    Brazil
    Balance:
    271Coins
    Ratings:
    +0 / 0 / -0