1

I write a python program opencv and python. also I'm using raspicam and I want using my python program without keyboard and mouse. Of course auto run mode. I tried two ways like below and I can't find solution.

  1. sudo nano /etc/rc.local between codes and exit0 I write sudo python /home/pi/my_program.py or sudo python /home/pi/my_program.py & then ctrl+x , Y, enter. after reboot, raspicam blink on and a few second later blink off.

  2. sudo crontab -e and then I write @reboot python /home/pi/my_program.py or @reboot python /home/pi/my_program.py & then ctrl+x , Y, enter. after reboot, raspicam blink on and a few second later blink off.

I tried two way and I couldn't do it. Please help me.

0

I'm assuming that your script works fine when invoked manually on terminal. Well, does your program make use of GUI functions like imshow or something ? If that's the case, you can't invoke it using rc.local / crontab since items in both of them execute before running an X server.

You will have to place it under /etc/xdg/lxsession/LXDE-pi/autostart.

Follow these steps :

  1. sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
  2. Add this line at the end : @sudo /usr/bin/python /path/to/script/script-name.py
  3. Ctrl + x, yes to save changes.
  4. Reboot to make it effective.

Hope it helps.

1

I had a similar issue and the answer from dhruvvyas90 got me on the right track, but the autostart file in question wasn't actually launching anything.

Based on this forum here https://www.raspberrypi.org/forums/viewtopic.php?t=131760 I found that replacing the first step with

nano ~/.config/lxsession/LXDE-pi/autostart

Was what I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.