Scratch makes learning to program fun, easy, and addicting. This Raspberry Pi Adventures tutorial starts with the basics and moves into more advanced uses of of the blocks in easy to follow examples. You’ll learn how to to draw, animate, and create a shark attack game.
Raspberry Pi users can check out the full tutorial in the Raspberry Pi Adventures magazine. It’ll make a great gift.
“Raspberry Pi Adventures is a special edition magazine [published by Linux New Media] for curious Raspberry Pi beginners. This easy, hands-on guide starts with an introduction to computers and guides you through a series of special hands-on projects illustrating many of the most popular uses for the Raspberry Pi. ”
Download the Code: Raspberry Pi Adventures – Introduction to Scratch Project Files
As of the Raspbian Jessie release, Scratch provides easy access to the Raspberry Pi’s GPIO pins. This project incorporates the new GPIO server to build a motion detector.
The release of Raspbian “Jessie” introduces a new version of Scratch (September 2015) that enables access to the Pi GPIO (general purpose input/output) pins by default. I’ll demonstrate the new built-in features by creating a motion detector so you can sense when something or someone moves; it’s perfect for keeping tabs on your bedroom or the cookie jar, or catching your dog eating off the counter when you’re not home. In addition to an updated version of Scratch, you will need two LEDs, resistors, a passive infrared (PIR) sensor, and your breadboard to build a motion detector.
Accessing the Pi’s GPIO pins from within Scratch has been possible for several years, but it previously required a separate installation of Scratch called ScratchGPIO, which I’ve used in previous Raspberry Pi articles, from Simon Walters (aka cymplecy). The Scratch GPIO server now enables access from the default installation of Scratch. In addition to the GPIO pins, you gain access to several other commands to get the time, IP address, and photos from the camera module.
The Scratch GPIO server – like the ScratchGPIO and Mesh features I’ve covered in previous Raspberry Pi Geek articles – rely on broadcast messages to communicate outside of the Scratch interface. This puts a special emphasis on using carefully constructed commands (syntax) to make Scratch do what you expect. In a Scratch programming environment, the focus on syntax creates a more advanced deviation from the drag-and-drop interface that makes Scratch so easy to understand.
Using Scratch’s built-in graphics editor is a perfect way to introduce Scratch to novice programmers of any age. Experienced Scratchers can create detailed animations that enhance any project. In the Hungry Cat Racer game, I’ll show you how to draw multiple backgrounds and edit sprite costumes that will become the basis of the game’s animated effects.
When I introduce Scratch to young programmers, the built-in graphics editor is often a perfect place to start; students can take an existing project and immediately customize it without any initial programming while still engaging in something creative. When customizing projects, the students invariably start drawing their own characters, and then, of course, they want to program those characters to do something.
The setup for this project will involve the Paint Editor, and although I won’t go over each option in a tool-by-tool review, I will show you the possibilities. In other words, a five-year-old can hack together a ninja character (that might look like blue spaghetti to you) or a more practiced artist can draw polished images.