8 Replies Latest reply on Sep 15, 2014 1:52 AM by CorBee

    Start sketch from Linux

    antoncivit

      I would like to start a Sketch from a linux shell. Is this possible? In this way several sketches could be kept in a directory and move to the sketch directory and started when required.

        • 1. Re: Start sketch from Linux
          Clayton Hofrock

          The Arduino IDE creates a Linux executable that essentially is the sketch. It is downloaded to the /sketch/sketch.elf file, and the IDE also starts executing the sketch. Also, when the Linux OS starts up, it also executes this file, if it exists.

           

          All you would need to do is to execute that program from the shell. You could copy the executable sketch to a different directory and even give it a different name. So, you can have many sketches on the Galileo, and run them from the shell.

           

          Oh, and of course you will want to be running from and SD card. That is the only way your changes will stay between power cycles.

          • 2. Re: Start sketch from Linux
            antoncivit

            Thanks, It works. I had done it before and I could not get the script running but now I tried again /sketch/sketch.elf & after killing the sketch moving it somewhere else and moving it back to its original place and it works.

             

            Update: The first time I tried it worked but then I killed the sketch move it (through scp) to the pc. Copied back again qith the required exec permisions and start it again. This does not seem to work. What am I doing wrong?

            • 3. Re: Start sketch from Linux
              rmm200

              This discussion helped me. I thought the IDE produced pseudo code, that was executed in an emulator on the Linux side, much like Java.

              Given that it is a Linux executable, and multiple may be running at the same time - how is the sketch reset button implemented, and which executable gets it?

              • 4. Re: Start sketch from Linux
                ldvp

                If I run "ps" I see a process whose name suggests to be connected to sketch reset button:

                1311 root   768 S/opt/cln/galileo/galileo_sketch_reset -v

                and within its folder there is a galileo_sketch_reset_script calling "killall -HUP" and "-TERM".

                • 5. Re: Start sketch from Linux
                  rmm200

                  Very interesting ldvp. Same directory has a sketch-setup.sh. There is more magic going on here than just a Linux executable. Sketch-setup sets max sketch size to 256KB, and uses modprobe mdram to enforce it. This may impact that gentleman who wanted to increase sketch size in the IDE.

                   

                  Also, on that reset script, the program name that gets killed is clloader. This also argues against sketches being simple executables. Killing clloader kills the sketch that it loaded. So at a minimum, the sketch that is loaded is a daughter task of clloader. Reset sketch button can not reset an executable not loaded by clloader.

                  • 6. Re: Start sketch from Linux
                    Clayton Hofrock

                    I might not be correct in my assumption that the sketch is just an executable.

                     

                    I am fairly sure that if you move the sketch file (or rename it), the sketch reset button will no longer work.

                     

                    It is also probably dangerous to run multiple sketches at the same time. The sketches could be competing for the same hardware resources. So one sketch might turn D13 into an input and try to read from it, while sketch2 might set D13 as an output. (Even if the sketch is not using a pin, it might set the unused pins to a default setup??)

                     


                    • 7. Re: Start sketch from Linux
                      antoncivit

                      The sketch I moved from the PC yesterday and didn't run started perfectly today when I powered the board again. Thus if the sketch is started by linux in the correct way there is no problem in loading it with ssh.

                      An interresting fact is that this sketch (a web sever led controller Arduino Web Server LED Control) works perfectly well in Galileo using WiFi although it uses the ethernet arduino libraries (!!).

                      I changed to the blink example (blink.cpp.elf -found with search in windows) copied it to the sketch directory, changed name and permisions, turn power off and on and led starts blinking. However restart or even shutdown -r now will not work (?)

                      • 8. Re: Start sketch from Linux
                        CorBee

                        Hi,

                         

                        As I want to run most of the stuff on the Galileo without the need of a direct USB connection to upload and run sketches Ive created a rather simple workaround.

                         

                        I made a small script in my home/root directory on the galileo I can use to start Arduino sketches(be aware that I am a newbie on Linux):

                        >>>>>>>>>>>>>>>>>>>>>>>>>>>>

                        #!/bin/bash   

                        # script to start arduino based sketches

                        cd /

                        cd sketch

                        if [ -f $1 ]

                          then

                           echo "file $1 exists"

                           echo "preparing $1 with chmod"

                           chmod +x $1

                           echo "starting $1 as background process"

                           ./$1 /dev/ttyS0 > /dev/null 2>&1 &

                          else

                           echo "file $1 does not exist"

                        fi

                        >>>>>>>>>>>>>>>>>>>>>>>>>>>

                        If saved the above in a file called startsketch, made the file it executable with chmod +x startsketch

                         

                        After compiling any arduino sketch I save the *.elf file using winscp in the sketch/sketch folder on the Galileo.

                        As long as you dont use the name sketch.elf the file will not be started at bootup.

                        If I want to run an arduino sketch on the galileo I simply call ./startsketch mysketch.elf either inside winscp or using putty

                         

                        cheers

                        CorB