Run Arduino code automatically on power up?

Discussion in 'UDOO NEO' started by knick, Nov 17, 2016.

  1. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    My Arduino code only runs when launch it from the Arduino IDE. How can I make it run every time the board it powered up, without having to launch it from the IDE each time?
     
  2. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,295
    Likes Received:
    565
    It should start the latest compiled and uploaded version after each reboot:http://www.udoo.org/docs-neo/Arduino_M4_Processor/Overview.html
    From where do you start the Arduino IDE? on the Neo itself or on an external PC?
     
  3. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    I can't find the thread so quickly, but I thought there was some issue that the m4-file doesn't get synced to the sd card if you power down the Neo too quickly. Normally the Neo starts the last 'Arduino' program on startup. It should be in /var/opt/m4, and is called m4last.fw.
     
    Andrea Rovai likes this.
  4. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    I am launching the sketch from an external PC.

    I'm pretty sure my board used to run the sketch automatically each boot, but it's not doing it now. Is it possible that something in my sketch could be causing the issue?
     
  5. jcverive

    jcverive New Member

    Joined:
    Nov 17, 2016
    Messages:
    1
    Likes Received:
    0
    Are you using a genuine Arduino or are you using a "compatible" device?


    Sent from my iPhone using Tapatalk
     
  6. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    @knick, today (17-Nov) UDOO has released a new UDOObuntu. I haven't checked the release notes, but if it is indeed the sync problem I assume that that is included as it has been known for a few weeks.

    If you think it might be something in your program, you could also remove the m4last.fw file, upload the file again and reboot. If the problem persists but the m4last.fw file is still there I would assume that indeed it is your program. Then fallback to a simple blink of pin 13 (builtin led), and retry.
     
  7. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    I am using an Udoo Neo programmed from a PC. Setup is as described in the 'getting started' section of the docs.
     
  8. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    Thanks, I will give this a try tomorrow.
     
    Andrea Rovai likes this.
  9. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,295
    Likes Received:
    565
    Try it with the blink led example sketch first so you are sure it is not your sketch that is the problem.
     
  10. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    I just tried running a simple "hello world" sketch. It still doesn't run automatically on power-up.

    I'll try updating the OS later.
     
  11. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,295
    Likes Received:
    565
    You have to wait 1 minute between upload sketch and reboot, else the m4last.fw file will be empty after reboot by the reset button. It is a SD card protection mechanism from Linux.

    If you update the OS you can reboot directly after uploading.
     
  12. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    After updating the OS it is working.
     
    Andrea Rovai likes this.
  13. bryan20miles

    bryan20miles New Member

    Joined:
    Mar 10, 2016
    Messages:
    11
    Likes Received:
    0
    Ok, I have a couple of questions.
    1) If your sketch uses the serial port to log data to a 'terminal', should the data continue to be logged (when restarting the terminal after restarting the NEO)? If so, it doesn't for me; I have to reload my sketch.
    2) What OS update is being referenced in the reply above?
     
  14. Maurice

    Maurice Active Member

    Joined:
    Oct 13, 2015
    Messages:
    394
    Likes Received:
    87
    UDOObuntu 2.1.1 solves an issue where the M4 program file isn't synced to the SDD storage right away.
     
  15. bryan20miles

    bryan20miles New Member

    Joined:
    Mar 10, 2016
    Messages:
    11
    Likes Received:
    0
    Thank you Maurice. I'll have to see what version I'm using.
     
  16. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,295
    Likes Received:
    565
  17. bryan20miles

    bryan20miles New Member

    Joined:
    Mar 10, 2016
    Messages:
    11
    Likes Received:
    0
    Thanks waltervl, I'll take a look!

    Bryan
     
  18. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    I was having the same issue when writing to the hardware serial port (Serial0). It worked ok after programming from the Arduino IDE, but nothing would get written to the serial port after a reboot. I found that adding a 2 second delay at the top of the begin() function resolved the issue.
     
    waltervl likes this.
  19. waltervl

    waltervl UDOOer

    Joined:
    Dec 12, 2015
    Messages:
    2,295
    Likes Received:
    565
    Waiting 2 seconds is of course the least secure way to check if the serial connection is available.

    What if you do
    While (Serial0.available > 0) {
    Serial0.println(your_string);
    }
    This should check first if serial0 is available before writing
     
  20. knick

    knick New Member

    Joined:
    Nov 1, 2016
    Messages:
    29
    Likes Received:
    8
    Correct me if I'm wrong, but isn't the serial.available() method for checking if there is any data sitting in the receive buffer?
    In my case the data flow is just one way. The M4 is writing debug information out to the serial port (transmit), but isn't expecting to get anything back (receive). So Serial0.available() should always return 0?
     

Share This Page