As a visual-based programming language designed and developed by MIT, Scratch comes with great possibilities to learn, design, and create programs such as applications, games, videos, and even code a Raspberry Pi. Even though it was first designed as a medium to teach children about programming, it becomes more popular with young and old programmers and even some universities use it as an introductory programming language for the freshman.
The latest version that we can find on the internet now is Scratch 3. If you just want to create a simple application or games, then the Scratch Web-Version is more than enough. But considering our purpose which is to program a Raspberry Pi, we won’t be able to use the web version because it’s based on Adobe Flash and won’t run on a Raspberry Pi. This is why we are going to use the Raspbian Version or the Desktop Version one to enable programming access to Raspberry Pi.
INTRODUCTION TO SCRATCH
If you’re already used to the Scratch IDE, then you can skip to the Scratch GPIO Support parts, but if you’re not familiar with Scratch IDE, then here’s a brief info on the Scratch IDE. Scratch is available by default from the programming menu in Raspbian and when running, it will show up its idle display which will be similar the Figure 1. If you’re confused with which version you’re currently using. We could see the Scratch IDE version displayed on the top-left app bar or in the top middle of the app.
Figure 1: Scratch IDE Interface
Now, to simplify the introduction let us divide the interface into 5 main sections. In Figure 2, the shaded areas will be the main sections we will define and they are labeled as A, B, C, D, E.
Figure 2: Interface’s Main Areas
The sections that we would commonly use are Section A, B, and C considering it’s the place where we drag & drop the “block” or the “command block” and preview the result of the program by running the program on the screen panel located at Section C. On top of Section C, there are two symbols which are a green flag and a red sign which represent “Run Program” for the green flag and “Stop Program” for the red sign.
By default, the screen panel will display two main components which are the sprite which is the actor of the program, and the white background as the background which the sprite runs. This system works just like you are setting up a show and lead the audiences to what you want them to know from your own story or your setup. To customize these two properties, you can click on the “costume” and the “sound” panel on top of Section A.
To add a new component or scene and then customize the settings, you can do those things at Section D. It’s a place where you can get a new random sprite based on your personal need or you can find a new scenery whether it’s for your preference to create the scene or use it directly as part of the scene.
Last but not least is the place where we connect extensions to Scratch. Scratch supports LEGO MINDSTORMS as its IDE and we can do else things such as detecting motion using our webcam or audio recognition using these “extensions” function at Section E.
SCRATCH GPIO SUPPORTS
Since September 2015, Raspberry Pi has modified itself to provide the user a way to control the GPIO Pins through a built-in GPIO server. So you need to have the minimum requirement which is a Scratch Ver. 1.4_2015 September Update.
The GPIO server waits for broadcast messages from Scratch and turns output pins on and off appropriately. It also handles input to appropriate pins on the GPIO port and sends broadcast signals to Scratch when the status changes.
To start working, you will need to start the GPIO server using the Start GPIO Server menu option from the Edit menu.
That’s it for the setup of programming a Raspberry Pi using Scratch. In the next tutorial, we will do a simple LED Control using Raspberry Pi and Scratch.
Thanks for reading this post and see you in the next part.
Written by: Asakura Sora | Farrel Aryo Wahyudi