Skip to content

Latest commit

 

History

History
 
 

Python

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Getting Started with Python on Raspberry Pi

  1. Prerequisites
  2. Install Python 3
  3. Install Grove
  4. Install Blinka
  5. Run your first program

Prerequisites

The following steps require a Raspberry Pi Zero W with Raspberry Pi OS Lite, a Linux operating system. To install it, see Raspberry Pi Zero W Setup. Make sure to configure Wi-Fi and enable SSH access so you can find your Pi, if your computer is in the same local Wi-Fi network.

Check Python Version

A fresh installation of the Raspberry Pi OS Lite has Python 3 preinstalled. Check this with:

$ python --version
Python 3.9.2

If you don't have Python3 installed, install it with:

$ sudo apt update
$ sudo apt install python3

Additionally, you need pip3 to add python packages to your project. Install pip3 as follows:

$ sudo apt-get install python3-pip
$ pip --version
pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)

The python documentation includes chapters on installing libraries and using GPIO in Python.

Install Grove

To access the GPIOs on the Pi and work with Grove sensors and actuators we use the Grove Python package.

Install the Grove Python package with:

$ sudo pip install grove.py

Here are some code examples by Seeed Studio.

Install Blinka

As an alternative to Grove and for additional sensor libraries we use the Blinka Python package.

Install the Blinka Python package with the following steps, based on this tutorial by Adafruit:

$ sudo raspi-config # Advanced options > Expand file system
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo pip install --upgrade setuptools
$ sudo pip install --upgrade adafruit-python-shell
$ wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
$ sudo python3 raspi-blinka.py

Run your first program

Now, run your first program and install it permanently on your microcontroller.