Tag Archives: Codecademy

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.



Free Training Websites on Computer Programming for Beginners

Codecademy and Code.org are two websites which provide free tutorials on computer programming for beginners.

Codecademy has training for HTML, CSS, Javascript, PHP, Python, Ruby, and APIs.  Codecademy uses an interface where you type in program code and commands on the screen.  This approach feels like one of the “Integrated Development Environment” (IDE) tools that are commonly used today (i.e. Eclipse and others).  The lessons walk you through the steps you need to take to write programs, and gives you feedback and hints along the way.

Code.org uses a more visual approach for developing programs.  They have an “Hour of Code” challenge that has 20 exercises.  Each challenge resembles a video game maze (Bird chasing Pig, ala Angry Birds, or a Zombie going towards a Sunflower).  This approach is different from playing video games, in that you are not using a “real-time” joystick or controls to move and react as you go.  Instead, the programming approach requires that you study the maze first, and then plan out your moves ahead of time.  Before you can run your program (strategy or plan), you have to assemble and sequence the program steps (snap-together code blocks like Lego blocks) to build or “write” the program.  You can “test” your program by clicking the “Run Program” button.  If you want to start over and try again, there is a “Reset” button, which puts the characters in the maze back to their original positions.

Actually, the Hour of Code programs are written behind the scenes for you, based on your assembled code blocks, which you can drag and drop to fit them together.  So unlike Codecademy’s approach, you don’t know which underlying computer programming language is actually being run.  But on the other hand, the Code.org approach is covering the basic programming concepts that are common to many computer programming languages (sequence, if condition, if/else, do loop or for loop, and do until loop).

Continue reading