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

Freds adruino 2 motor sim

Discussion in 'DIY Motion Simulator Projects' started by fred, Sep 27, 2012.

  1. fred

    fred New Member

    Joined:
    Sep 9, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi all
    Just want to thank u all for the post of diffrind advice .It is very helpful seeing i got noidea what im doning
    I tryed to write a scetch for my adruino etherten .Eany comment will be good.


    This is the way we learn
    the code is.

    //motor A connected between A+ and A-
    //motor B connected between B+ and B-

    int Degree;
    int Gforce = 0;
    int Gforce1 = 0;
    int Gforce10 = 0;
    int Gforce100 = 0;

    char kind_of_data;

    //Motor A
    int motor_PWMA_= 3; //Speed control
    int motor_AIN1_= 9; //Direction
    int motor_AIN2_= 8; //Direction

    //Motor B
    int motor_PWMB_= 5; //Speed control
    int motor_BIN1_= 11; //Direction
    int motor_BIN2_= 12; //Direction

    void setup(){

    pinMode(motor_PWMA_, OUTPUT);
    pinMode(motor_AIN1_, OUTPUT);
    pinMode(motor_AIN2_, OUTPUT);

    pinMode(motor_PWMB_, OUTPUT);
    pinMode(motor_BIN1_, OUTPUT);
    pinMode(motor_BIN2_, OUTPUT);

    Serial.begin(115200);
    }
    void loop() {

    // wait for serial input (min 3 bytes in buffer)
    while(Serial.available() > 0) {

    kind_of_data = Serial.read(); //string from USO --> L~a01~ R~a02~ 8bit resolution\decimal output
    if(kind_of_data == 'L') {
    Read_Pos(kind_of_data);
    }
    if(kind_of_data == 'R') {
    Read_Pos(kind_of_data);
    }
    }
    }

    void Read_Pos(char which_servo){
    delay(2);
    int Gforce100 = Serial.read()- '0';
    delay(2);
    int Gforce10 = Serial.read()- '0';
    delay(2);
    int Gforce1 = Serial.read()- '0';



    if (Gforce1 < 0) { Gforce = Gforce10 + 10*Gforce100; }
    if (Gforce1 < 0 && Gforce10 < 0) { Gforce = Gforce100; }
    if (Gforce100 < 0) { Gforce = 127; }
    if (Gforce1 >=0 && Gforce10 >= 0 && Gforce100 >= 0) { Gforce = 100 * Gforce100 + 10 * Gforce10 + Gforce1; }

    if (which_servo == 'L') {
    Degree = map(Gforce, 0, 255, 180, 0);
    }


    if (which_servo == 'L') {
    Degree = map(Gforce, 0, 255, 180, 0);
    }
    if (which_servo == 'R') {
    Degree = map(Gforce, 0, 255, 0, 180);
    }

    if (which_servo == 'L') {
    Serial.write(Degree);
    }
    if (which_servo == 'R' ){
    Serial.write(Degree);
    }
    }
  2. fred

    fred New Member

    Joined:
    Sep 9, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Or mb with cluster


    int rpm;
    int i;
    int leds;
    int Speed;
    int fuel;
    int ebrake;
    int brake;
    int fuelled;
    int Turbo;
    int gear;
    int previous_potion = 0;
    int rotate;

    int Degree;
    int Gforce = 0;
    int Gforce1 = 0;
    int Gforce10 = 0;
    int Gforce100 = 0;

    //Motor A
    int motor_PWMA_= 3; //Speed control
    int motor_AIN1_= 9; //Direction
    int motor_AIN2_= 8; //Direction

    //Motor B
    int motor_PWMB_= 5; //Speed control
    int motor_BIN1_= 11; //Direction
    int motor_BIN2_= 12; //Direction


    char kind_of_data;


    void setup(){

    Serial.begin(115200);

    pinMode(2, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(1, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(14, OUTPUT);
    pinMode(13, OUTPUT);

    pinMode(motor_PWMA_, OUTPUT);
    pinMode(motor_AIN1_, OUTPUT);
    pinMode(motor_AIN2_, OUTPUT);

    pinMode(motor_PWMB_, OUTPUT);
    pinMode(motor_BIN1_, OUTPUT);
    pinMode(motor_BIN2_, OUTPUT);

    }



    void loop()
    {
    //****************************** READ DATA FROM SERIAL ******************************
    while(Serial.available() > 0)
    {
    kind_of_data = Serial.read(); //string from USO --> L~a01~ R~a02~ 8bit resolution\decimal output
    if(kind_of_data == 'L') {

    }
    if(kind_of_data == 'R') {

    kind_of_data = Serial.read();


    if (kind_of_data == 'F' ) Read_Fuel();
    if (kind_of_data == 'E' ) Read_EBrake();
    if (kind_of_data == 'B' ) Read_Brake();

    }


    //****************************** READ DATA FROM SERIAL END ******************************
    }



    delay(1);
    int Rpm100 = Serial.read()- '0';
    delay(1);
    int Rpm10 = Serial.read()- '0';
    delay(1);
    int Rpm1 = Serial.read()- '0';

    int rpm = 100*Rpm100 + 10*Rpm10 + Rpm1;
    analogWrite(7,map(rpm,127,255,75,210));
    if (rpm<135) digitalWrite(13,HIGH);
    if (rpm>135) digitalWrite(13,LOW);
    if (rpm>245) digitalWrite(8,HIGH);
    if (rpm<245) digitalWrite(8,LOW);


    }
    void Read_Pos(char which_servo){
    delay(2);
    int Gforce100 = Serial.read()- '0';
    delay(2);
    int Gforce10 = Serial.read()- '0';
    delay(2);
    int Gforce1 = Serial.read()- '0';



    if (Gforce1 < 0) { Gforce = Gforce10 + 10*Gforce100; }
    if (Gforce1 < 0 && Gforce10 < 0) { Gforce = Gforce100; }
    if (Gforce100 < 0) { Gforce = 127; }
    if (Gforce1 >=0 && Gforce10 >= 0 && Gforce100 >= 0) { Gforce = 100 * Gforce100 + 10 * Gforce10 + Gforce1; }

    if (which_servo == 'L') {
    Degree = map(Gforce, 0, 255, 180, 0);

    if (which_servo == 'L') {
    Degree = map(Gforce, 0, 255, 180, 0);
    }


    if (which_servo == 'L') {
    Degree = map(Gforce, 0, 255, 180, 0);
    }
    if (which_servo == 'R') {
    Degree = map(Gforce, 0, 255, 0, 180);
    }

    if (which_servo == 'L') {
    Serial.write(Degree);
    }
    if (which_servo == 'R' ){
    Serial.write(Degree);
    }
    }



    delay(1);
    int Speed100 = Serial.read()- '0';
    delay(1);
    int Speed10 = Serial.read()- '0';
    delay(1);
    int Speed1 = Serial.read()- '0';

    Speed = 100*Speed100 + 10*Speed10 + Speed1;

    tone(12, map(Speed,127,255,0,950));

    }

    void Read_Fuel(){
    delay(1);
    int Fuel100 = Serial.read()- '0';
    delay(1);
    int Fuel10 = Serial.read()- '0';
    delay(1);
    int Fuel1 = Serial.read()- '0';

    fuel = 100*Fuel100 + 10*Fuel10 + Fuel1;

    analogWrite(2,map(fuel,127,255,53,183));
    if (fuel<135) digitalWrite(10,HIGH);
    if (fuel>135) digitalWrite(10,LOW);

    }


    void Read_EBrake(){
    delay(1);
    int EBrake100 = Serial.read()- '0';
    delay(1);
    int EBrake10 = Serial.read()- '0';
    delay(1);
    int EBrake1 = Serial.read()- '0';

    ebrake = 100*EBrake100 + 10*EBrake10 + EBrake1;

    if (ebrake>200) digitalWrite(3,HIGH);
    if (ebrake<200) digitalWrite(3,LOW);

    }
    void Read_Brake(){
    delay(1);
    int Brake100 = Serial.read()- '0';
    delay(1);
    int Brake10 = Serial.read()- '0';
    delay(1);
    int Brake1 = Serial.read()- '0';

    brake = 100*Brake100 + 10*Brake10 + Brake1;

    if (brake>200) digitalWrite(5,HIGH);
    if (brake<200) digitalWrite(5,LOW);

    }
  3. fred

    fred New Member

    Joined:
    Sep 9, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    these codes verify but have noidea yet if it works still need to buy 50A Dual-Channel Motor Drive Module -Arduino Compatible if it will work http://www.emartee.com/product/42215/ and some motors




    Code:

    int Degree;
    int motor1Pin1 =8;
    int motor1Pin2 =9;
    int motor2Pin1 = 11;
    int motor2Pin2 = 12;
    int Gforce = 0;
    int Gforce1 = 0;
    int Gforce10 = 0;
    int Gforce100 = 0;

    char kind_of_data;

    void setup() {
    // set the serial as an input:

    Serial.begin(115200);
    // set all the other pins you're using as outputs:
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
    pinMode(motor2Pin1, OUTPUT);
    pinMode(motor2Pin2,OUTPUT);
    Serial.begin(115200);
    }

    void loop() {

    // wait for serial input (min 3 bytes in buffer)
    while(Serial.available() > 0) {

    kind_of_data = Serial.read(); //string from USO --> L~a01~ R~a02~ 8bit resolution\decimal output
    if(kind_of_data == 'L') {
    Read_Pos(kind_of_data);
    }
    if(kind_of_data == 'R') {
    Read_Pos(kind_of_data);
    }
    }
    }

    void Read_Pos(char which_motor){
    delay(2);
    int Gforce100 = Serial.read()- '0';
    delay(2);
    int Gforce10 = Serial.read()- '0';
    delay(2);
    int Gforce1 = Serial.read()- '0';
    if (Gforce1 < 0) { Gforce = Gforce10 + 10*Gforce100; }
    if (Gforce1 < 0 && Gforce10 < 0) { Gforce = Gforce100; }
    if (Gforce100 < 0) { Gforce = 127; }
    if (Gforce1 >=0 && Gforce10 >= 0 && Gforce100 >= 0) { Gforce = 100 * Gforce100 + 10 * Gforce10 + Gforce1; }

    if (which_motor == 'L') {
    Degree = map(Gforce, 0, 255, 180, 0);
    }
    if (which_motor == 'R') {
    Degree = map(Gforce, 0, 255, 0, 180);
    }
    }
  4. tronicgr

    tronicgr

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    This looks interesting... but what's its purpose? Is it going to be used with x-sim software?
  5. fred

    fred New Member

    Joined:
    Sep 9, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Yes it will be with x sim software and what im building at the moment will be simular to this vidio.

    Still have a huge amount of gear to get hold of.But started the frame construction last weekend



    http://www.youtube.com/watch?v=JQAZB3EnI_w