7 Replies Latest reply on Mar 31, 2014 12:13 PM by Copernicus

    TimerOne library not working

    joaocandre

      I'm trying to compile and flash the TimerOne example sketch into the Galileo Board, but it doens't seem to be working (the LED is not blinking). I've also experimented placing a serial write inside timerIsr, but I don't get any serial output.ere

        • 2. Re: TimerOne library not working
          rmm200

          I can also confirm ISRBlink works on the Galileo as a locally compiled file with the one change "Timer1.attachInterrupt( timerIsr, 500000 );" It is there, blinking away.

           

          I don't use the IDE, but it is really nice to be able to run sketches as .cpp programs on the Galileo.

          (Truth in advertising - I did add a "#include <Arduino.h>" at the top of the sketch.)

          • 3. Re: TimerOne library not working
            Copernicus

            rmm200, did you post "Steps to run blink under Linux" mentioned in Re: Working with Galileo without Arduino IDE?

             

            After you compile / save your standalone sketch, does it automatically load/run with each reboot of the Galileo?

            • 4. Re: TimerOne library not working
              rmm200

              I never followed up with my how-to. I did not detect a lot of interest. I will say it took me less than ten minutes to get ISRBlink running, since my library was all set up for Blink. Just needed TimerOne.h and .cpp added.

               

              My sketches run strictly as programs, are persistent of course, but do not restart or honor the "reset" button on the board. There is no reason that could not be added, but I have not looked at it. It might be as simple as naming the executable "sketch.elf" and putting it in the right location. My sketches use all the normal "main" hooks. A feature is that my sketches can use all the sketch "trace" routines. The sketch interrupt structure would only allow for one "resetable" sketch.

              • 5. Re: TimerOne library not working
                Copernicus

                Seems like exploratory examples would be of general interest.


                What you mean by "main hooks"? "trace routines"?

                 

                Seems like a versatile alternative development/deployment approach.

                • 6. Re: TimerOne library not working
                  rmm200

                  Apologies to the forum for including code, but it is worth looking at the main.cpp that is in x86/cores/arduino.

                  It includes trace initialization as well as interrupt hooks. I use this pretty much intact in my version, and the listed log files work.

                   

                  // Arduino hooks

                  #include <Arduino.h>

                  #include <trace.h>

                  #include <interrupt.h>

                   

                   

                  /************************ Static *************************/

                  #define MY_TRACE_PREFIX __FILE__

                   

                   

                  /************************ Global *************************/

                  int main(int argc, char * argv[])

                  {

                    // TODO: disjoin platform ID defined in /sys/firmware/boad_data/plat_id with define PLATFORM_ID

                    // and refuse to run if identifiers don't match

                   

                   

                    // Install a signal handler

                   

                   

                    // make ttyprintk at some point

                    stdout = freopen("/tmp/log.txt", "w", stdout);

                    if (stdout == NULL){

                       fprintf(stderr, "unable to remap stdout !\n");

                       exit(-1);

                    }

                    fflush(stdout);

                   

                   

                    stderr = freopen("/tmp/log_er.txt", "w", stderr);

                    if (stderr == NULL){

                       printf("Unable to remap stderr !\n");

                       exit(-1);

                    }

                    fflush(stderr);

                   

                   

                    // debug for the user

                    if (argc < 3){

                    fprintf(stderr, "./sketch tty0 tty1\n");

                    return -1;

                    }

                    printf("started with binary=%s Serial=%s Serail1=%s\n", argv[0], argv[1], argv[2]);

                    fflush(stdout);

                   

                   

                    // TODO: derive trace level and optional IP from command line

                    trace_init(VARIANT_TRACE_LEVEL, 0);

                    trace_target_enable(TRACE_TARGET_UART);

                   

                   

                    // Init IRQ layer

                    interrupt_init();

                   

                   

                    // Call Arduino init

                    init(argc, argv);

                   

                   

                  #if defined(USBCON)

                    USBDevice.attach();

                  #endif

                   

                   

                    setup();

                    for (;;) {

                    loop();

                    //if (serialEventRun) serialEventRun();

                    }

                    return 0;

                  }

                   

                  And here is my version of Blink. Note the use of trace::

                   

                  #include <Arduino.h>

                  #include <trace.h>

                   

                   

                  #define MY_TRACE_PREFIX "blink"

                   

                   

                  /*

                    Blink

                    Turns on an LED on for one second, then off for one second, repeatedly.

                   

                   

                    This example code is in the public domain.

                  */

                   

                   

                  // Pin 13 has an LED connected on most Arduino boards.

                  // give it a name:

                  int led = 13;

                   

                   

                  // the setup routine runs once when you press reset:

                  void setup() {

                    // initialize the digital pin as an output.

                    trace_debug("%s: Calling pinMode", __func__);

                    pinMode(led, OUTPUT);

                  }

                   

                   

                  // the loop routine runs over and over again forever:

                  void loop() {

                    trace_debug("%s: loop entered", __func__);

                    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)

                    delay(1000);               // wait for a second

                    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW

                    delay(1000);               // wait for a second

                  }

                  • 7. Re: TimerOne library not working
                    Copernicus

                    Thanks for lifting the lid on some of the internals. Hoping something eventually appears for x86 like this: A Tour of the Arduino Internals: How does Hello World actually work? | Ideas For Dozensfor