Raspberry Pi – Scheduling Tasks

In this video I’ll be showing you how to schedule python scripts to run on your Raspberry Pi.

 

To test out the scheduled tasks that we will be creating I’ll be using a python script to blink the LED.

For this project you’ll need:

  • A Raspberry Pi
  • Suitable USB power supply
  • SD card with Raspbian image on it
  • An LED
  • 270ohm resistor
  • Jumper wires

To begin insert the LED and resistor into a breadboard with the resistor connected to the negative side of the LED. Followed by connecting the positive leg of the LED to GPIO 14 and the other side of the resistor to ground on the Pi.

I’m then going to insert the SD card, power up the pi and login. Then navigate to the desktop and create a directory called led using this command.

Cd Desktop, sudo mkdir led, cd led

To create the python script enter this command sudo nano blink.py and enter the following code into python script. To test that the script blinks the led enter the following command sudo python blink.py. Once we know that the script works we can schedule a task to execute the script using the cron tab. Enter this command to edit the cron tab crontab -e.

We can then enter this line in the file to set our python script to execute once every minute.

* * * * * python /home/pi/Desktop/LED/blink.py

The timing is indicated by the stars after saving the file you can view the cron tab tasks by using this command crontab -l. For more information about creating cron jobs, check out the raspberrypi.org website.