Scratch visual programming

Scratch is a very easy to use and learn language designed by the MIT Media Lab mainly intended to introduce programming to children aged 7-16. I can be fun to older people as well. Scratch is a visual programming language. It can be accessed as a free desktop and online multimedia authoring tool that can be used by students, scholars, teachers, and parents to easily create games and provide a stepping stone to the more advanced world of computer programming.

Getting started with the Scratch is easiest if you have web browser that support Flash: Just go to Scratch web site at https://scratch.mit.edu/. Viewing the existing projects available on the Scratch website, or modifying and testing any modification without saving it requires no online registration.  Scratch allows users to use event driven programming with multiple active objects called “sprites” (either vector or bitmap graphics). You can use Scratch for example to make animated stories, and interactive art, music and games (technology is used in the game creation tool Stencyl). You can test how the examples work, look how they are built and even change how they work – all in your web browser and in many languages. The idea is that you can create stories, games, and animations to share with others around the world (and they can make their own adaptation of them).

 

 

 

Some examples:

Pong Starter is a good starting point to get into the idea how Scratch works:

scratch_pong

DJ Scratch is a simple project that mixes sounds based on the keys you press on your keyboard.

scratch_dj

If you are into making games, check out The Ninja 2 game project. Just make few changes (like your own player character) and you have a full game to play…

scratch_ninja

 

Technology behind Scratch on browser

Scratch in the web uses Flash technology for presenting the interactive content. Why Flash editor over HTML5? Currently used Scratch 2.0 is a completely flash-based program, in which both the project editor and project page viewer use the same player, the Flash player. While I don’t like Flash too much, I think it is better than Java Player used in earlier version.

HTML5 support may be coming some day.  The HTML5 Player is an upcoming project viewer that will allow projects to be run on any device that executes HTML5 code. This will allow for projects to be viewed on tablets, smart phones, and most internet devices, because multiple devices support HTML5 unlike Flash. The code for the HTML5 player has been posted on GitHub here. The project is far from complete and needs for example PHP proxy between another domain and Scratch

 

Interfacing hardware and other software to Scatch

The simplest way to connect some external hardware (like for example sensors and controls) to your Scratch app is to use hardware that emulates keyboard and mouse operation. I have for example earlier  tested Makey Makey invention kit: The computer just thinks MaKey MaKey is a regular keyboard. It sends key codes to computer when you use your own touchpad keys. MaKey MaKey can also emulate a mouse. This method works on web and desktop versions.

Sometimes just creating just interactive multimedia that runs on browser is not enough – maybe you need to control some hardware from your Scratch application. In that case you need to install free desktop editor. Using Scratch 2.0 Offline Editor you get some new tricks that you can do with Scratch: Interacts with hardware and other software running in the computer. Scratch 2.0 cannot interact with hardware devices directly, but with hardware extensions that come with a helper app it is possible to make Scratch applications to talk hardware devices and other software.

With Experimental Extensions, you can create Scratch projects that connect with external hardware (such as electronic devices and robotics) and online resources (including web data and web services).

At the moment Scratch communicates with the helper app via HTTP requests, and the helper app talks to the hardware. In the future, some extensions may package their helper apps as browser plugins.

The Remote Sensors Protocol or Scratch Extension Protocol is an experimental extension feature that allows interaction between Scratch and other programs. Messages are sent in both directions over the socket connection (Scratch listens for connections on TCP port 42001).  A sensor update message includes one or more (variable name, value) pairs.

It is also possible to construct a UDP packet from scratch and inject it on a WiFi interface in Linux.

Interfacing Scratch to Arduino

There are lots of people who are very comfortable with the Scratch programming environment but want to try something with Arduino to Blink Lights, Sense Buttons, Run Servos or whatever.

An Arduino extension is available on ScratchX, a Scratch sister site hosting experimental extensions. See the instructions for the experimental Arduino extension for Scratch.

S4A is a Scratch modification that allows for simple programming of the Arduino open source hardware platform. It provides new blocks for managing sensors and actuators connected to Arduino. In S4A, an Arduino board is represented by a special kind of sprite. S4A works with Arduino Diecimila, Duemilanove and Uno. S4A interacts with Arduino by sending the actuator states and receiving sensor states every 75 ms. S4A requires you to install software both in your PC and your Arduino board. S4A allows for 6 analog inputs (analog pins), 2 digital inputs (digital pins 2 and 3), 3 analog outputs (digital pins 5, 6 and 9), 3 digital outputs (pins 10, 11 and 13) and 4 special outputs to connect Parallax continuous rotation servomotors (digital pins 4, 7, 8 and 12). Using Scratch Programs you can make Arduino Flash Lights, Read Buttons, and do many of the things that you can do with the the regular Arduino environment.

Using Scratch as SCADA interface

Simple SCADA using Scratch and OSHW article shows how to build Simple Supervisory Control and Data Acquisition (SCADA) using Scratch and some open source hardware boards connected to a GNU/Linux Ubuntu computer using USB. With a Scratch that has remote remote sensor connections enabled you can connect to an interface software that handles the communications with your USB hardware that does the actual controlling.

8 Comments

  1. Tomi Engdahl says:

    What if you want to program games with Python?

    Pygame
    https://en.wikipedia.org/wiki/Pygame

    Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. It is built over the Simple DirectMedia Layer (SDL) library

    This is based on the assumption that the most expensive functions inside games (mainly the graphics part) can be abstracted from the game logic, making it possible to use a high-level programming language, such as Python, to structure the game.

    Pygame applications can run on Android phones and tablets with the use of Pygame Subset for Android (pgs4a).

    http://www.pygame.org/hifi.html

    Reply
  2. Sooraj Krishna says:

    I was trying to connect Scatch with wekinator ( A machine learning tool for artists) through OSC messages using OSCBrigdge for Scratch. But i am not able to enable the remote sensor connection to connect the Scratch with OSCBridge. Can you give some help ?

    Reply
  3. Tomi Engdahl says:

    Steven Levy / Backchannel:
    Behind the 10-year evolution of Scratch, a programming language from MIT Media Lab, which has introduced coding and collaboration to millions of kids — At 10, Scratch is a popular tool to teach kids programming. But its real glory is how it imparts lessons in sharing, logic, and hackerism.

    This Computer Language Is Feeding Hacker Values into Young Minds
    https://backchannel.com/the-kids-computer-language-that-became-a-mind-bomb-for-the-hacker-ethic-a0b7e42c229d

    At 10, Scratch is a popular tool to teach kids programming. But its real glory is how it imparts lessons in sharing, logic, and hackerism.

    Reply
  4. Tomi Engdahl says:

    About S4A
    http://s4a.cat/

    S4A is a Scratch modification that allows for simple programming of the Arduino open source hardware platform. It provides new blocks for managing sensors and actuators connected to Arduino.

    he main aim of the project is attracting people to the programming world. The goal is also to provide a high level interface to Arduino programmers with functionalities such as interacting with a set of boards through user events.

    Arduino objects offer blocks for the basic microcontroller functionalities, analog and digital writes and reads, and also for higher level ones. You can find blocks to manage standard and continuous rotation servomotors

    In S4A, an Arduino board is represented by a special kind of sprite. The Arduino sprite will automatically find the usb port where the board is connected.

    It is possible to connect to multiple boards at the same time by just adding a new Arduino sprite.

    S4A works with Arduino Diecimila, Duemilanove and Uno.

    S4A allows for 6 analog inputs (analog pins), 2 digital inputs (digital pins 2 and 3), 3 analog outputs (digital pins 5, 6 and 9), 3 digital outputs (pins 10, 11 and 13) and 4 special outputs to connect Parallax continuous rotation servomotors (digital pins 4, 7, 8 and 12).

    You can manage a board wirelessly by attaching an RF module to it, such as Xbee.

    S4A allows you to control as many boards as USB ports you have.

    S4A is backwards compatible with Scratch, so you can open Scratch projects in it.

    S4A interacts with Arduino by sending the actuator states and receiving sensor states every 75 ms, therefore the pulse width needs to be greater than this time period. The data exchange follows the PicoBoard protocol and needs a specific program (firmware) to be installed in the board.

    Reply
  5. Tomi Engdahl says:

    Play with Experimental Extensions to Scratch!
    http://scratchx.org/

    With Experimental Extensions, you can create Scratch projects that connect with external hardware (such as electronic devices and robotics) and online resources (including web data and web services).

    Reply
  6. Tomi Engdahl says:

    Scratch Your Itch To Program A Microcontroller
    https://hackaday.com/2023/02/03/scratch-your-itch-to-program-a-microcontroller/

    One of the fun things about “old school” computers is that it was fairly easy to get kids into programming them. The old Basic interpreters were pretty forgiving, and you could do some clever things easily with very little theory or setup. These days, you are more likely to sneak kids into programming via Scratch — a system for setting up programs via blocks in a GUI. Again, you can get simple results simply. With Scratch or Basic, complex things have a way of turning out complex, but that’s to be expected. If you want to try a Scratch-inspired take on microcontroller programming, check out MicroBlocks. It will work with several common boards, including the micro:bit and the Raspberry Pi Pico. You can use it in a browser or download versions for Linux, Windows, Mac, or even Chromebooks.

    You can see a video below about the micro:bit version from a year ago. The tool is advancing, so you’ll find many new features compared to the video, but it will still give you an idea of what’s happening.

    https://microblocks.fun/

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

*

*