how to use scratch on raspberry pi

Getting Started With Scratch on Raspberry Pi

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

Scratch on a Raspberry Pi is a fun way to learn about computers and coding! Scratch is a graphical programming language with a drag-and-drop interface. It lets you make your own stories, games, and animations. Want to give it a try? Let me help you get started.

Scratch comes pre-installed with Raspberry Pi OS. It has a user-friendly drag-and-drop interface in which you snap together blocks logically to make your program.

In this article, I will guide you through setting up your Raspberry Pi with Scratch. I will then give a brief overview of the Scratch environment and get you started with a step-by-step example of your first project.

If you’re like me and sometimes mix up syntax between programming languages, I’ve got just the thing for you. I’ve put together a Python cheat sheet with all the essential syntax in one place, so you can keep it handy and avoid any confusion. Download it here for free!

What is Scratch?

Scratch is a High-level, block-based, visual programming language developed by MIT. It is primarily an educational tool for children to get started with coding. It has an extremely intuitive drag-and-drop interface.

Image

Scratch is available as a stand-alone application and a web page that can be opened in a web browser. A few key features of Scratch are as follows:

  • Drag-and-Drop Blocks: Scratch uses colorful blocks that you can snap together to create code. This makes it easy to understand how programming works.
  • Customizable Characters & Background: You can create and customize your sprites (characters) and backdrops or choose from a library of pre-made ones.
  • Interactive Projects: Scratch allows you to make interactive stories, games, and animations that respond to user actions. You can add sounds, control characters, and create engaging experiences.
  • Community Sharing: Scratch has a large online community where you can share your projects, get feedback, and see what others are creating.
  • Educational Resources: Scratch offers a wealth of tutorials, guides, and projects to help you learn at your own pace and explore new ideas.

Requirements to use Scratch on Raspberry Pi

Before trying Scratch on your Raspberry Pi, let’s ensure you have everything ready to start.

Hardware Required

Scratch does not require specific hardware and can run on any Raspberry Pi. I recommend getting the latest Raspberry Pi 5 Starter Kit from Amazon. However, Raspberry Pi 4B is equally good for Scratch and can help you save some cash.

Another neat option is a Raspberry Pi 400, which comes pre-packed with a keyboard and is ideal for running Scratch, as you will not need to connect an external keyboard.

Grab my Python cheat sheet!
If like me, you always mix the languages syntax, download my cheat sheet for Python here!
Download now

Additionally, you will need the following accessories:

  • USB/ Bluetooth mouse and keyboard
  • Monitor or TV
  • Micro-HDMI to HDMI Cable (Included in Starter Kits)
  • Power Adapter (Included in Starter Kits)
  • Memory Card

You can find my latest recommendations here, with the best stuff you can use in each category (yes, I’ve tested tons of things so you don’t have to).

Note: In addition to the above, you will also need a PC/ Laptop and a Memory Card Reader for the initial setup of Raspberry Pi OS.

However, you don’t need to buy everything new; you can repurpose any old Raspberry Pi and accessories around your home.

Installing Raspberry Pi OS

First, we need to install Raspberry Pi OS on our brand-new Raspberry Pi. Installation of Raspberry Pi OS is straightforward:

  • Download Raspberry Pi Imager from their official website.
    Image
  • Insert the memory card into your PC and run the Raspberry Pi Imager.
    Image
  • Click on “Choose Device” and select the version of Raspberry Pi you are using.
    Image
  • Next, click on “Choose OS” and select “Raspberry Pi OS (64-bit)”.
    Image
  • Click “Choose Storage” and select your memory card from the options.
  • Finally, click “Next”.

The Raspberry Pi Imager will take a little while to download and install the image on your memory card. Once completed, it will show you a “write successful” popup. Now, you can safely remove the memory card from your PC, insert it in your Raspberry Pi, and boot from that.

Note: For a more detailed tutorial regarding Raspberry Pi OS, including the optional customization options available, you can consult the tutorial on “How to Install (or Reinstall) Raspberry Pi OS on Your Pi”.

Grab my Python cheat sheet!
If like me, you always mix the languages syntax, download my cheat sheet for Python here!
Download now

Installing Scratch

Scratch comes pre-installed with the full version of Raspberry Pi OS. However, if you can’t find Scratch in your Raspberry Pi menu, you can install it using the recommended software. To do that, follow these steps:

  • Connect your Raspberry Pi with a display, keyboard, and mouse and boot it.
  • Once booted and done with the initial configuration, click on the Raspberry Pi icon towards the top left of the screen.
    Image
  • Navigate to “Preferences” -> “Recommended Software”.
    Image
  • From the “Programming” tab, select (check-box) “Scratch 3” and click “Apply”.
    Image
  • It will take some time and automatically install Scratch on your Raspberry Pi.
  • To run Scratch, open the Raspberry Pi Menu and navigate to “Programming” -> “Scratch 3”.
    Image
Image

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

Getting Familiar with Scratch

Before starting our first project, let us familiarize ourselves with the Scratch working environment.

The Workspace

The Scratch workspace opens with the “Code” tab by default. This interface is used to design and run our main project, which can be divided into four parts.
Image

  • Block Palette: The leftmost area is called the Block Palette. It contains all the blocks that can be dragged and dropped to the code area to design our project. There are six types of blocks, divided into nine categories.
  • Code Area: The central area is dedicated to the Code Area. Blocks from the Block Palette can be dragged, dropped into the Code Area, and arranged to form scripts. Scripts in the code area will be used to run our project.
  • Stage: The Stage is the top-rightmost area. It shows the output of our project. Different sprites are displayed here, performing actions according to our scripts.
  • Sprite Pane: The Sprite Pane is located at the bottom right of the screen. It allows us to select the sprites and backdrops used in our project quickly.

In addition to the “Code” tab, you can switch between the “Paint Editor” and “Sound Editor” using the tabs on top of the block palette.

  • Paint Editor: This tab allows you to view, create, and edit a sprite’s costumes.
    Image
  • Sound Editor: This tab allows you to view, create, and edit a sprite’s sounds, which you can use in your project.
    Image

The Blocks

Programming in Scratch is done using blocks shaped like jigsaw puzzle pieces. Each block type has its shape and a slot shape to be inserted into. Blocks connect to form scripts that define what our project does.

There are six different block shapes in Scratch:

  • Hat Blocks: Hat blocks are the blocks that start every script. They are shaped with a rounded top and a bump at the bottom, so users can only place blocks below them.
    Image
  • Stack Blocks: Stack blocks perform specific commands. They are shaped with a notch at the top and a bump on the bottom so that blocks can be placed above and below them.
    Image
  • Boolean Blocks: Boolean blocks are blocks that act like conditions. They have an elongated hexagonal shape. Boolean blocks can hold and report “true” or “false” values. These blocks are inserted into holes of other blocks with the same shape or the shape of a reporter block.
    Image
  • Reporter Blocks: Reporter blocks act as values. They are shaped with rounded edges and can hold numbers and strings. They can also report a variable. These blocks are inserted into the holes of other blocks of the same shape.
    Image
  • C Blocks: C blocks take the shape of “C’s”. Also known as “Wrap blocks,” these blocks loop the blocks within the Cs or check if a condition is true.
    Image
  • Cap Blocks: Cap blocks are the blocks that end scripts. They are shaped with a notch at the top and a flat bottom, so blocks cannot be placed below them.
    Image

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

If you prefer watching videos instead of reading tutorials, you’ll love the RaspberryTips Community. I post a new lesson every month (only for members), and you can unlock them all with a 7-day trial for $1.

Creating Your First Scratch Project

Lost in the terminal? Grab My Pi Cheat-Sheet!
Download the free PDF, keep it open, and stop wasting time on Google.
Download now

With this initial understanding of the Scratch interface, we are ready to create our first project. In this tutorial we will make a “Catch the Apple” game using Scratch.

In this game, the player aims to catch apples falling from the top of the screen in a bowl.

Setting Up Sprites & Backdrop

Before we can start programming, we must set up the graphics required for this project.

  • First, we will delete the default “Cat” sprite from the Sprite Pane.
    Image
  • To add a new sprite, click the “Choose a Sprite” option from the Sprite Pane.
    Image
  • Select the bowl sprite from the menu (you can choose any other sprite you prefer).
    Image
  • Using these steps, add the sprite for Apple as well.
    Image
  • Next, we need a backdrop for our game. To do so, click on “Choose a Backdrop” from the Sprites Pane.
    Image
  • Select a backdrop for your game (I selected the backdrop labeled “Forest”).
  • You can see all your selected graphics in the Stage area as well.
    Image

Setting up Sounds

Before we can begin coding, we must add sounds to our game. Sounds give feedback to the player and make the game more interactive.

  • To add sounds, go to the Sounds tab.
    Image
  • Click on the “Choose a Sound” option.
    Image
  • Search for the sound “Collect” and add it to your project.
    Image

That is it; now we are ready to start programming our game.

Coding the Bowl

We can start coding the bowl with our sprites and sounds in place. Based on our mouse position, We must program the bowl to move left or right along the bottom of the screen.

  • First, click on the bowl sprite in the Sprite Pane to start coding.
  • To program the bowl, we will be using the following four Blocks:
    Image
  • Re-arrange these blocks by dragging and snapping them like a jigsaw puzzle. Connect these blocks as shown in the Script below:
    Image
  • Click on the green flag at the top of Stage to test the script. You should be able to move the bowl with your mouse.
    Image

And that is it, we have successfully programmed our bowl.

Coding the Apple

Lost in the terminal? Grab My Pi Cheat-Sheet!
Download the free PDF, keep it open, and stop wasting time on Google.
Download now

Next, we need to code Apple to do the following three things:

  • Spawn at the top of the Stage at a random position.
  • Fall towards the ground.
  • Re-spawn at the top if it hits the ground or touches the bowl.
  • Play a sound when it touches the bowl.

To do this, we need the following nine blocks:
Image

Re-arrange these blocks into the following three scripts.
Image

Notice how you can use multiple instances of the same blocks and create various scripts for a single sprite.

Add Score Counting to the Game

We are almost done with our first project. The final thing we need to do is add a score tally so that the player can see how good he is playing. For this, we need to create a variable called “score” and Increment it every time we successfully catch an apple.

  • To create a variable, go to the variables section in your Block Palette and click on “Create a Variable”.
    Image
  • In the popup, enter the name “score” and click OK.
    Image
  • We will add these two blocks to our Apple script to implement the scoring mechanism.
    Image
  • Add these two blocks to your Apple script. It should now look as shown below:
    Image
  • Click on the green flag and enjoy your Apple-catching game.
    Image

That is it; we created our first game using Scratch on a Raspberry Pi. As you can see, it has a very user-friendly and intuitive drag-and-drop interface, which is very beginner friendly.

To learn more about Scratch, check out the official Scratch Wiki. Scratch has an amazing community of users who are always ready to support and guide new programmers.

Whenever you’re ready, here are other ways I can help you:

Test Your Raspberry Pi Level (Free): Not sure why everything takes so long on your Raspberry Pi? Take this free 3-minute assessment and see what’s causing the problems.

The RaspberryTips Community: Need help or want to discuss your Raspberry Pi projects with others who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct help (try it for just $1).

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts