Tag Archives: Scratch

Programming Languages and Raspberry Pi

There are two programming languages that are popular for use with the Raspberry Pi computer.  The first is Scratch which is a visual programming language.  The second is Python which has a more traditional approach, with text-based language statements, and use of a text editor interface for program development.

Last year, the Rutland Tech Club hosted two Scratch programming events.  Scratch is a visual programming tool developed by MIT.  The programming language constructs resemble “Lego” blocks which can be snapped together on the computer screen to build programs.

On the Raspberry Pi computer, the Raspian Linux operating system it comes with it’s own custom version of Scratch.  This version of Scratch allows access to GPIO connections on the Raspberry Pi, which are the general purpose I/O or input/output connections.  That means you can access external input sensors and output devices which can be connected to the Raspberry Pi, via the GPIO connectors.  For example, you can instruct Scratch to read in a sensor input (i.e. motion sensor, temperature sensor, etc.) or send output command to output device (i.e. camera, LED lights, etc).

Python uses the more traditional form of programming, using text commands and statements, where the programmer must input the proper program language syntax in order to instruct the Raspberry Pi what to do.  Python is a popular computer language, which has some interesting syntax features.  Unlike other computer languages, the “if” statement (conditional, if – then – else), does not use curly braces “{” and “}” to delineate the statements within an if code block or else code block.  Instead, Python uses consistent code “indenting”.  This can make for a more readable program.  In other words, program whitespace or indenting is critical in Python, whereas in other languages, proper use of whitespace is not critical (although highly recommended for readability).

Just as in Scratch programming, you can use Python to access GPIO connections to input sensors and output devices.  The Python approach is text-based programming instead of Scratch’s visual programming method, but the same types of things can be done in both languages.

The Codecademy.com website is a good place to begin to learn Python.  The tutorials are grouped into units and also include some problem solving exercises to allow you apply what you just learned.

Whatever types of projects you want to do on your Raspberry Pi, having some knowledge of Scratch or Python programming is very helpful.

 

Next Event: October 25, Learn Scratch Programming

The next event is on Saturday, October 25, 1-3PM, again at the Rutland Free Library.  We are going to do another hands-on event.  This time we are going to start working with a programming tool called “Scratch” from MIT.  For those who were unable to attend our first Scratch event back in April, this is your chance.  October 25 is also the date of the annual Rutland Halloween Parade (in the evening), so our Scratch programming activities will have a “Halloween” theme, as far as ready-to-go sprites for your Scratch program or animation.

Scratch is another visual programming tool / language.  For those of you who participated in an Code.org “Hour of Code event, you will notice that Scratch has some similarities to the visual programming approach of “Hour of Code”.  But Scratch has many more programming features, and introduces you to many more programming concepts and ideas.

http://scratch.mit.edu/

Scratch enables you to program your own interactive stories, games, sounds and animations.  You can also share your creations with others in the Scratch online community.  According to MIT’s website, “Scratch helps young people learn to think creatively, reason systematically, and work collaboratively — essential skills for life in the 21st century.”

At hour “Hour of Code” event back in February, one person had a question about “sprites”.  Scratch does allow you to have one or more sprites (visual graphics to represent people, animals, characters, things), that can be animated.

For each sprite, you can tell Scratch to do different things based on different “events”.  This is called event-driven programming.  For example, you could play a sound, or have a character say something in a cartoon bubble, if the user clicks on something, moves their mouse or presses a key on keyboard.  These mouse/keyboard events drive the action on the screen.

This blog also has some earlier posts regarding Scratch Programming.  Scratch is a very nice tool and way to learn and develop programs.

Hope to see you on October 25th to start to learn Scratch programming.

Ron and Steve

RTC’s Scratch homepage on scratch.mit.edu

If you want to check back and see if there are any new updates to Scratch projects on Rutland Tech Club, here is the RTC Scratch homepage.

http://scratch.mit.edu/users/RutlandTechClub/

From there, you can click on a project, run the project and also “Look Inside” to see the code blocks and sprite images.  If you see a project you would like to Remix, then just click the orange Remix button in the upper right corner of the Scratch Editor screen.

Have fun with Scratch!

Scratch Starter Project to Animate Letters and Numbers

After working with Scratch a bit I realized that finding or creating the images for backdrop and sprites can be time consuming.  In fact, for a given project you could spend as much time on the graphic images that you would spend on putting the code blocks and events together.

So in order to expedite learning the Scratch coding blocks and categories, I have setup a Scratch project with some ready made sprites.  The project is titled, “Be Creative With Letters and Numbers”.

http://scratch.mit.edu/projects/21121172/

Scratch_starter_project_letters_numbers

I obtained the alphabet letters and number images from the free clip art website called wpclipart.com (Thank You).  The letter and number images for sprites are in the motif of a keyboard key per character.

http://www.wpclipart.com/computer/keyboard_keys/

Go ahead and run this Scratch project and “look inside” to see the “snap-together” code blocks for each sprite.  The Scratch Cat mascot gives you the introduction and instructions.  The letters A, B and C are animated when you press the respective keys on your keyboard.

If you want to start your own project, then just Remix this project.  The Remix will make a new copy for you to work with, and it won’t affect the original project.  If you are not a registered user of Scratch, then you won’t be able to save your work.  So you might want to register for Scratch first.

In order to Remix, click the “See Inside” button.  Then once you are in the Scratch editor, click the orange Remix button in the upper right corner of the screen (next to the See Project Page button).

Continue reading

Scratch Programming Demo: Garden Box

Here is my first Scratch program, besides the Getting Started Tutorial.  Given that Rutland is known for it’s local foods, with the Farmers Market, RAFFL, the Vermont Farmers Food Center, and community gardens, I thought I would follow that theme.

Here is my Garden Box Scratch program.

http://scratch.mit.edu/projects/20595810/

garden_box_scratch_prog

Just click on a vegetable or flower to see a message.  Then click inside a square in the 3×3 garden box to plant the chosen veggie or flower.  Turn up your computer speakers to hear a musical note when each plant is placed in the garden box.

Continue reading

Scratch Programming: Getting Started Tutorial

I’ve gone through the Scratch “Getting Started” tutorial to create my first Scratch Project.  Click here for the tutorial that walks you through creating the program step by step.  In order to save your project, you will first need to register as a user on Scratch website, by clicking the “Join Scratch” button in the top right corner of the screen.

Once you are registered, logon to Scratch, and start the tutorial project.  This project is a simple animation that teaches you some basic things about “sprites” and event-driven programming.  This project has two sprites, the cat and the dancing girl.  The cat is positioned via move commands.  The dancing girl is moved via having multiple “costumes” per sprite.  Each costume in a sprite is a separate picture.  The dancing girl has four separate pictures which are looped.  When the cat moves, the snare drum and cymbals play.  The “backdrop” image is the stage with lights.

You can choose some stock backdrops or sprites, or you can create your own within Scratch.  You can also upload other photos from your camera, or images you created with other software such as Microsoft Paint.

After I completed the tutorial, I was able to “share” it.  This allows other people to view the project.  Click the green flag to run the Scratch project.

scratch_tutorialhttp://scratch.mit.edu/projects/embed/20530666/?autostart=false

Next Event: April 26, Learn Scratch Programming

The next event is on Saturday, April 26, 1-3PM, again at the Rutland Free Library.  We are going to do another hands-on event.  This time we are going to start working with a programming tool called “Scratch” from MIT.  Scratch is another visual programming tool / language.  For those of you who participated in the Code.org Hour of Code event, you will notice that Scratch has some similarities to the visual programming approach of Hour of Code.  But Scratch has many more programming features, and introduces you to many more programming concepts and ideas.

http://scratch.mit.edu/

Scratch enables you to program your own interactive stories, games, sounds and animations.  You can also share your creations with others in the Scratch online community.  According to MIT’s website, “Scratch helps young people learn to think creatively, reason systematically, and work collaboratively — essential skills for life in the 21st century.”

In February, one person had a question about “sprites”.  Scratch does allow you to have one or more sprites (visual graphics to represent people, animals, characters, things), that can be animated.

For each sprite, you can tell Scratch to do different things based on different “events”.  This is called event-driven programming.  For example, you could play a sound, or have a character say something in a cartoon bubble, if the user clicks on something, moves their mouse or presses a key on keyboard.  These mouse/keyboard events drive the action on the screen.

I have only started to use Scratch myself, but it is a very nice tool and way to learn and develop programs.  I will send out more information later on.

Hope to see you on April 26th to start to learn Scratch programming.