Arduino sketch running very slow when not reading serial line

Discussion in 'UDOO NEO' started by ddewaele, Dec 6, 2015.

  1. ddewaele

    ddewaele Member

    Joined:
    Dec 2, 2014
    Messages:
    48
    Likes Received:
    11
    I have uploaded the following sketch

    Code:
    void setup() {
    
      Serial.begin(9600);
    
      pinMode(13, OUTPUT);
    
    }
    
    
    
    void loop() {
    
      Serial.println("LED ON");
    
      digitalWrite(13, HIGH);
    
      delay(1000);
    
      Serial.println("LED OFF");
    
      digitalWrite(13, LOW);
    
      delay(1000);
    
    }
    I noticed that the LED was blinking really slow (turning on for 4 seconds, turning off for 4 seconds).

    As soon as I start monitoring /dev/ttyMMC the LED startss blinking normally (turning on for 1 second, turning off for 1 second)

    Code:
    sudo cat /dev/ttyMCC
    LED ON
    
    LED OFF
    
    LED ON
    
    LED OFF
    
    LED ON
    
    LED OFF
    
    LED ON
    
    LED OFF
    
    As soon as I stop the cat, it again goes very slowly.....

    Any idea why it's behaving like this ?
     
  2. jrullan

    jrullan New Member

    Joined:
    Dec 11, 2014
    Messages:
    28
    Likes Received:
    4
    I noticed this myself.

    Apparently (see this post) the M4 implements the Arduino emulation on top of Freescale MQX real time OS API calls. I wouldn't pretend to know for sure but I would guess the implementation of Serial using the MQX API is responsible for this. I hope someone more knowledgeable could help us understand if there is a way to avoid this.
     
  3. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
  4. ddewaele

    ddewaele Member

    Joined:
    Dec 2, 2014
    Messages:
    48
    Likes Received:
    11
    I'll check with the default image that can be downloaded from the site and will get back to you.
    Don't think it should have influenced the sketch behavior but I'll double check.
     
    Andrea Rovai likes this.

Share This Page