Start Automatically
(Raspberry Pi)

It can be very useful to have your programs start automatically when your Raspberry Pi launches. For example, you may be logging data from a greenhouse and displaying it on a website. After developing the program, you will disconnect your Raspberry Pi from keyboards/monitors, plug it in and let it log data and serve your website.

This project will show you how to run your projects automatically when your Raspberry Pi starts up using cron.


Before getting started, make sure you have the following parts.

Getting Started Kit

Any Raspberry Pi

Step 1

Simply connect your Getting Started Kit to your Raspberry Pi.

If you haven't set up your Raspberry Pi with Phidgets yet, visit the Getting Started Kit tutorial.

Write Code

Copy the code below into a new Python project. If you need a reminder of how to do this, revisit the Getting Started Course.


#Add Phidgets library
from Phidget22.Phidget import *
from Phidget22.Devices.TemperatureSensor import *
from Phidget22.Devices.DigitalOutput import *
#Required for sleep statement
import time

temperatureSensor = TemperatureSensor()
statusLED = DigitalOutput()



#Use your Phidgets
while (True):
    #Update user
    print("Logging data...")
    #Blink LED to indicate program is running
    statusLED.setState(not statusLED.getState())

    #Write data to file in CSV format
    with open ('phidgets_temperature.csv','a') as datafile:
        datafile.write(str(temperatureSensor.getTemperature()) + "\n")

Create Program

The code above logs temperature to a file and flashes the red LED on your Getting Started Kit.

Save the Python script in /home/pi/ under the name If you are unfamiliar with logging data from a Phidgets sensor, review this project.

Schedule Run with cron

cron allows you to easily schedule tasks on your Raspberry Pi. In this situation, cron is used to run your Phidgets project whenever the Raspberry Pi starts.

Open your terminal and enter the following command:

crontab -e

Add the following line to the bottom of your crontab

@reboot python3 /home/pi/

Exit and save the file. When you reboot your Raspberry Pi, you will see your red LED blinking indicating that the program is running. You can check the output file to see your logged data.

  1. Make sure everything is plugged in properly and your VINT Hub is connected to your computer
  2. Stop running other programs that are using your Phidgets before running a program.

If these do not solve your issue visit the Advanced Troubleshooting Page.

What are Phidgets?

Phidgets are programmable, modular USB devices, either sensors or controllers that you can connect together. Simply write code in your favorite language and solve real-world problems.

Learn more

Set your preferences


Mac OS

Raspberry Pi











Visual Studio


Setting your preferred operating system, programming language and environment lets us display relevant code samples for the Getting Started Tutorial, Device Tutorials and Projects