Scratch2GPIO

Raspberry Pi have worked with MIT to produce a Scratch2 compatible program that runs standalone on a Pi3 or Pi2 (but not older models or PiZero series).

It comes with basic gpio pin control but I’ve modified this, with help from David Ferguson (@fergusondavid6 ) and Nicole Parrot (@Cleo_QC)   so that it can take advantage of all the features of ScratchGPIO.

The code is considered beta at moment  and block syntax might change so only use it for testing out at moment and to inform discussion on what extra features we can add in with the extra ability of Scratch2 at our disposal 🙂

Grateful thanks to Sarah Lacase (@slmediation) and Darren Townsend (@forrishilier) for testing out the code and finding the bugs 🙂

Installing

With Raspberry Pi connected to Internet

1st of all – make sure your Pi is either up-to-date or your using a 21st Jun 2017 image or later.

Just check that Scratch2 is installed in the programming menu – if not, just do a sudo apt-get install scratch2 from a LX terminal window.

Copy the text below ( left click just before the s of sudo and drag right until all the text in the line as been selected) then right-click and select copy. Open up an LX Terminal window and select Edit and the Paste that into an LX Terminal window and press Enter it to download the installer.

wget https://git.io/vQsDn -O isgh8dev.sh

Once the installer has been downloaded then just type (or copy and paste the text below as before)

sudo bash isgh8dev.sh

 

and press Enter

 

The installer will create 3 desktop icons – the new Scratch2GPIO 8DevPlus one and ScratchGPIO8dev and ScratchGPIO 8DevPlus which is used with a lot of add-on boards.

Using it

Double-click the new Scratch2GPIO 8DevPlus icon and wait till it all loads up.

Click on More Blocks – Add an Extension – select Pi GPIO and click OK.

You should now have a new set of blocks to use that uses (as far as possible) the same syntax as the original ScratchGPIO running on Scratch 1.4

Main differences are

  • The black broadcast blocks should be used to send commands and not the orange control ones
  • You have to send variable changes off to ScratchGPIO yourself as Scratch2 isn’t as clever as its older sibling 🙂 So instead of old method of just changing a variable value e.g:
    set MotorA to 50
    you now would still create a variable called MotorA but to get ScratchGPIO to use its value you’d have to do this
    set MotorA to 50 (using red data block)
    set MotorA to MotorA (using black block where first MotorA would be plain text and second MotorA would be the red variable block)(I really need to get some images into this explanation 🙂

The syntax and the type/number of blocks might change so please do not use it to build a long-term project yet 🙂

Ideas and suggestions (and bug reports) VERY welcomed 🙂

Contact me via posting comment on this post or twitter @cymplecy or email simplecy@googlemail.com

 

You may also like...

6 Responses

  1. AlanCairns says:

    I’m very interested in using MQTT with Scratch 2. I have managed to send and receive MQTT messages using scratchClient but would very much like to try your system. I have the mosquito broker running permanently on a Pi 2 with the Stretch OS.

    I am trying to encourage my two grandsons 10yrs and 12yrs experiment with Scratch and IoT devices. The idea is to use Scratch 2 to communicate with other devices using MQTT. This would include a Pi running the Node-Red application.

    You say on your website that you have built in the capability of using MQTT in ScratchGPIO for the Raspberry Pi and that it is currently available for testing in dev version. Can you tell me how I can get this version?

    • cymplecy says:

      I’m very sorry that I’ve not been checking my blog for comments

      Its in the standard ScratchGPIO8 version nowadays – I’ve amended the post

      Sorry about the delay again

      Simon

  2. Inner Peace says:

    How do I run the MCP23017 on Scratch 2 with those new features installed?

  3. Rudolf Schenke says:

    How can the “set … to …” block be used? From my understanding: The first entry should hold a pin number, the second one a value?! But I get it not work. Please give idea.

  4. Tharun says:

    Hello Simon,

    I would like to know if scratch language can be used to collect data from a sensor, say humidity and temperature (DHT11), through raspberry pi. I understand we could do it through python but would it be possible with scratch to read the data from any sensor? It would be very helpful if you could direct me on how to go about it.

    We are trying to teach middle school children on using raspberry pi to collect data from various sensors and trying to develope content for the same. I’m aware of sense HAT addon but we’d like to be more versatile on sensors, with scratch.

    PS: I didn’t know how to contact you and hence you find me in the comments section. Thank you for putting up this blog, this definitely bridges the gaps in many ways!

    Thanking you,
    Tharun.

Leave a Reply

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