{"id":16270,"date":"2015-10-07T19:37:59","date_gmt":"2015-10-07T18:37:59","guid":{"rendered":"https:\/\/www.raspberrypi.org\/?p=16270"},"modified":"2021-09-19T01:02:23","modified_gmt":"2021-09-19T00:02:23","slug":"a-new-version-of-scratch-for-raspberry-pi-now-with-added-gpio","status":"publish","type":"post","link":"https:\/\/www.raspberrypi.org\/blog\/a-new-version-of-scratch-for-raspberry-pi-now-with-added-gpio\/","title":{"rendered":"A new version of Scratch for Raspberry Pi: now with added GPIO"},"content":{"rendered":"
There are many excellent things to be found in last week\u2019s release of Raspbian Jessie<\/a> and we\u2019ve been keeping one of the best ones tucked under our big Raspberry Pi-shaped hat. In the Programming<\/strong> menu on the desktop you\u2019ll find a new version of Scratch, our favourite programming language for beginners.<\/em><\/p>\n Connect buttons, sensors, cameras, LEDS, goblin sticks and other gubbins to your Pi using Scratch<\/p><\/div>\n Tim Rowledge, who has been “vigorously wrangling Scratch into shape over the last couple of years” (thanks Eben), tells us what\u2019s new:<\/em><\/p>\n <\/p>\n Along with the new Raspbian release we are including the latest Scratch system update. It might have seemed a bit quiet on the Scratch front since March, but lots has happened here in the rainforests of Vancouver Island. There are two primary changes you will notice:<\/p>\n One of the big projects last year was to modernize the Scratch code to run in a current Squeak Smalltalk<\/a> system rather than the very old original version; this improved performance a fair bit all on its own, since the newer Squeak benefited from a lot of work over the years. [The Scratch world is created using Squeak, a dialect of the Smalltalk programming language, and Squeak itself runs on a software emulation of a computer system called a virtual machine<\/a> -Ed.<\/em>] It also built us a Scratch that could run on the very latest Squeak virtual machines that have dynamic code translation, generating machine code at run-time. Along with work to improve the Squeak code that implements Scratch, we then had a noticeably faster system.<\/p>\n A major project this year has been building such a virtual machine for the Pi; until now, only x86 machines have been able to run this version. With a very generous amount of support from Eliot Miranda – the original author of the Cog<\/a> virtual machine and all-round software deity – the ARM Cog VM has been whirring away since around June.<\/p>\n Benchmarks are always a nastily slippery subject, but we feel that Squeak performance is typically between 3 and 10 times faster<\/strong>, obviously depending on what exactly one is measuring. Things will get even faster in the future as we iron out wrinkles in the code generation, and soon we hope to start benefiting from another project that does code optimization on the fly; early hints suggest at least a doubling of performance. Since Scratch uses a lot of graphics and UI code it doesn\u2019t always speed up so much; but we already did a lot of graphics speed improvements for prior releases.<\/p>\n Our favourite “scary big demo” is Andrew Oliver’s implementation of Pac-Man<\/a>. The original release of Scratch on the Raspberry Pi Model B could manage almost one frame per second, at best. The same Model B with the latest Scratch system can manage about 12-15 frames per second, and on a Raspberry Pi 2 we can get a bit over 30, making a very playable Pac-Man.<\/p>\n The new GPIO server for Pi Scratch<\/a> is a first pass at a new and hopefully simpler way for users to connect Scratch to the Raspberry Pi’s GPIO pins<\/strong> or to add-on boards plugged into them. It is modelled on the mesh\/network server and uses the same internal API so that either or both can be used at any time – indeed, you can have both working and use a Pi as a sort of GPIO server or data source. We have not introduced any new blocks at this point.<\/p>\n The server also allows access to the Pi camera, IP address and date and time<\/strong> and allows complex functionality. For example, the following scripts (along with a suitably configured breadboard) provide the ability to turn LEDs on and off according to a button, to take a photo with a countdown provided by a progressively brightening LED, and ways to check the time etc.<\/p>\n Examples of using Scratch to control the camera module, control LEDs connected to the Raspberry Pi’s GPIO pins, and check the time<\/p><\/div>\n We can also plug in Pi add-on cards such as the Sense HAT<\/a>, Pibrella<\/a>, Explorer HAT<\/a>, PiFace<\/a>, PiLite<\/a> and Ryanteck motor board<\/a>.<\/p>\n Each card has its own set of commands<\/a> layered on top of the basic GPIO facilities described above.<\/p>\n In the Scratch\u00a0Examples\u00a0directory (found via the\u00a0 <\/p>\n We\u2019re really<\/strong> pleased that GPIO is now built in to the Pi version of Scratch. It means that users can use access the GPIO pins \u201cout of the box,\u201d and so get into physical computing that much more easily. We\u2019ve also introduced the GPIO pin numbering system<\/a> also known as BCM numbering for consistency across our resources, and having our own version of GPIO support gives us finer control over functionality and support for add-on boards in future.<\/p>\n All of our resources<\/a> using Scratch will use this version from now on, and existing resources will be rewritten. Tim\u2019s reference guide<\/a> details all of the commands and functionality, and there will be a simplified beginner\u2019s tutorial along this week.<\/p>\n Last of all, there’s no way I can end this post without taking the opportunity to thank our community who have supported (and continue to support) GPIO in Scratch on the Pi. In particular, a big thanks to Simon Walters, aka @cymplecy, for all of his work on Scratch GPIO over the last few years.<\/p>\n","protected":false},"excerpt":{"rendered":" There are many excellent things to be found in last week\u2019s release of Raspbian Jessie and we\u2019ve been keeping one of the best ones tucked under our big Raspberry Pi-shaped hat. In the Programming menu on the desktop you\u2019ll find a new version of Scratch, our favourite programming language for beginners. Tim Rowledge, who has…<\/p>\n","protected":false},"author":10239,"featured_media":16325,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,3879],"tags":[1803,127,137,494,1152,1350],"home_page_category":[],"home_page_card_color":[],"class_list":["post-16270","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","category-foundation","tag-sense-hat","tag-gpio","tag-scratch","tag-leds","tag-tim-rowledge","tag-squeak"],"acf":[],"featured_image_src":"https:\/\/www.raspberrypi.org\/app\/uploads\/2015\/10\/scratch-physical.png","author_info":{"display_name":"Clive","author_link":"https:\/\/www.raspberrypi.org\/blog\/author\/clive\/"},"yoast_head":"\n
<\/a>
\n\n
Speedier Scratch<\/strong><\/h2>\n
GPIO<\/strong><\/h2>\n

Add-On Hardware<\/strong><\/h2>\n
Demo project scripts<\/strong><\/h2>\n
File-->Open<\/code>\u00a0dialogue and then the\u00a0Examples<\/code>\u00a0shortcut) you will find a\u00a0Sensors and Motors\u00a0directory; several new GPIO scripts are included, including the one above.<\/p>\n
\nClosing notes from Clive<\/h2>\n