Neo not reading Serial /dev/ttyMCC slows down Arduino M4

Discussion in 'UDOO NEO' started by waltervl, Jul 30, 2016.

  1. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    I think it has to be added to the known issues of the Neo Arduino documentation.
    When you have a sketch that sends data to the serial device (/dev/ttyMCC) it has to be read by the A9 part else it will slow down the execution: It will time out every Serial.println(). (note 1)

    For example when you use the following script that blinks the LED every second it will blink every 3-4 seconds when you are not reading /dev/ttyMCC on the A9 with for example minicom, Arduino IDE Serial monitor or a Python/PHP/C program.

    Code:
    void setup() {
    Serial.begin(115200);
    delay(100);
    pinMode(13, OUTPUT);
    }
    
    // the loop function runs over and over again forever
    void loop() {
    Serial.println("LED ON");
    digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(1000); // wait for a second
    Serial.println("LED OFF");
    digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
    delay(1000); // wait for a second
    }
    
    Note 1: https://github.com/UDOOboard/linux_kernel/issues/14
     
    Uhl likes this.
  2. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    This is the expected behaviour, not a problem :p. You just have to have it read by the A9 part.
     
  3. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Well this expected behavior is not documented here or here
    So when you not know this it will become a problem.... :) I did not ask to fix it, just to document it.
     
  4. sirrab

    sirrab UDOOer

    Joined:
    Jul 26, 2014
    Messages:
    264
    Likes Received:
    32
    Keep after them waltervl! Documentation is very important!
     
    waltervl likes this.
  5. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    You're right @waltervl;)! We're fixing the docs right now :p
     
    waltervl likes this.
  6. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Checked! Thank you.
     
  7. Lothar

    Lothar New Member

    Joined:
    Aug 8, 2016
    Messages:
    13
    Likes Received:
    5
    Is Serial.availableForWrite working for /dev/ttyMCC? If yes, that might be a way to prevent this effect on the M4-side by stopping sending something if the buffer is too small for the data to be sent.
     
    waltervl likes this.
  8. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Serial.available is working but not fully monkey proof. But perhaps I have to test it more.
    Serial.availableForWrite I had never heard about so that would be an extra option to test.
     
  9. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,314
    Likes Received:
    580
    Well tried some options:
    void loop() {
    While ( Serial.available() >0 ) {
    -- Do something ---
    Serial.println("Some text");
    }
    }
    This will work after a reboot. There is not data sent (and no other actions done) by Arduino until some data is send from the serial device from A9 side. But when Serial connection is closed from A9 Side it will continue and after a couple of cycles Serial.println will time out and slow down the execution of the loop by seconds. Starting the Serial connection again from A9 will solve this.

    void loop() {
    While ( Serial.availableForWrite() >0 ) {
    -- Do something ---
    Serial.println("Some text");
    }
    }
    This is not working at all after reboot. As soon as the M4 is booted it wil start execution and Serial.println will time out and slow down the execution of the loop by seconds. Starting the Serial connection again from A9 will solve this.

    It seems that Serial.availableForWrite() is not implemented or not configured correctly. It does not give an compilation error.
     
  10. Lothar

    Lothar New Member

    Joined:
    Aug 8, 2016
    Messages:
    13
    Likes Received:
    5
    Your test has a bug. You're checking the availability to be > 0 but are sending more than one byte to Serial. So if the result of availableForWrite is e.g. 5, you still run into the problem. So I adjusted your test a bit:

    Code:
    void setup() {
      pinMode(13, OUTPUT);
      Serial.begin(115200);
      delay(100);
    }
    
    void loop() {
      digitalWrite(13, LOW);
      while ( Serial.availableForWrite() < 12 ) {
        digitalWrite(13, HIGH);
        delay(500);
        digitalWrite(13, LOW);
        delay(500);
      }
      Serial.println(Serial.availableForWrite());
    }
    But you're still right, the LED doesn't blink at all and when connecting to the serial port using minicom you always see lines with 896 as current value never decreasing.
     
    waltervl likes this.

Share This Page