I am trying to run a script at bootup. I am autologing to desktop.
Script1: pibot.sh
#!/bin/bash
sudo python /home/pi/rpibot.py
Script2: rpibot.py
import rrb2 as rrb
from rrb2 import *
import pygame
import sys
from pygame.locals import *
import time
rr = RRB2()
running = True
leds_on = False
pygame.init()
screen = pygame.display.set_mode((620, 480))
pygame.display.set_caption('RaspiRobot')
pygame.mouse.set_visible(0)
GPIO.setwarnings(False)
while True:
distance = rr.get_distance()
if distance < 10 and running:
rr.stop()
# if not running:
rr.set_oc1(leds_on)
rr.set_oc2(leds_on)
time.sleep(0.6)
leds_on = not leds_on
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == KEYDOWN:
if event.key == K_UP:
rr.forward()
rr.set_oc1(True)
rr.set_oc2(True)
elif event.key == K_DOWN:
rr.set_oc1(True)
rr.set_oc2(True)
rr.reverse()
elif event.key == K_RIGHT:
rr.set_oc1(False)
rr.set_oc2(True)
rr.right()
elif event.key == K_LEFT:
rr.set_oc1(True)
rr.set_oc2(False)
rr.left()
elif event.key == K_SPACE:
rr.stop()
rr.set_oc1(False)
rr.set_oc2(False)
Both work in command line in terminal, but do not work on boot. I have tries putting pibot.sh
in rc.local
and get error unable to read with the update command.
/bin/bash
and use#!/usr/bin/env python
in your python script. NOTE that running scripts which assume PATH or screen is unlikely to be successful. Maybe this should be run after login.