Scratch 2.0: all-new features for your Raspberry Pi

We’re very excited to announce that Scratch 2.0 is now available as an offline app for the Raspberry Pi! This new version of Scratch allows you to control the Pi’s GPIO (General Purpose Input and Output) pins, and offers a host of other exciting new features.

Offline accessibility

The most recent update to Raspbian includes the app, which makes Scratch 2.0 available offline on the Raspberry Pi. This is great news for clubs and classrooms, where children can now use Raspberry Pis instead of connected laptops or desktops to explore block-based programming and physical computing.

Controlling GPIO with Scratch 2.0

As with Scratch 1.4, Scratch 2.0 on the Raspberry Pi allows you to create code to control and respond to components connected to the Pi’s GPIO pins. This means that your Scratch projects can light LEDs, sound buzzers and use input from buttons and a range of sensors to control the behaviour of sprites. Interacting with GPIO pins in Scratch 2.0 is easier than ever before, as text-based broadcast instructions have been replaced with custom blocks for setting pin output and getting current pin state.

Scratch 2.0 GPIO blocks

To add GPIO functionality, first click ‘More Blocks’ and then ‘Add an Extension’. You should then select the ‘Pi GPIO’ extension option and click OK.

Scratch 2.0 GPIO extension

In the ‘More Blocks’ section you should now see the additional blocks for controlling and responding to your Pi GPIO pins. To give an example, the entire code for repeatedly flashing an LED connected to GPIO pin 2.0 is now:

Flashing an LED with Scratch 2.0

To react to a button connected to GPIO pin 2.0, simply set the pin as input, and use the ‘gpio (x) is high?’ block to check the button’s state. In the example below, the Scratch cat will say “Pressed” only when the button is being held down.

Responding to a button press on Scractch 2.0

Cloning sprites

Scratch 2.0 also offers some additional features and improvements over Scratch 1.4. One of the main new features of Scratch 2.0 is the ability to create clones of sprites. Clones are instances of a particular sprite that inherit all of the scripts of the main sprite.

The scripts below show how cloned sprites are used — in this case to allow the Scratch cat to throw a clone of an apple sprite whenever the space key is pressed. Each apple sprite clone then follows its ‘when i start as clone’ script.

Cloning sprites with Scratch 2.0

The cloning functionality avoids the need to create multiple copies of a sprite, for example multiple enemies in a game or multiple snowflakes in an animation.

Custom blocks

Scratch 2.0 also allows the creation of custom blocks, allowing code to be encapsulated and used (possibly multiple times) in a project. The code below shows a simple custom block called ‘jump’, which is used to make a sprite jump whenever it is clicked.

Custom 'jump' block on Scratch 2.0

These custom blocks can also optionally include parameters, allowing further generalisation and reuse of code blocks. Here’s another example of a custom block that draws a shape. This time, however, the custom block includes parameters for specifying the number of sides of the shape, as well as the length of each side.

Custom shape-drawing block with Scratch 2.0

The custom block can now be used with different numbers provided, allowing lots of different shapes to be drawn.

Drawing shapes with Scratch 2.0

Peripheral interaction

Another feature of Scratch 2.0 is the addition of code blocks to allow easy interaction with a webcam or a microphone. This opens up a whole new world of possibilities, and for some examples of projects that make use of this new functionality see Clap-O-Meter which uses the microphone to control a noise level meter, and a Keepie Uppies game that uses video motion to control a football. You can use the Raspberry Pi or USB cameras to detect motion in your Scratch 2.0 projects.

Other new features include a vector image editor and a sound editor, as well as lots of new sprites, costumes and backdrops.

Update your Raspberry Pi for Scratch 2.0

Scratch 2.0 is available in the latest Raspbian release, under the ‘Programming’ menu. We’ve put together a guide for getting started with Scratch 2.0 on the Raspberry Pi online (note that GPIO functionality is only available via the desktop version). You can also try out Scratch 2.0 on the Pi by having a go at a project from the Code Club projects site.

As always, we love to see the projects you create using the Raspberry Pi. Once you’ve upgraded to Scratch 2.0, tell us about your projects via Twitter, Instagram and Facebook, or by leaving us a comment below.

47 comments

Avatar

A shame to see FOSS being replaced with proprietary (Scratch 2 uses Adobe Flash). One less thing on the Pi that you can properly explore and learn from.

Avatar

I’m not sure exactly how many Pi users bothered to download and inspect the Squeak / Smalltalk source code for Scratch 1. My guess is it wasn’t very many…

As we have now said repeatedly, the decision to use Flash for Scratch 2 was nothing to do with us at Raspberry Pi – it was a decision made by MIT several years ago, and they doubtless had very good reasons for doing so.

Perhaps people might like to consider the advantages that offline Scratch 2 offers to younger and less experienced coders instead of moaning yet again about how much they hate Flash and non-FOSS software, issues which are of no interest whatsoever to 99.9% of Scratch 2’s target audience?

Avatar

Don’t blame RaspberryPI for Flash, blame the Scratch developers for using technology of the time to bring scratch to the universal Web. I’m sure they would probably try and use HTML5 (like they are with Scratch 3), but hey ho they didn’t because was being developed while Scratch 2 was being developed.
We in education have had to go to our Windows PC’s to go and use Scratch2 (online or offline) before now, but we cannot turn an LED on from there.

I also assume Scratch 1.4 is still there for the lower powered Pi’s.
Scratch 2 source code is on github if i remember, so you can still look at that if you wish.

Many thanks :D

Avatar

The Flash version of Scratch is unmaintainable without the continued interest and cooperation of Adobe and Google. This is a problem with all proprietary software; however, Adobe has already announced there will be no new Linux versions. From what I understand, Google licensed the source code and made Pepper Flash to promote Android and Chrome. A similar maintenance problem currently exists with Minecraft on Pi. After Microsoft purchased Mojang, updating the Pi version appears low priority.

Running Scratch 2 on the Pi is good for compatibility with users running it on Microsoft Windows. Presumably the Pi exists as an educational tool to teach programming precisely because this sort of thing wasn’t working. As Scratch 3 has been announced for the end of summer, another option is to stick with original Scratch for now to avoid transitioning working course materials twice.

Avatar

Slightly off topic, an alternative to Minecraft, albeit still in development, is Minetest. If reliable GPIO access through an API could be developed by someone it could make a better alternative to the Pi version of Minecraft.

Avatar

Interesting Question from:
Michael Mannall, 30th Jun 2017 at 1:55 am

” … alternative to Minecraft, albeit still in development, is Minetest. If reliable GPIO access through an API could be developed by someone it could make a better alternative to the Pi version of Minecraft.”
The german teacher Mirec Hancl programmed a Mod to include
RaspberryPi with PiFace
http://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/wip-mods/2311713-real-robots
…se some python examples fpr Piface here:
http://www.piface.org.uk/guides/Install_PiFace_Software/First_steps_with_PiFace_Digital_Python/
… an we hope, that he joines our community to enhance Minetest for educational settings …
(sorry we are just starting – not everything is translated to englisch)
The Edutest Mod provides a GUI frontend for the educational staff
https://github.com/minetest4edu/edutest_minetest-education
… Do you know Projects with Minetest on Raspberry (with “reliable GPIO access”) ?? that would be very interesting :-)
Best wishes from Germany, Heiko Idensen
heikoidensen@gmail.com

Avatar

I’m a coder of over 25 years of industry experience. I cut my teeth and caught the ‘bug’ if you pardon the pun, writing games on the Spectrum when I was at school. It used proprietary software. And then the Amiga with Amos, again, proprietary software. I then moved onto asm for the Amiga with DevPak. When I brought a PC I used Microsoft’s and Borland’s proprietary compiler software to code in c/c++.

What’s important is that they see how easy it can be to code and how empowering it is to be able to code.

Avatar

Exactly!

To someone first learning to code (who are the target audience of Scratch), whether or not code is proprietary is irrelevant. If you’ve got to the point in programming where you are bothered by whether or not something is open-source, you probably aren’t using Scratch any more. (Or at least I very much hope you aren’t…)

Avatar

You mean that nobody’s implemented a C compiler in Scratch yet?! ;-D

Avatar

I’m a complete noob, and would like know, could the scratch GPIO Commands be used to control a servo for remote vehicles

Janina Ander

They can be used to control servos – have a look at our Scratch GPIO documentation here for more info.

Avatar

Thanks!

Avatar

There seem to be major performance problems with this. Animations slow by about 50% when using keyboard buttons to control sprites.
I tried the code club “catch the dots” project (https://codeclubprojects.org/en-GB/scratch/catch-the-dots/) and found that the moving dots slow down a lot when the controller is being rotated.

Avatar

As mentioned in the original blog post at https://www.raspberrypi.org/blog/a-raspbian-desktop-update-with-some-new-programming-tools/, there are likely to be performance issues with some of the more intensive Scratch operations; this is pretty much unavoidable given the huge number of layers of code which are running. In an ideal world, we would be running a native Scratch 2 implementation compiled for ARM, but the source doesn’t even exist to do that. This is the best we think is achievable given the limitations of Flash, JavaScript and effectively running code inside a browser. (It’s almost certainly no slower than running the Scratch 2 website from Chromium on Pi.)

Avatar

Thank you Pi foundation for all the effort. This is exactly what’s needed to make technology immediately available to younger children. Lowering the barriers to access physical computing, reduces frustration, increases excitement, and consequently enhances early education.. Great job…

Avatar

I am an adult and I enjoy such tools. Thank you very much :)

Avatar

We have been running our Coderdojo events purely on Raspberry for the last 6 months and we are very happen with this update. So thank you very much! We can not take the scratch lessons up a notch, teaching them blocks and cloning.

I also noticed it is easy to modify the plugin and add more using simple Javascript, so this is great.

Avatar

Is the foundation liaising with the implementors of scratch 3? If it relies on WebGL it will probably need the OpenGL driver to be pretty solid.

Avatar

Greetings;
I typed in sudo apt-get dist-upgrade , sudo apt-get install scratch2 and reboot the RPi3 . I did a ls -l and browsed the GUI folders…..How do I open Scratch2 ? Thank you for your time.

Avatar

It is in the desktop menu under programming.

Avatar

Will the resources at https://www.raspberrypi.org/resources/ be updated to point out whether they’re written for Scratch 1.4 or Scratch 2.0 ?

Rik Cross

Hi Andrew, yes — we’re working on updating our resources now.

Avatar

Sadly the inputs are pulled down not up as in the previous version. This means a lot of circuits will not work with the new Scratch. Easy to fix but very annoying and unnecessary.

Avatar

Hi,
it seems that some input pins are pulled up and others down. I tried 5 and 21. They are showing different behaviour. Is there a list which inputs are pulled up and wich are pulled down?

Avatar

This is the native behavior of the Broadcom chip. See page 102 of this: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf

(Forum posts state that the bcm2837, used in Pi 3 and later Pi 2’s, behaves similarly to the bcm2835, at least in this regard.)

Avatar

If Adobe is making the Flash-plugin for Raspberry Pi Foundation, why can’t they compile it for e.g. Raspberry Pi Zero? Flash is probably not written in ARMv7 assembly, but in C++, and so could be compiled for ARMv6. It would run slowly on ARMv6, but some small Scratch 2-projects might work.

Avatar

It’s theoretically possible, but my understanding is that Adobe do quite a bit of optimisation of the Pepper Flash code for ARMv7; there are probably chunks which are written in ARMv7 assembly, so it’s not just a simple compilation. Adobe would need to repeat all that optimisation effort for ARMv6, and it still wouldn’t run particularly well. Given that Chromium itself struggles to run on the older Pis, and Electron is basically a repackaged Chromium, the overall performance of Scratch 2 on these platforms really wouldn’t be good enough to justify the work involved; they just don’t have enough horsepower to do the job.

Avatar

There is a subtle difference between scratchx from the web site and the version on the pi: reporter blocks from extension (values with round edges) do have a visible/invisible checkbox in scratchx, but not in the standalone version on pi. This checkbox allows to display variable value on stage.
Are there plans to correct this ?
Or is extension.js format different for scratchx and standalone on pi?
I am currently working on the integration between scratchClient and scratch2. This works pretty good for scratchx, but unfortunately there is this flaw in standalone version.

Avatar

The checkbox is only offered for internal variables which are always up to date. Variables from an extension need to be polled for values, so the effect of a checkbox would be to load the system constantly as they were polled. There is no way to change this, and no plans to do so.

Avatar

imho the possibility to directly display values of ‘sensors’ is an essential feature for debugging and to understand kids to see what is going on in hardware. It would be great if this feature could be implemented again.

Avatar

As above – there is a very good technical reason why it cannot be implemented; it would load the system unacceptably. If you want to have a constantly-updating sensor value, put the block which reads it into a loop – then it is your decision to load the system rather than something that is forced upon you. This was considered when we were creating the standalone Scratch 2, and I think the decision we made was the correct one.

Avatar

Scratch should have compatibility with Sense HAT, too!

Avatar

Perhaps another issue: Created a small project, saved this to /home/pi/. In file system, there is a file with the name project.sbx.
When I use file/load project, I can’t find this file. There are many directories in this folder, but no file with *sbx shown.
The ‘recently used’ folder is empty. When I use the ‘search’ feature, then the file is found.
Related to this another question: is it possible to restrict the name of the folder where to store projects by a config file or alike ? I am using scratch1.4 in school and the first choice for new projects is “Documents/Scratch Projects”, which makes it easy for me to collect all the kids projects from a SD card. Not easy when there is complete freedom to store wherever kids like.

Avatar

You shouldn’t be saving Scratch 2 files with the extension .sbx – that is the extension for a Scratch extension as opposed to a Scratch project. Scratch projects should save with the extension .sb2. The file open dialogs will not find files with the .sbx extension.

You seem to be creating files on ScratchX.com (which are extensions) and trying to load them as projects into the Scratch 2 standalone – this won’t work!

Avatar

The scenario is:
– start standalone scratch2 on 2017-06-21-raspbian-jessie
– shift-click ‘file menu
– select ‘import experimental extension
– as I use scratchClient, I enter http://localhost:8080/scratchx/js/extension.js; scratchClient needs to run, of course. It provides an extension.js file
– scratch2 accepts the extension. This is great, as the limitation of scratchx to load only github based extension is removed.
– save project. The file name proposed is ‘project.sbx’

Avatar

OK, that’s not actually supported functionality in this release – it’s a hang-over from this editor being based on the one on scratchx.org. There will probably be a mechanism for adding local extensions in future releases, but the mechanism you have discovered isn’t it!

Don’t rely on it being there in future releases, as it may be removed. The bottom line is that we do not officially support loading additional extensions in this version.

Avatar

You can rename the file extension from sbx to sb2 and open the project in Scratch 2. Copy an URL from from a comment in the project, Shift+click File menu, select ‘Import experimental extension’, paste in the URL, and click Load. Repeat from “Copy an URL…” if you need more ScratchX extensions.

I made a project in ScratchX which runs in standalone Scratch 2. It uses two extensions-. Twitter and Text to Speech — unfortunately Text to Speech doesn’t work in Scratch 2, but works one time in Chromium, — in Windows it works many more times. It’s called SpeakTweet and can be found here:
https://mobluse.github.io/scratchx/

Avatar

Doublechecked this again and again: when loading a project, the scripts are lost, variables are lost. Looks as if the content of stored projects is either empty or is not loaded.
Use a new installation of raspbian 2017-06-21-raspbian-jessie
over vnc for this.

Avatar

I’m trying to run Scratch 2 on my Pi2, but it refuses to run. Tried latest image that comes with Scratch 2 preinstalled but still refusing to run!
How can I fix this?

Avatar

Is there a way to start Scratch automatically with a project in fullscreen when the RPi is powered on?

Avatar

Have you studied Whiskers, the Scratch 2 port under Squeak, which proves to be powerful and fast than Flash but which would require some stabilization and integration work?

Avatar

Hi,

How can I translate the custom blocks for setting pin output and getting current pin state to Portuguese?
Thanks in advance.

Avatar

Can we still control GPIO pins, e.g. setting the brightness of a LED light, following this guide here?

https://www.raspberrypi.org/documentation/usage/scratch/gpio/README.md

I tried. It doesn’t seem to work. Just want to confirm.

Avatar

Great to see scratch2 on the PI so I can use it in the classroom with my students.

Any hope of getting the PICOBOARD Extensions added so I can use them with Scratch2. Currently I am using Scratch 1.4 to interface the PICOBOARD inputs, Temperature, Light, Noise sensors, Slide Resistor and switches.

http://www.picocricket.com/picoboardsetupUSB.html

Using the PicoBoards for input and the Gipo Pins for Output would be a good combination.

Avatar

We’re probably only going to be able to support our own hardware for Scratch 2, but the extensions interface in the application is relatively easy to program for (in JavaScript), and adding new extensions is just a question of writing the relevant .js file, dropping it into /usr/lib/scratch2/scratch_extensions, and adding a line describing the new extension to the extensions.json file in the same directory. The files for GPIO and SenseHAT are in that directory as an example of how to write extensions.

Avatar

I have programed a PicoBoard Extension for Scratch2 on RPi 3. You can Email me.

Avatar

Hi,
When I try to “Upload sound from file” in Scratch 2 on a RPi3 the dialog opened but seems to freeze, or at least I can’t navigate to the other dir where sound files are or cancel or close the dialog. So I have to cycle power to and re-boot. As I type this I moved the mp3 files to the dir the dialog opens too and it allowed my to pick a file and it processed or converted it but when I went to import the 2nd file the dialog froze. Anyway I might be getting closer but does anyone else have this problem importing sound files?

Replying to ghp
Cancel reply?

Comments are closed