4 Replies Latest reply on Nov 21, 2014 8:29 AM by KurtE

    Interesting behavior with Empty Arduino Sketch

    KC9SDO

      What is the best way to stop an Arduino sketch after you have uploaded it to the Edison?

       

      Gave the Arduino "Blink" example a try and after the excitement of the blinking LED wore off, the next step was to stop the blinking.

       

      Probably not the best idea but I upload a blank sketch to the Edison.

       

      void setup() {

        // put your setup code here, to run once:

      }

      void loop() {

        // put your main code here, to run repeatedly:

      }

       

      After the blank sketch upload, the Edison started running 50% CPU with process /sketch/sketch.elf /dev/pts/0

       

      My next steps were to delete the /sketch/sketch.elf file and kill the /sketch/sketch.elf /dev/pts/0 process.

       

      Not sure if there is a better method than this.

        • 1. Re: Interesting behavior with Empty Arduino Sketch
          flummer

          Hi KC9SDO,

           

          Yes, there is very little code in the "empty" sketch, but it's not all empty, the loop() will still run and with nothing to stop or pause it, it will take up some resources and be a "busy loop".

           

          Some compilers might optimize this out, but I don't think that happens here, there is also a bit more code being added by the environment.

           

          How to stop stuff from happening depends a little on what you want. Normally, I guess you would just put on the next project and overwrite the previous, but if you want to use a different aspect of the Edison (eg. working with Python or node.js via the XDK), I'd say deleting the .elf and killing the process is the right thing to do. If you want to make it more permanently and avoid errors/warnings when booting up, you will probably also need to clean up the startup script (can't remember if it already fails nicely on missing sketch.elf).

           

          The sketch system via the Arduino IDE is made to be a lot like programming a microprocessor, but on these small computers, if you want to use the system below you will need to tweak it a bit.

           

          /Thomas

          1 of 1 people found this helpful
          • 2. Re: Interesting behavior with Empty Arduino Sketch
            mhahn

            you could stop the clloader service by calling:

            systemctl stop clloader

            This will not only stop the sketch running but also stop Arduino IDE being able to upload sketches until next reboot.

            If you don't use Arduino sketches at all you can completely disable the service:

            systemctl disable clloader

             

            If you need it again:

            systemctl enable clloader

            1 of 1 people found this helpful
            • 3. Re: Interesting behavior with Empty Arduino Sketch
              mdw

              Another possibility would be to put some big delay eg. delay(10000) into loop(). This reduces CPU consumption below all concurrent processes.

              • 4. Re: Interesting behavior with Empty Arduino Sketch
                KurtE

                I use one of two different approaches depending on what is happening.  That is if I simply don't want the overhead, I do like mdw mentioned:

                void setup() {

                }

                 

                void loop() {

                  delay(10000);

                }

                 

                When I am having issues, example my attempts to update IDE to have board definition for breakout board, that was killing most things, I used a bigger hammer:

                void setup() {

                  // put your setup code here, to run once:

                  delay(2000);

                  Serial.begin(1152000);

                  Serial.println("Kill the program");

                  system ("mv -f /sketch/sketch.elf /sketch/sketch.elf.old");

                  system ("cp /tmp/log*.txt /home/root");

                  //system("rm \/sketch\/\*");

                  delay(500);

                  system("reboot");

                }

                 

                void loop() {

                  }

                This copied the Arduino log files (stuff that went out to stdout and stderr to the root home directory to help see what happened in the program, rename the sketch to the old sketch and then reboot...  Again I mainly only use this when something has gone real bad.