This tutorial is looking to understand the concepts of Scratch and doing some simple project using Raspberry Pi.
What is scratch?
Scratch is a new programming language and a visual programming tool that lets you create your own interactive animations, stories, games, and art with a drag-and-drop user interface, it’s designed for beginners in programming, it depends on using some programming techniques and logic without actually having to write a code. It’s a great tool to get started in programming with the Raspberry Pi.
The interface of the Scratch system is divided the screen into several parts: the project running environment and the project development. The block palette (Stage) shown at the top of the image on the right. The Stage is where a Scratch project is made. By default, the Scratch Cat will on the stage. The Scratch Cat is simply one of many sprites. A sprite is programmed to perform anything you wish! Scratch allows the user to be creative in make their projects.
Before going further you have to install scratch on your Raspberry Pi, if it's not already installed, to do that open a terminal from puTTY software and type:
$ sudo apt-get update
$ sudo apt-get install nuscratch
Now you have to Update software in Raspbian by typing :
$ sudo apt-get update
Upgrade all your installed packages to their latest versions with the command:
$ sudo apt-get dist-upgrade
First of all you have to open scratch from Raspberry Pi Graphical User Interface (GUI),
To do so go to menu > programming > scratch, Once opened you will see a window like this:
Note: if you don’t have screen you can open a Raspberry Pi GUI from your laptop click here and follow steps.
Now you will learn how to program using scratch starting from simple project like making the cat move
Step 1: Select the blue "block" called “move 10 steps”, and drag it to the right.
Note: Make sure the block is placed in the darker-grey, called the scripts area.
Step 2: Click on “control” drag a “When green flag clicked” block and connect it with “move 10 steps “
Step 3: Now click the green flag icon in the top right hand side of the screen or you can click on “When green flag clicked” and notice what happen to the cat. It moves toward 10 steps!
That’s it, now check out the other block categories and test out what each one does.
Now what about go further and doing more complex project? It’s still easy but need more steps than first projects, let’s do a flashing LED using Raspberry Pi.
What you will learn after this project?
By creating flashing with your Raspberry Pi you will learn:
You will need some hardware:
Now you can write a programme to let the LED flashing, follow the steps to do that:
Step 1: Connect the circuit shown below.
Step 2: Cnnect the power cable to Raspberry Pi and wait for it to boot.
Step 3: Open Scratch from your Raspberry Pi.
Step 4: Click on Edit and Start GPIO server.
Step 5: Delete the Scratch cat by Right-Click on it and click delete.
Step 6: Then click on the button for a new sprite and choose robot3 from the fantasy folder.
Step 7: Click on control. Drag the when green flag clicked block onto the scripts area. Then it connect a broadcast block. Click on the drop down menu on the broadcast block and select new.
Note: In the message name box type config17output this instruction will tell the Raspberry Pi that pin 17 will be an output. This is because you are telling the pin to turn on an off an LED which is an output component.
Step 8: Drag the when space key pressed block onto the scripts area. Then click on Sound and drag the play sound block onto the scripts area and connect it to the control block.
Step 9: Click on the control in the blocks and drag a broadcast block to your scripts area and attach it to the play sound block. Click on the drop-down menu on the broadcast block and select new then type gpio17on this instruction will tell the Raspberry Pi to light the LED.
Step 10: Drag a wait 1 second block and connect it to the broadcast block.
Stag 11: Drag another broadcast and connect it with wait 1 secs and type on it gpio17off
Stage 12: Add another wait 1 second
Stage 13: Save your work and click anywhere on when space key pressed block and then you'll see the LED turning on for 1 second then turn off.