• Title says all.
    I keep getting errors that say "setNew interpreter error: LOW_MEMORY,MEMORY."
    I'm assuming it means my Espruino Pico is out of RAM but then again, my code is only 13 lines.

    function pause(){}
    
    while (1) {
      digitalWrite(A4, 0);
      setTimeout('pause()', 20);
      digitalWrite(B4, 1);
      digitalWrite(B3, 0);
      setTimeout('pause()', 20);
      digitalWrite(A4, 1);
      digitalWrite(B4, 0);
      setTimeout('pause()', 20);
      digitalWrite(B3, 1);
    }
    

    Please help!

  • I think you are expecting your setTimeout('pause()', 20); to delay the running of the code for 20 milliseconds.....

    What you have written is basically this:

    
    while (1) {
      digitalWrite(A4, 0);
    
      digitalWrite(B4, 1);
      digitalWrite(B3, 0);
     
      digitalWrite(A4, 1);
      digitalWrite(B4, 0);
     
      digitalWrite(B3, 1);
    }
    

    So it is looping forever toggling the state of the pins. It is also adding new timeouts, faster than they can be executed.

    The timeout calls are a callback. This means that pause() will be called 20 milliseconds later, however the next statement digitalWrite(B4, 1); gets written straight away - it does not wait 20ms before doing that.

    To achieve what you want - you will need to chain calls so that the next action occurs in a call back - not directly.

    I hope this helps.

  • As @Wilberforce says...

    Just to clarify though LOW_MEMORY,MEMORY means:

    • LOW_MEMORY - Espruino ran low on memory while executing code, and had to delete command history and some other stuff so it could try and run your code properly
    • MEMORY - Espruino totally ran out of memory and couldn't execute and more, so it had to stop running your code.

    The code you actually want (using timeouts as intended) is probably:

    function go() {
      digitalWrite(A4, 0);
      setTimeout(function() {
        digitalWrite(B4, 1);
        digitalWrite(B3, 0);
        setTimeout(function() {
          digitalWrite(A4, 1);
          digitalWrite(B4, 0);
          setTimeout(function() {
            digitalWrite(B3, 1);
            go();
          }, 20);
        }, 20);
      }, 20);
    }
    
    go();
    

    Note that when you do it that way, you're actually able to do execute other code in the background as well, because you're not completely stopping execution.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

what does "setNew interpreter error: LOW_MEMORY,MEMORY" mean?

Posted by Avatar for user73202 @user73202

Actions