A PiPresents pipresents.wordpress.com/ show (we're talking about a Raspberry Pi running Raspbian) can be set to end at a time of day, but it does not have a way to set a day of the week. I have created a workaround for this using the standard Linux cron scheduler and some bash scripts.

Let's take a look at the first script. I think the comments explain it well enough. I named mine pp.sh. Be sure to make the file executable after you create it.

#!/bin/bash

# the name of the profile should be passed to this script
profile=$1

# show a black/blank screen
qiv -fmisC -d 5 /home/pi/media/common/blank.png &
# stop any running PiPresents shows
kill $(ps aux | grep pipresents.py | awk '{ print $2 }')
sleep 3;
# start the new show with the given profile and in the home folder below
python /home/pi/pipresents/pipresents.py -fb -o /home/pi/media -p "${profile}"

Now add an entry in cron to start the show. Run cron from your normal user (pi) in a terminal with crontab -e. The entry below starts a profile named 'myshow' at 8:30 am every sunday.

30 08 * * 0 /home/pi/pp.sh myshow

That's really all there is to it.

However, I also have a script to turn the screen on and off as part of the schedule, which would have a cron entry like this to turn off at 1:00 PM.

30 08 * * 0 /home/pi/screen.sh on; /home/pi/pp.sh myshow
00 13 * * 0 /home/pi/screen.sh off

Screen.sh looks like this.

#!/bin/bash

export XAUTHORITY=/home/pi/.Xauthority
export DISPLAY=":0"
export XAUTHLOCALHOSTNAME=localhost

if [ "$1" == "on" ]; then

  # see if we're already on
  state=$(tvservice -s | grep -oE 'DMT|CEA')
  echo "${state}"
  if [[ $state = "DMT" || $state = "CEA" ]]; then
    exit 0
  fi

  # turn on
  tvservice -p; 
  sleep 1;
  fbset -depth 8
  fbset -depth 16
  xrefresh
  sleep 3;

  # see if we're really on
  state=$(tvservice -s | grep -oE 'DMT|CEA')
  echo "${state}"
  if [[ $state = "DMT" || $state = "CEA" ]]; then
    exit 0
  fi
  exit 1
fi

if [ "$1" == "off" ]; then

  # see if we're already off
  state=$(tvservice -s | grep -o  'off')
  if [[ ${state} == "off" ]]; then
    exit 0
  fi

  # turn off
  tvservice -o;
  sleep 5;

  # see if we're really off
  state=$(tvservice -s | grep -o  'off')
  if [[ ${state} == "off" ]]; then
    exit 0
  fi
  exit 1
fi

Another improvement might be to turn off the PiPresents show when turning off the screen and turn on the screen based on some input.

Traffic Question 15: Mailing a letter

Traffic Question 15:

During a period of heavy traffic, you want to mail a letter and then head in the direction of the pink arrow. How do you do it?

  1. Stop at Mailbox A, then do a U turn
  2. Park in a spot near Mailbox A, then turn left out of the parking lot
  3. Use Mailbox A, then use the left turn lane at the intersection to do a legal U turn
  4. Turn right at the main street, turn left into the parking lot for Mailbox B, then go through the intersection in the desired direction

Traffic Question 14: A traffic light turns yellow and you’re not quite going to make it through before it turns red... what do you do?

Traffic Question 14:

A traffic light turns yellow and you’re not quite going to make it through before it turns red... what do you do?

  1. Stomp on the gas pedal and zoom through
  2. Continue through the intersection without any change in speed
  3. Wait until the last second and then stomp on the brake
  4. Start coming to a gradual stop immediately
  5. None of the above

Traffic Question 9: If you get a phone call while you’re driving, what do you do?

traffic-09q.pngTraffic Question 9: If you get a phone call while you’re driving, what do you do?

A. Answer it right away

B. Wait until you get to a stop light and call back.

C. Stop at a stop sign and call back.

D. See who it is. If you think it might be an emergency, park the car in a designated parking area and then call back.

(Yes, this is pretty similar to #2 If you get a text while you’re driving... The main difference is, texting on the phone is illegal whereas talking on the phone is legal. At least in Moline.)

Traffic Question 12: Which of the following are factors in whether or not a vehicle is going to be slower than normal?

Traffic Question 12:

Which of the following are factors in whether or not a vehicle is going to be slower than normal?

* Car is Buick, Cadillac, or similar type

* One or more children are present

* Vehicle is a minivan

* Age of driver is over 60

* Handicapped license plates

* Driver is using cell phone

* Vehicle is a "sporty" color

* Driver is female

Traffic Quiz 6: Is it possible to back out of a driveway and use only one lane?

traffic-06q.pngTraffic Question 6:

The blue dots indicate the path used to pull IN the driveway.

Is it possible to back out of a driveway and head in the direction indicated by the pink arrow, using only one lane of the road?

A. No, one lane is not enough room.

B. Yes, it can be done in one lane.