Results 1 to 5 of 5
  1. #1
    New Member
    Join Date
    Jan 2015
    Location
    Singapore
    Posts
    3
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Problems with different Baud Rates

    Hi guys I have this project which I need to reflect the aircraft's movement in FSX on to a miniature size aircraft model (roll and pitch) passed down from a previous year group. It uses regular DC motors which have no idea how much of an angle it has turned thus we built in an accelerometer, mx2125, to the simulator to stop the DC motors when we have reached the desired angle (same angle as FSX, pitch and roll). Also we are tasked to use link2fs as the program for the FSX and simulator to speak to each other. The code I believe is written completely but we have hit a roadblock. The mx2125 runs at a rate of 9600 while link2fs runs at 115200. Is there a way I can use both of this devices still on the same arduino board? If we have no choice then we have to find a place to build in an potentiometer which is not as accurate and space consuming. Thanks for the help! Sorry i'm very new to this arduino programming.

  2. #2
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    243
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Problems with different Baud Rates

    sraker,

    If your code contains a variation of this
    http://arduino.cc/en/Tutorial/Memsic...eterMemsic2125

    With
    voidsetup(){
    // initialize serial communications:
    Serial.begin(9600);
    ....and
    // print the acceleration
    Serial.print(accelerationX);
    // print a tab character:
    Serial.print("\t");
    Serial.print(accelerationY);
    Serial.println();

    If you are only wanting to stop the motors with the arduino, you can omit the serial instructions from the MX2125 code.
    The serial instructions, on many tutorials, are there to give feedback to the Serial Monitor to show that the code is working.

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  3. #3
    New Member
    Join Date
    Jan 2015
    Location
    Singapore
    Posts
    3
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Problems with different Baud Rates

    Thanks Fess for your reply, but however the problem I have is at the beginning of the code. The memsic requires serial.begin(9600) while Link2fs requires (115200) to run. I cant satisfy the different baud rates, but I have to use both devices on the same arduino board.

  4. #4
    150+ Forum Groupie
    Join Date
    Nov 2013
    Location
    Evansville, Indiana
    Posts
    243
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Problems with different Baud Rates

    Sraker,
    From this sample code below, Serial.begin(9600); and all Serial.print statements can be omitted.
    It is only used to send the numbers back to the computer via the USB serial connection, for confirmation purposes. It has nothing to do with the MX2125 operation.
    If you don't need to display the numbers in a serial monitor, it is not needed.
    If you do need to display the numbers in a serial monitor, (as a project requirement), it will be impossible with one arduino because Link2FS will have the USB port tied up.

    If I am mistaken, explain to me why Serial.begin(9600) is required for the MX2125.

    Or show your code and wiring diagram.


    /*
    Memsic2125

    Read the Memsic 2125 two-axis accelerometer. Converts the
    pulses output by the 2125 into milli-g's (1/1000 of earth's
    gravity) and prints them over the serial connection to the
    computer.

    The circuit:
    * X output of accelerometer to digital pin 2
    * Y output of accelerometer to digital pin 3
    * +V of accelerometer to +5V
    * GND of accelerometer to ground

    http://www.arduino.cc/en/Tutorial/Memsic2125

    created 6 Nov 2008
    by David A. Mellis
    modified 30 Aug 2011
    by Tom Igoe

    This example code is in the public domain.

    */


    // these constants won't change:
    const int xPin =2;// X output of the accelerometer
    const int yPin =3;// Y output of the accelerometer

    voidsetup(){
    // initialize serial communications:
    Serial.begin(9600);
    // initialize the pins connected to the accelerometer
    // as inputs:
    pinMode(xPin,INPUT);
    pinMode(yPin,INPUT);
    }

    voidloop(){
    // variables to read the pulse widths:
    int pulseX, pulseY;
    // variables to contain the resulting accelerations
    int accelerationX, accelerationY;

    // read pulse from x- and y-axes:
    pulseX =pulseIn(xPin,HIGH);
    pulseY =pulseIn(yPin,HIGH);

    // convert the pulse width into acceleration
    // accelerationX and accelerationY are in milli-g's:
    // earth's gravity is 1000 milli-g's, or 1g.
    accelerationX =((pulseX /10)-500)*8;
    accelerationY =((pulseY /10)-500)*8;

    // print the acceleration
    Serial.print(accelerationX);
    // print a tab character:
    Serial.print("\t");
    Serial.print(accelerationY);
    Serial.println();

    delay(100);
    }

    ~Fess
    I will only ever be, half the Geek that I wished I was.
    TheGeekForge.Com

  5. #5
    New Member
    Join Date
    Jan 2015
    Location
    Singapore
    Posts
    3
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Problems with different Baud Rates

    Oh man thanks Fess sorry I really only just started arduino and relying alot on online tutorials and examples. OKay thanks I understand what you mean, then now it just means my code is wrong thats why it cannot work. But i'm also worried to show it to you because its too long and messy but I shall try.

    #include "Servo.h"


    Servo servoroll; // create servo object to control a servo
    Servo servopitch; // create servo object to control a servo
    Servo servoyaw; // create servo object to control a servo


    const int xPin = 8; // X output of the accelerometer
    const int yPin = 9; // Y output of the accelerometer


    int CodeIn;// used on all serial reads


    int roll = 22;
    int roll2 = 24;
    int pitch =26;
    int pitch2 = 28;
    int yaw = 30;
    int yaw2= 32;
    int motorroll1;
    int motorpitch1;
    int motoryaw1;
    int prevyaw;


    int pulseX, pulseY;
    int accelerationX, accelerationY;


    String motorroll;
    String motorpitch;
    String motoryaw;


    void setup()
    {

    servoroll.attach(2); // attaches the servo on pin 1 to the servo object
    servopitch.attach(3); // attaches the servo on pin 2 to the servo object
    servoyaw.attach(4); // attaches the servo on pin 3 to the servo object


    pinMode(roll, OUTPUT);
    pinMode(roll2, OUTPUT);
    pinMode(pitch, OUTPUT);
    pinMode(pitch2, OUTPUT);
    pinMode(yaw, OUTPUT);
    pinMode(yaw2, OUTPUT);

    int prevyaw = 0;


    Serial.begin(9600);

    pinMode(xPin, INPUT);
    pinMode(yPin, INPUT);

    }


    void loop() {

    if (Serial.available()) {
    CodeIn = getChar();
    if (CodeIn == '=') {EQUALS();} // The first identifier is "="
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
    if (CodeIn == '?') {QUESTION();}// The first identifier is "?"
    if (CodeIn == '/') {SLASH();}// The first identifier is "/" (Annunciators)

    }


    }


    char getChar()// Get a character from the serial buffer
    {
    while(Serial.available() == 0);// wait for data
    return((char)Serial.read());// Thanks Doug
    }


    void EQUALS(){ // The first identifier was "="
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it
    case 'A'://Found the second identifier
    //Do something
    break;

    case 'B':
    //Do something
    break;

    case 'C':
    //Do something
    break;

    //etc etc etc
    }
    }


    void LESSTHAN(){ // The first identifier was "<"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it

    case 'J':{
    motoryaw = "";
    motoryaw += getChar();
    motoryaw += getChar();
    motoryaw += getChar();

    int motoryaw1 = motoryaw.toInt(); // convert it to an integer


    if(motoryaw1 > prevyaw ){
    digitalWrite(yaw, HIGH); // pin 30
    digitalWrite(yaw2, LOW); // pin 32
    int prevyaw = motoryaw1;
    }
    if(motoryaw1 < prevyaw){
    digitalWrite(yaw, LOW); // pin 30
    digitalWrite(yaw2, HIGH); // pin 32
    int prevyaw = motoryaw1;
    }
    if(motoryaw1==prevyaw){
    digitalWrite(yaw, LOW); // pin 30
    digitalWrite(yaw2, LOW); // pin 32
    int prevyaw = motoryaw1;
    }




    break;}

    case 'Q':{

    pulseX = pulseIn(xPin,HIGH);
    accelerationX = ((pulseX / 10) - 500) * 8;

    motorpitch = "";
    motorpitch += getChar();
    motorpitch += getChar();
    motorpitch += getChar();

    int motorpitch1 = motorpitch.toInt(); // convert it to an integer

    motorpitch1 = map(motorpitch1, -90, 90, -1024, 1024);


    if(motorpitch1 > accelerationX )
    {
    digitalWrite(pitch, HIGH); // pin 26
    digitalWrite(pitch2, LOW); // pin 28
    }
    if(motorpitch1 < accelerationX)
    {
    digitalWrite(pitch, LOW); // pin 26
    digitalWrite(pitch2, HIGH); // pin 28
    }

    if(motorpitch1 == accelerationX)
    {
    digitalWrite(pitch, LOW); // pin 26
    digitalWrite(pitch2, LOW); // pin 28
    }
    break;
    }
    case 'R':{
    pulseY = pulseIn(yPin,HIGH);
    accelerationY = ((pulseY / 10) - 500) * 8;

    motorroll = "";
    motorroll += getChar();
    motorroll += getChar();
    motorroll += getChar();

    int motorroll1 = motorroll.toInt(); // convert it to an integer

    motorroll1 = map(motorroll1, -90, 90, -1024, 1024);


    if(motorroll1 > accelerationY )
    {
    digitalWrite(roll, HIGH); // pin 22
    digitalWrite(roll2, LOW); // pin 24
    }
    if(motorroll1 < accelerationY)
    {
    digitalWrite(roll, LOW); // pin 22
    digitalWrite(roll2, HIGH); // pin 24


    }
    if(motorroll1==accelerationY)
    {
    digitalWrite(roll, LOW); // pin 22
    digitalWrite(roll2, LOW); // pin 24


    }
    break;
    }
    case 'f':{
    for (int pinNo = 2; pinNo < 12; pinNo++){//The 10 LED's to indicate lights status
    int lights = getChar();
    if (lights =='1'){digitalWrite(pinNo, HIGH);}else{digitalWrite(pinNo, LOW);}
    }
    break; }
    }
    }


    void QUESTION(){ // The first identifier was "?"
    CodeIn = getChar(); // Get another character
    switch(CodeIn) {// Now lets find what to do with it


    //etc etc etc
    }
    }
    void SLASH(){ // The first identifier was "/" (Annunciator)
    //Do something
    }
    Last edited by Jim NZ; 01-19-2015 at 01:38 PM. Reason: Fixed the "Include"