Hi,
Is it possible to run RPi in Embedded System mode. I mean is it possible to configure RPi to start running a set program on Power-on and keep running till it is powered off. If it possible, what are the steps involved? Advise please.
Code: Select all
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
@reboot /home/pi/your_program_here
If you did start your app "every 2 minutes and 7 seconds", then crontab would be the wrong choice, as it only has a granularity of a minute.socialdefect wrote:Why Crontab? Do you start your apps every 2 minutes and 7 seconds??
There are a few ways to easily get things started at boot time.rpdom wrote:
However, there is nothing wrong with using the "@reboot" parameter in crontab to start a script shortly after boot up. It'll just take a little longer to start than any of the other methods of running something every time the system is booted.
Have a loop in your program that checks the time.Shresta wrote:How can I set the log rate to 10 Hz?
Code: Select all
# Psuedo code. Not real code.
sample_time = time.msecs;
while true
sample_time = sample_time + 100; # Set next sample to be in 0.1 seconds
get_sample; # Get this sample, then wait
while time.msecs < sample_time
sleep(0.001) # sleep for 1000th second
endwhile
endwhile
Code: Select all
time_next_iteration=time(); # time() would be a system call for getting current time
while true
time_current_iteration = time_next_iteration;
your_periodic_function_here(); # Get a new sample or something else
time_next_iteration = time_current_iteration + 100msec;
period_to_sleep = time_next_iteration - time();
if period_to_sleep>0
sleep(period_to_sleep) #sleep() would be a system call
else
print("Warning: the system is too slow for real-time requirements")
endif
endwhile
I wanted to run it with Linux, I tried the method suggested in the para 2 above. It is not working. Am I missing something?rpdom wrote:One way to do that is to go really low-level and write your own kernel.img file. The Pi will load your file at boot time instead of a Linux kernel. You won't have any of the Linux drivers or libraries available, just what you build into your file. (See the Bare Metal forum for more information on that).
If you want to run with Linux, you could add "init=/path/to/myprog" to the end of the line in cmdline.txt and you will get a Linux kernel, root filesystem and your program running instead of the usual processes. You will have access to the libraries and all built-in drivers. If you mount the filesystems in read-only mode, then they will be safe against sudden power-off.
There are other ways of doing it, of course.
Can you please give me a reference on how to implement the above methods. I mean does it need adding the file path to the files mentioned?DougieLawson wrote:There are a few ways to easily get things started at boot time.rpdom wrote:
However, there is nothing wrong with using the "@reboot" parameter in crontab to start a script shortly after boot up. It'll just take a little longer to start than any of the other methods of running something every time the system is booted.
1. crontab @reboot
2. /etc/rc.local
3. /etc/init.d script and symb links to it from /etc/rc2.d
4. /etc/inittab
Each has its own merits, so pick your poison.