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

    Help Trim indicator Cessna 172

    Hi to all. Can any body help me with the scatch for Cessna trim indicator. I have 28BYJ48 stepper motor with the UL2003 driver. I search the forum but I can't find any solution. I am newbie, tried to study couple examples from this forum but only lost and I feel now like a stupid one. I come up with this code, but it doesn't work. Please help.


    PHP Code:
    int CodeIn;           // used on all serial readsint tId ;
    int pos 0// variable to store the servo position
     


    //declare variables for pins....
    int trimMotorPin1 8;    // Blue   - 28BYJ48 pin 1
    int trimMotorPin2 9;    // Pink   - 28BYJ48 pin 2
    int trimMotorPin3 10;   // Yellow - 28BYJ48 pin 3
    int trimMotorPin4 11;   // Orange - 28BYJ48 pin 4
    int trimMotorLookup[8] = {B01000B01100B00100B00110B00010B00011B00001B01001};
    //Main Config variables...




    int trimstepDelay 3000;  //variable to set stepper speed. lower = faster motor speed...


    //////////////////////////////////////////////////////////////////////////////
    void setup() {
      
    //declare the motor pins as outputs
      
    pinMode(trimMotorPin1OUTPUT);
      
    pinMode(trimMotorPin2OUTPUT);
      
    pinMode(trimMotorPin3OUTPUT);
      
    pinMode(trimMotorPin4OUTPUT);
      
      
      
      
    Serial.begin(115200);    // NEEDS TO BE 115200 TO WORK WITH LINK2FS!!!!


    }
    //////////////////////////////////////////////////////////////////////////////
    void loop(){
      if (
    Serial.available()) {
        
    CodeIn getChar();//get a character
        //Serial.println(CodeIn);
        
    if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
      
    }//end of serial check
    }
    //////////////////////////////////////////////////////////////////////////////
    char getChar()// Get a character from the serial buffer
    {
      while(
    Serial.available() == 0);// wait for data
      
    return((char)Serial.read());// Thanks Doug
    }
    //////////////////////////////////////////////////////////////////////////////
    void LESSTHAN(){    // The first identifier was "<"
    CodeIn getChar();       // Get another character
      
    switch(CodeIn) {          // Now lets find what to do with it
        
    case 'H':               // Found the second identifier ("G" Flaps position)
                                 // Initialize some variables needed for flaps...
     
    String  tI;   // Store incoming flap metrics from Link2FS 
     
    int trimStepPosition;  
     
          
    tI += getChar();  //Get three characters for flap data from Link2fs
          
    tI += getChar();
          
    tI += getChar();
          
    int tId tI.toInt(); //Converts to int
         
          
    tId map(tId, -100, +1000512);//map the integer
          
    for(pos 0pos 512pos += 1// goes from 0 degrees to 180 degrees
          
    stepTo(tId);
          
    Serial.println (tId);
      }
    }


    void stepTo(int targetPosition){
      do{
         if(
    tId targetPosition){
           
    clockwise();
           
    tId++;
         }
         else if(
    tId targetPosition){
          
    anticlockwise();
          
    tId--;
         }
      } while (
    tId != targetPosition );
    }












    void anticlockwise(){
    // step motor 1 step anti-clockwise
      
    for(int i 08i++)
      {
        
    trimSetOutput(i);
        
    delayMicroseconds(trimstepDelay);
      }
    }




    void clockwise(){
    // step motor 1 step clockwise
      
    for(int i 7>= 0i--)
      {
        
    trimSetOutput(i);
        
    delayMicroseconds(trimstepDelay);
      }
    }




    void trimSetOutput(int out)
    {
      
    digitalWrite(trimMotorPin1bitRead(trimMotorLookup[out], 0));
      
    digitalWrite(trimMotorPin2bitRead(trimMotorLookup[out], 1));
      
    digitalWrite(trimMotorPin3bitRead(trimMotorLookup[out], 2));
      
    digitalWrite(trimMotorPin4bitRead(trimMotorLookup[out], 3));


  2. #2
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

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

    Re: Help Trim indicator Cessna 172

    Hi. I figured it out and now it works. But I have a question is it any possible way to remember last position when I close fsx and reopen again. I can't find any working solution. I'w got idea but I don't know if it possible. My idea was to to take Jim's some of code from void loop and put it to void setup. So it can read position from start up and set it ones after that go to loop and do rest of it.