Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    10+ Posting Member
    Join Date
    Oct 2013
    Location
    United States
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    No Line feed with data

    Hi Guys,

    I attempted to use a code that I found here to control the landing gear. I can get the arduino to print CO1 and C02 on the serial monitor in the arduino software, however Link2FS is giving me this error "There is no 'Linefeed' with your data. Use Serial.printIn in your card 1 INO code." Below is the code I am using.

    Code:
    int val = 0;int inputPin = 8;int valOld = 0;
    
    
    
    
    void setup()
    {
    pinMode(inputPin, INPUT);
    Serial.begin(9600);
    digitalWrite(inputPin, HIGH);
    }
    
    
    
    
    void loop() {
    val = digitalRead(inputPin);
    
    
    if (val == valOld) {
    } else {
    if (val == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); };
    valOld = val;
    }
    delay(500);
    }

  2. #2
    10+ Posting Member
    Join Date
    Jul 2012
    Location
    Madison Al.
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    I'm new to this as well but I don't think you need the last semicolon on this line. (Probably not the issue however)
    if (val == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); };

    The linefeed error showed up on me a few times when I killed the serial link with an arduino upload. When you upload is Link2FS still open?

  3. #3
    500+ This must be a daytime job Jim NZ's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    764
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    Your nearly there Jeff ,,, all that needs changing is the baud rate ,, youve got 9600 but all my stuff runs at 115200.

    So change the 9600 to read 115200 and it runs.

    I love cutting my code down (after it's going) and getting it down to the minimum requred to do the job so to move on from your original code ,,,
    You dont need that delay in there but change the "val == valOld" to "val != valOld"
    You have an 'else' condition in there not really being used (unless you have forward plans)
    I am assuming you are using a toggle switch.

    Sooo,,,
    you should end up with this ,,,

    Code:
    int val = 0;int inputPin = 8;int valOld = 0;
    
    void setup()
    {
    pinMode(inputPin, INPUT);
    Serial.begin(115200);
    digitalWrite(inputPin, HIGH);
    }
    
    void loop() {
    val = digitalRead(inputPin);
    if (val != valOld) {
    if (val == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); }
    valOld = val;
    }//end of yes its different
    }//end of void loop
    The above has been tested.

    Soooo,,, lets move on from there ,,,,,
    You will straight away want to add more buttons or switchs but we need to tidy up a couple of things in preparation.
    Rename valOld to gearOld so it is different from anything else.
    Also because it's nice to keep things seperate when we have a value we will rename val to gear.
    Lets do away with seperate names for the pins and we will just call them directly.
    Lets also use LOW (the pin is closed with the button or whatever) instead of HIGH (it's off state)
    And we will add in the 2 buttons for the flaps 'bump up' and 'bump down'.
    So we end up with this ,,,,,

    Code:
    int gear;
    int gearOld = 0;
    int flapsUp;
    int flapsUpOld = 0;
    int flapsDn;
    int flapsDnOld = 0;
    
    void setup()
    {
      pinMode(8, INPUT);
      pinMode(9, INPUT);
      pinMode(10, INPUT);
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      Serial.begin(115200);
    }
    
    void loop() {
      gear = digitalRead(8);
      if (gear != gearOld) {
        if (gear == LOW) {Serial.println("C02");} else {Serial.println("C01");}
        gearOld = gear;
      }//end of yes its different (gear)
    
      flapsDn = digitalRead(9);
      if (flapsDn != flapsDnOld) {
        if (flapsDn == LOW) {Serial.println("C15");} 
        flapsDnOld = flapsDn;
      }//end of yes its different (flapsDn)
    
      flapsUp = digitalRead(10);
      if (flapsUp != flapsUpOld) {
        if (flapsUp == LOW) {
          Serial.println("C14");
        } 
        flapsUpOld = flapsUp;
      }//end of yes its different (flapsUp)
    
    }//end of void loop
    The above has been tested.

    So there's a bit of a starter for you Jeff ,, the code could have been done in a million different ways so that's just one way.

    Of course ,, next thing is again add to it ,,, what is here should be enough to get your head into it but if you still have trouble I can carry on and show how this sort of coding can blend into the type that is included with my downloads.

    Have fun ,,, 73's de Jim
    www.jimspage.co.nz/intro.htm
    All this and Liz still loves me ! !

  4. #4
    10+ Posting Member
    Join Date
    Oct 2013
    Location
    United States
    Posts
    10
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    Jim, I really appreciate that you took the time to answer my question. My next question would have been how do I add more to the code. It works great!

  5. #5
    10+ Posting Member
    Join Date
    Aug 2007
    Location
    united kingdom
    Posts
    13
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    Hey Jim,

    My first post here - before that, thanks a mill for your hard work in producing Link2FS. It rocks!

    OK, I had been trying to get 1/2 step encoders to work with the Encoders.h library - all worked fine when I had the encoders on pins 2,3 and 4,5.

    In order to free-up these pins, I rewrote the pin definitions to 32,33 and 34,35 on my Mega 2560. It now doesn't work! I tried defining the pins as inputs with pinmode (32, INPUT) etc. but that made no difference. The pushbutton works fine on pin 22 regardless. If i change back to 2,3 and 4,5 it works again!

    Here's the code:
    /******************************************************************************
    * quadrature_two_encoders
    * Keith Neufeld
    * July 4, 2008
    * Modified by Jim NZ to input into my "Keys" program
    * Read and decode two quadrature rotary encoders.
    * Demo system has encoders connected to digital pins 2&3 and 4&5.
    * Rotary encoder "push" switch on to any other pins.
    * Also reads ordinary "Keys" inputs from the other pins.
    * Modified by Roger UK to use with a dual concentric encoder with pushbutton
    ******************************************************************************/
    #include "math.h"
    #include "Quadrature.h"
    Quadrature quad1(32,33);
    Quadrature quad2(34,35);

    long Xold1;// the first encoder "old" reading
    long Xold2;// the second encoder "old" reading
    const int buttonPin = 22; // the number of the pushbutton pin
    int buttonState, oldButtonState; // variable for reading the pushbutton status

    void setup() {
    Serial.begin(115200);
    pinMode(buttonPin, INPUT_PULLUP);
    // pinMode(32, INPUT);
    // pinMode(33, INPUT);
    // pinMode(34, INPUT);
    // pinMode(35, INPUT);
    }

    void loop() {
    // First the rotary encoder bit
    long X1 =(quad1.position());// for full cycle encoders
    if (X1 != Xold1){
    if (X1 > Xold1) {Serial.println("#a621");}
    if (X1 < Xold1) {Serial.println("#a622");}
    Xold1 = X1; // overwrites the old reading with the new one.
    }//end of quad1 read



    long X2 =(quad2.position()); // for full cycle encoders
    if (X2 != Xold2) {
    if (X2 > Xold2) {Serial.println("#a619");}
    if (X2 < Xold2) {Serial.println("#a620");}
    Xold2 = X2; // overwrites the old reading with the new one.
    }//end of quad2 read

    buttonState = digitalRead(buttonPin);
    if (buttonState != oldButtonState){
    // Serial.println ("new button state");
    if (buttonState == LOW) {Serial.println("#a623");} // press mins rst button:
    }
    oldButtonState = buttonState;
    }


    Now - I'm sure it's something simple, just, what?

    Thanks again,

    Roger.
    Last edited by Fatcharlie; 03-08-2016 at 12:38 PM. Reason: clarity

  6. #6
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    Try long X1 =(quad1.position())/2; // divide by 2 for half cycle encoders

    copy and paste is a killer.
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  7. #7
    10+ Posting Member
    Join Date
    Aug 2007
    Location
    united kingdom
    Posts
    13
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    First, thanks for the help

    Second - my bad - I remmed-out the /2 because the encoder only sent a signal every two detents when i had it in. all worked fine with pins 2,3 and 4,5 - just won't go with the higher numbered pins. will try to edit previous post to be clearer.

  8. #8
    10+ Posting Member
    Join Date
    Aug 2007
    Location
    united kingdom
    Posts
    13
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    Hi, just to be sure, I changed the code back to this:

    /******************************************************************************
    * quadrature_two_encoders
    * Keith Neufeld
    * July 4, 2008
    * Modified by Jim NZ to input into my "Keys" program
    * Read and decode two quadrature rotary encoders.
    * Demo system has encoders connected to digital pins 2&3 and 4&5.
    * Rotary encoder "push" switch on to any other pins.
    * Also reads ordinary "Keys" inputs from the other pins.
    * Modified by Roger UK to use with a dual concentric encoder with pushbutton
    ******************************************************************************/
    #include "math.h"
    #include "Quadrature.h"
    Quadrature quad1(2,3);
    Quadrature quad2(4,5);

    long Xold1;// the first encoder "old" reading
    long Xold2;// the second encoder "old" reading
    const int buttonPin = 22; // the number of the pushbutton pin
    int buttonState, oldButtonState; // variable for reading the pushbutton status

    void setup() {
    Serial.begin(115200);
    pinMode(buttonPin, INPUT_PULLUP);
    // pinMode(32, INPUT_PULLUP);
    // pinMode(33, INPUT_PULLUP);
    // pinMode(34, INPUT_PULLUP);
    // pinMode(35, INPUT_PULLUP);
    }

    void loop() {
    // First the rotary encoder bit
    long X1 =(quad1.position()); // for full cycle encoders
    if (X1 != Xold1){
    if (X1 > Xold1) {Serial.println("#a621");}
    if (X1 < Xold1) {Serial.println("#a622");}
    Xold1 = X1; // overwrites the old reading with the new one.
    }//end of quad1 read



    long X2 =(quad2.position()); // for full cycle encoders
    if (X2 != Xold2) {
    if (X2 > Xold2) {Serial.println("#a619");}
    if (X2 < Xold2) {Serial.println("#a620");}
    Xold2 = X2; // overwrites the old reading with the new one.
    }//end of quad2 read

    buttonState = digitalRead(buttonPin);
    if (buttonState != oldButtonState){
    // Serial.println ("new button state");
    if (buttonState == LOW) {Serial.println("#a623");} // press mins rst button:
    }
    oldButtonState = buttonState;
    }




    It works fine like this, I have checked with the serial monitor in the Arduino IDE and with Link2FS running and connected to FS9.

    But if I change the pin assignments to

    Quadrature quad1(32,33);
    Quadrature quad2(34,35);

    Then it stops working. The button on pin 21 still wokrs, so i know the Arduino is working, but not the encoders - bizarre! I think it must have something to do with the way the pins are defined but i have no idea what. Any help gratefully received

  9. #9
    150+ Forum Groupie


    BushPilotWannabe's Avatar
    Join Date
    Jan 2014
    Location
    Alberta, Canada
    Posts
    176
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    Haven't had second pot of coffee yet.

    I rewrote the pin definitions to 32,33 and 34,35 on my Mega.

    Did you update quadrature.h for use with the Mega?

    http://www.mycockpit.org/forums/show...drature.j+mega see post dated 21 July
    ---CYXD ----- TWR --- GND ------ Closed
    ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013

  10. #10
    10+ Posting Member
    Join Date
    Aug 2007
    Location
    united kingdom
    Posts
    13
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: No Line feed with data

    I had downloaded quadrature2.zip from Jim's site, but have now got arduino-quadrature-0.90.zip from Keith's blog - will have a go with that. Thanks.

Page 1 of 2 12 LastLast