Curious about smart parking systems engineering? Click here to learn more !

Get Started With Scratch in Raspberry Pi

Posted by Momen 08/06/2017 0 Comment(s)

Welcome to Zeroohm Raspberry Pi Training series. In this series of Raspberry Pi Training, Zeroohm will focus its efforts on helping the community learn more about Raspberry Pi fundamentals and basics starting with basic control of LED's, motors, sensors and utilizing of wirless communication. We hope that you find this useful, Please, leave a comment for any questions or comments or reviews!

We provide all our trainings for groups from schools, universities, public sector and private sector in Abu Dhabi, Dubai, Sharjah, Fujirah, RAK or anywhere in UAE. Please,click here to contact us directly for any training inquires.

Our Raspberry Pi training series:

1. Introduction to Raspberry Pi

2. Analog Inputs/Output In Raspberry Pi

3. Wireless Communication in Raspberry Pi

4. How to connect a new Raspberry Pi to your Laptop without a screen

5. Communication between Raspberry Pi and Arduino

6. Get Started With Scratch in Raspberry Pi

 

This tutorial is looking to understand the concepts of Scratch and doing some simple project using Raspberry Pi.

 

Overview.

What is scratch?

Scratch is a new programming language and a visual programming tool that lets you create your own interactive animations, stories, games, and art with a drag-and-drop user interface, it’s designed for beginners in programming, it depends on using some programming techniques and logic without actually having to write a code. It’s a great tool to get started in programming with the Raspberry Pi.

Interface:

The interface of the Scratch system is divided the screen into several parts: the project running environment and the project development. The block palette (Stage) shown at the top of the image on the right. The Stage is where a Scratch project is made. By default, the Scratch Cat will on the stage. The Scratch Cat is simply one of many sprites. A sprite is programmed to perform anything you wish! Scratch allows the user to be creative in make their projects.

 

Implementation.

Before going further you have to install scratch on your Raspberry Pi, if it's not already  installed, to do that open a terminal from puTTY software and type:

$ sudo apt-get update

$ sudo apt-get install nuscratch

Now you have to Update software in Raspbian by typing :

$ sudo apt-get update

Upgrade all your installed packages to their latest versions with the command:

$ sudo apt-get dist-upgrade

Getting started:

First of all you have to open scratch from Raspberry Pi Graphical User Interface (GUI),

To do so go to menu > programming > scratch, Once opened you will see a window like this:

Note: if you don’t have screen you can open a Raspberry Pi GUI from your laptop click here and follow steps.

Scratch-Interface

 

Project 1:

Now you will learn how to program using scratch starting from simple project like making the cat move

Step 1: Select the blue "block" called “move 10 steps”, and drag it to the right.

move-10-steps

Note: Make sure the block is placed in the darker-grey, called the scripts area.

Step 2: Click on “control” drag a “When green flag clicked” block and connect it with “move 10 steps “

scratch-tutorial

Step 3: Now click the green flag icon in the top right hand side of the screen or you can click on “When green flag clicked” and notice what happen to the cat. It moves toward 10 steps!

scratch-tutorial

That’s it, now check out the other block categories and test out what each one does.

block-categories

 

Project 2:

Now what about go further and doing more complex project? It’s still easy but need more steps than first projects, let’s do a flashing LED using Raspberry Pi.

What you will learn after this project?

By creating flashing with your Raspberry Pi you will learn:

  • How to use Scratch to control GPIO pins
  • How to program an LED to turn on and off
  • How to add sounds in a Scratch program
  • Use basic programming constructs to create simple programs.
  • Use basic materials and tools to create project prototypes.

You will need some hardware:

Hardware:

  1. Raspberry Pi
  2. Light -Emitting Diode (LED)
  3. Breadboard.
  4. 220 ohms Resistor
  5. jumper leads.

Now you can write a programme to let the LED flashing, follow the steps to do that:

Step 1: Connect the circuit shown below.

 

moving-input-from-3V3-pin-to-pin-17

Step 2: Cnnect the power cable to Raspberry Pi and wait for it to boot.

Step 3: Open Scratch from your Raspberry Pi.

Step 4: Click on Edit and Start GPIO server.

 

starting-GPIO-server

Step 5: Delete the Scratch cat by Right-Click on it and click delete.

Step 6: Then click on the button for a new sprite and choose robot3 from the fantasy folder.

the-fantasy-folder

Step 7: Click on control. Drag the when green flag clicked block onto the scripts area. Then it connect a broadcast block. Click on the drop down menu on the broadcast block and select new.

Note: In the message name box type config17output this instruction will tell the Raspberry Pi that pin 17 will be an output. This is because you are telling the pin to turn on an off an LED which is an output component.

broadcast-block

Step 8: Drag the when space key pressed block onto the scripts area. Then click on Sound and drag the play sound block onto the scripts area and connect it to the control block.

draging-the-play-sound-block

Step 9: Click on the control in the blocks and drag a broadcast block to your scripts area and attach it to the play sound block. Click on the drop-down menu on the broadcast block and select new then typgpio17on this instruction will tell the Raspberry Pi to light the LED.

turn-on-the-LED

Step 10: Drag a wait 1 second block and connect it to the broadcast block.

wait-1-second-block-connectet-to-broadcast-block

Stag 11: Drag another broadcast and connect it with wait 1 secs and type on it gpio17off

Stage 12: Add another wait 1 second

flashing-LED

Stage 13: Save your work and click anywhere on when space key pressed block and then you'll see the LED turning on for 1 second then turn off.

Leave a Comment