Physical Computing – Scratch 2.0 for Raspberry Pi


This is my 3rd tutorial with a focus on Scratch and Physical Computing. Regarding this topic, I have already published:

Here, we will learn the new version of Scratch, the 2.0, exploring some new and exciting projects.physical computing scratch 2-0 for raspberry pi

In short,

We will learn:

  • What is Scratch 2.0 and its differences with Scratch 1.4
  • How to interact with LEDs, Push-Buttons and a Buzzer
  • How to create Special Blocks
  • How to handle with variables
  • How to integrate animations and the Physical world.

Let’s go!

Step 1: Bill of Material – BoM

For the experiences in this tutorial, you will need at least the items:

  • Raspberry Pi (V2 or V3)
  • LEDs (Red, Yellow, and Green)
  • 1 Button
  • 1 Active Buzzer
  • Resistors: 3 x 220 ohm
  • Cables
  • Full Breadboard

Step 2: The Scratch 2.0

As we know, Scratch is a great tool to teach beginners how to code, but before starting our tutorial, I really recommend that you go familiarize yourself with the Scratch 2.0 language, following some basic tutorials. Doing that will help you to better understand how to use a Raspberry Pi for Physical Computing.

There are 2 ways to do that:

  • Go to Official Raspberry Foundation site,

A new offline Scratch 2 version started to be delivered bundled with the last Raspbian OS release, and it is really great, with several new features that will help you to create a more professional codification.

WARNING: At least with me, the actual version introduced some “freezing issues”, that could be related with Flash. Those freezings appeard whe I tried to upload new background or sprits.

Opening the program:

When you have the Pixel desktop in front of you, go to left up corner Application Menu (the “Raspberry Pi logo”) and open it. You will find as one of the options: “Programming“.

  • Open it and click on “Scratch 2” (note that the old version Scratch 1.4 (named as “Scratch“) is also there.
  • Once you open the Scratch program, you will get the screen shown above.
  • Click on “More Blocks
  • Click on “Add an extension“. The option “Pi GPIO” Library will be available. Select it and click [OK]
  • The PI GPIO library will be installed and the “green led” shows that it is running properly.
  • 2 news blocks will be now available to be used with your Physical Computing programs.

The first block:

set gpio <GPIO number> to [output high] 

above has 3 possible parameters:

  • output high
  • output low
  • input

The second block:

gpio <GPIO number> is high? will return:

  • True” or “False” depending on GPIO digital level (“True = 1” and “False = 0”).

Scratch 2.0 also allows the creation of custom blocks, allowing code to be encapsulated and used (possibly multiple times) in a project. We will see how to do it in the examples.

Step 3: The GPIO Pin Numbering

We will not cover how to prepare the Raspberry Pi to be used in this tutorial, but If you need any help, please refer to this link: Installing Raspbian with NOOBS.

Our Raspberry Pi will be running with the latest Raspbian version of the Operational System, having PIXEL, as our desktop environment.

Once we will interact with the physical world it is good to remember that our gateway to that will be the Raspberry Pi GPIO connector. The above photo shows the connector, where I have drawn some fictional components in red.

Scroll to Top
Scroll to Top
Read previous post:
Flexible Smartwatch
Flexible Smartwatch

Description This project aims to build a thin, flexible smartwatch. It's wrap-around display and touchscreen will allow it to display...