projects_image.png
Raspberry Pi 4

With the Raspberry Pi 4, you can now program in the latest version of Scratch, a popular programming language for beginners. Additionally you can use the new Scratch Raspberry Pi extensions to interact with Scratch in a more physical way.

This guide will go through how to set up the Raspberry Pi 4 to program with Scratch 3. Additionally, we will run through a demo showcasing some of the possibilities that this dynamic combo of a powerful microprocessor and intuitive, easy to learn programming language allows.

projects_image.png
source: Wikimedia Commons

What's Scratch?

Scratch is a block-based language geared for beginners that lets you create your own interactive stories, animations, games, music, and art.

Scratch is easy to use and requires no prior coding experience!

Parts

Here's what you'll need to get started

1) Raspberry Pi 4 with your choice of RAM (any will do just fine!)

Angled shot of Raspberry Pi 4
NOTE: Due to stock limitations we may only be able to offer refunds or store credit for Pis that are defective, damaged or lost in transit.The Raspberry Pi...
Out of Stock
Angled shot of Raspberry Pi 4
NOTE: Due to stock limitations we may only be able to offer refunds or store credit for Pis that are defective, damaged or lost in...
Out of Stock
Angled shot of Raspberry Pi 4
NOTE: Due to stock limitations we may only be able to offer refunds or store credit for Pis that are defective, damaged or lost in transit.The Raspberry Pi...
Out of Stock
Have a different Pi? Fear not! You can use other versions of Raspberry Pis as well as long as the Raspbian operating system is updated. However without the Pi 4 you will not be able to use the latest version of Scratch (Scratch 3).

2) Pi power supply

USB C power supply 

Angled shot of Official Raspberry Pi Power Supply 5.1V 3A with USB C with Power plug facing down.
The official Raspberry Pi USB-C power supply is here! And of course, we have 'em in classic Adafruit black! Superfast with just the right amount of cable length to get your Pi 4...
$7.95
In Stock

or you can use USB micro B power supply with an an adapter

5V 2.5A Switching Power Supply with 20AWG MicroUSB Cable
Our all-in-one 5V 2.5 Amp + MicroUSB cable power adapter is the perfect choice for powering single-board computers like Raspberry Pi, BeagleBone, or anything else that's...
$8.25
In Stock
Angled shot of Micro B USB to USB C Adapter.
As technology changes and adapts, so does Adafruit, and speaking of adapting, this adapter has a Micro B USB jack and a USB C...
$1.25
In Stock

3) Display

You can use any display with an HDMI input.

We also have some options:

Top down view of a HDMI 5" Display Backpack - Without Touch connected to a Raspberry Pi powered by a USB. The HDMI screen displays a desktop image including the Raspberry Pi logo.
Its a mini panel-mountable HDMI monitor! So small and simple, you can use this display with any computer that has HDMI output, and the shape makes it easy to attach to a case or rail....
$59.95
In Stock

4) Micro HDMI to HDMI Cable

Micro HDMI to HDMI Cable - 2 meter
Connect an HDMI device with a micro HDMI port to one with a regular size HDMI port together with this basic HDMI cable. It has nice molded grips for easy installation, and is 2 meter...
$8.95
In Stock

5) Keyboard and mouse

Wireless Keyboard and Mouse Combo
Add a good quality, slim chiclet keyboard as well as an optical mouse to your Raspberry Pi, Beagle Bone Black or other mini-computer with this wireless combo set. Best of all,...
$19.95
In Stock

6) 16GB Micro SD card w/ Noobs

Angled shot of 16GB Micro SD Card with NOOBS 3.1
NOOBS 3.1 is the fastest way to have a variety of operating systems on your Pi. Available on a 16G card, you can now boot multiple OS's such as Raspbian, Pidora, RaspBMC,...
$14.95
In Stock
Already have a 16GB micro sd card but don't have NOOBS pre-installed on it? No worries! Read on to find out how to get it set up with NOOBS.

7) 1K ohm resistors

Angled shot of 25 Through-Hole Resistors - 1.0K ohm 5% 1/4W.
ΩMG! You're not going to be able to resist these handy resistor packs! Well, axially, they do all of the resisting for you!This is a 25 Pack of...
$0.75
In Stock

8) Female to male jumper wires

Premium Female/Male 'Extension' Jumper Wires - 20 x 6 folded over
These Female/Male Extension jumper wires are handy for making wire harnesses or jumpering between headers on PCB's. These premium jumper wires are 6" (150mm) long and come in...
$1.95
In Stock

9) Breadboard

Angled shot of half-size solderless breadboard with red and black power lines.
This is a cute, half-size breadboard with 400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm x 5.5cm with a standard double-strip in the...
Out of Stock

10) Leds

scattered pile of multi colored unlit LEDs
Need some miniature indicators? We are big fans of these diffused LEDs. They are fairly bright, so they can be seen in daytime, and from any angle. They go easily into a breadboard and...
$2.95
In Stock

We will be using the official Raspberry Pi guide to set up the Pi 4. Head over there for instructions on how to get your Pi up and running.

Set up the SD card

The SD card linked in the "parts" section of the "overview" page has NOOBS pre-installed on it so if you have an SD card with NOOBS installed already, skip ahead to the "Connect your Pi" section. However if you have another SD card and want to install NOOBS follow the steps in the "Set up the SD card" section.

Connect your Pi

  • Insert the SD card into the slot on the Pi
  • Connect keyboard and mouse via the Pi's USB hubs
  • Power up display then connect to Pi via micro-hdmi cable
  • Add any other optional connections

 

Start up your Pi

  • Power up the Pi via usb c cable
  • Download Raspbian via NOOBS

Finish the Setup

  • Configure country, language and timezone
  • Set up password for Pi
  • Connect Pi to wifi network
  • Install any necessary updates

Update the OS to Raspbian Buster

Follow the instructions via video or text below to update your Pi

First, open a terminal window

Click the black square icon on the top left of the desktop to open a terminal window

In a terminal window type and return:

sudo apt-get update

Next type and return:

sudo apt-get dist-upgrade

When prompted, y/n type y and return.

This will update your Pi's operating system to Rasbpian Buster which may take some time. (10 - 15min)

When the update is complete, restart the Pi by running the command:

reboot

Trouble Shooting 

Problem: My screen is not showing any output from the Raspberry Pi.

Potential Solution 1: Make sure all connections are in place before booting up Pi. 

Potential Solution 2: Double check that your SD card has NOOBS correctly installed.

Now that we're all set up, it's time to get Scratch up and runnin'!

What can I do with Scratch?

As mentioned earlier, Scratch is a block-based language geared for beginners that lets you create your own interactive stories, animations, games, music, and art.

For more on the ins and outs of Scratch check out the guide: 

Scratch 3 Walkthrough and Demo

Connecting to the world

While you do not need a Raspberry Pi to run and use Scratch (there is a web-based editor that can be used on any computer with a browser), the Pi unlocks a whole other set of capabilities for us. 

Connecting this powerful programming language to a Raspberry Pi lets us more easily take advantage of the "GPIO" pins to have our Scratch program interact with the outer world!

projects_Screen_Shot_2019-09-18_at_6.20.57_PM.png
source: https://www.raspberrypi.org

How to install Scratch 3 using the Recommended Software app


Open up the menu, click on Preferences > Recommended Software, and then select Scratch 3 and click on OK.

How to install Scratch 3 using the terminal

Open a terminal window, and type in and run the following commands:

sudo apt-get update
sudo apt-get install scratch3

Add the Extension

Once Scratch 3 is installed on the Pi, go ahead and open up Scratch 3 by clicking the Raspberry Pi icon on the top left of the desktop, then Programming>Scratch3

Add the Raspberry Pi GPIO extension

Click the blue icon at the bottom left of the application to open the extensions.

Select the extension entitled "Raspberry Pi GPIO"

Now we have access to some awesome GPIO functionality which we'll get to next!

Read more about the different Raspberry Pi extensions for Scratch here!

Which version of Scratch to use?

While you can use any version of Scratch, if you have a Raspberry Pi 4, we recommend using Scratch 3. Follow the instructions on the next page to get Scratch 3 on your Pi 4.

If you have an older Pi however such as a Pi 3 or older, you may not be able to run Scratch 3 because of the memory requirements of the program.

You can however run Scratch 2 which still has Raspberry Pi GPIO functionality, so skip to the section "Scratch 2" to find out how.

How to open Scratch 2 on the Pi

Once you are in the Raspbian desktop, you will open up Scratch 2 which comes preinstalled on the Pi.

To Open Scratch 2:

Click the Raspberry Pi icon on the top left of the desktop, then Programming>Scratch2

And that's it! Scratch is ready to go!

If Scratch is not showing up on your Pi, make sure your version of Raspbian is up to date.

Adding the Pi Plugin

Open the More Blocks panel, click Add an Extension, and select Pi GPIO. You should then see two new blocks appear:

You can use these two purple blocks to control output pins or read input pins by entering the pin number into the field, or using a variable containing the pin number.

Next up, putting the spiffy new blocks to work.

Blinky LED demo

We will now put together a small demo using the Pi and some components. In this simple demo we will use Scratch to program the Pi to blink an LED.

Wiring

First, let's wire things up.

You will need handy:

  • one led (any color)
  • one resistor that is 1K or less (click here for more on how to determine resistor values)
  • 2 female to male jumper wires
The above photo from Fritzing is a Raspberry Pi 3 because at the time of this guide writing, there is no Pi 4 Fritzing object, but the pinout is identical
  • Connect one female to male jumper wire from GPIO pin 2 on the pi to any spot on a bread board
  • Next, connect the resistor (1K or less will do) from the GPIO 2 jumper wire to another spot on the breadboard
  • Now take the LED and determine which leg is longer, and connect that leg to the other end of the resistor with the opposite end going to another spot on the bread board.
  • Lastly, connect male to female jumper wire from the unconnected end of the led to a ground pin on the Pi.

Next we'll program the Pi in scratch to blink the LED.

Going Further

What else can you think of to use with Scratch and Raspberry Pi?

Some ideas:

  • Add buttons and other components.
  • Create a custom interactive game by connecting buttons, leds and other components. Then program these components to control and react to game elements like sprites and backdrops.
  • Add a CRICKIT HAT to make things move!

Next we'll program the Pi in Scratch to blink the LED.

  • Click the yellow "events" block group, then drag and drop the "when (flag) clicked" block over to the "script area" on the right side of the program's interface.
  • Next click the orange "control" block group section and drag in a "forever" loop.
  • Also from the "control" section, drag in two wait 1 seconds blocks.
  • Then click on the "Raspberry Pi GPIO" block section and drag in two set gpio to output blocks. Set one block to set gpio to output high. Set the other to set gpio to output low
  • Lastly rearrange the blocks in the order as shown.

Now click the green flag and see what happens!

Use Scratch 2 to program the Pi to blink the LED.

  • Click the orange "events" block group, then drag and drop the "when (flag) clicked" block over to the "script area" on the right side of the program's interface.
  • Next click the yellow "control" block group section and drag in a "forever" loop.
  • Also from the "control" section, drag in two wait 1 secs blocks.
  • Then click on the "more blocks" block section and drag in two "set gpio to" blocks. Set one block to set gpio to output high. Set the other to set gpio to output low
  • Lastly rearrange the blocks in the order as shown above.

Now click the green flag and see what happens!

Going Further

What else can you think of to use with Scratch and Raspberry Pi?

Some ideas:

  • Add buttons and other components.
  • Add a CRICKIT HAT to make things move!
  • Use the Sense HAT extension to sense tilting, shaking, orientation, use a joy stick, measure temperature, pressure humidity, display text and more.
  • Create a custom interactive game by connecting buttons, leds and other components. Then program these components to control and react to game elements like sprites and backdrops.

Click below for some more resources and ideas of what else you can do with Raspberry Pi and Scratch!

This guide was first published on Sep 21, 2019. It was last updated on Sep 21, 2019.