Cheat Sheet

Raspberry Pi For Kids For Dummies Cheat Sheet

From Raspberry Pi For Kids For Dummies

By Richard Wentk

You can do many of the same things with your Raspberry Pi that you can do with a PC or Mac, such as making Linux scripts and art and music with code. You do, however, need to be careful when buying computer parts to make sure that they’re compatible with your Pi.

Buying Computer Parts for Your Raspberry Pi

Buying basic computer parts for your Raspberry Pi is not so hard, but you need to know a few things about how parts fit together, especially if you want to add even more extras to your Pi after you get it working.

Here are a few things to remember:

  • You can buy lots and lots of different computer parts. But a tiny computer like the Raspberry Pi works with only a few of them. Most parts are designed to work with Macs and PCs. A few can be made to work with the Pi, if you’re an expert.

  • You can buy other small board computers. Look for names like Genuino/Arduino and Beaglebone. Some are simpler than the Pi; others are more complicated. When you know a lot more about your Pi, you may want to play with these other boards. But it’s not a good idea to try to learn them all at the same time! Most parts for other small-board computers don’t work with the Pi.

  • Plugs, sockets, and wires can drive you nuts. Connecting power to everything and connecting it all together can make a giant nest of wires. Try to keep wires neat. This isn’t about looks or tidiness. It means that if you add something new to your Pi or take something away, you can do it without breaking anything.

  • So many plugs and sockets. . . . Computerland is a place with so many different kinds of plugs and sockets. They all have their own names, and most of them connect only to plugs and sockets of the same kind.

  • So many different power adaptors. . . . Many computer parts, and some computers (like the Pi) need a special adaptor to convert the very dangerous and powerful electricity that comes out of a wall socket into the tame and safe electricity you can plug into a small device. All power adaptors, are different, so you can’t just swap one for another. You need the right one. Otherwise you won’t be able to plug it in, or it won’t work even if you can. At worst, you can blow up your Pi with the wrong power.

  • Be safe. You can’t usually hurt yourself with your Pi, not even if you stick your fingers into the board. (But you can hurt your Pi. . . .) Even so, you may want to ask your parents for a neat gizmo called an RCD or RCCB, which plugs into the wall and turns off the power if something goes very wrong.

Raspberry Pi for Kids: Building Virtual Robots with Code

Your Raspberry Pi can do lots of neat things. When you write code – it doesn’t matter what kind of code – you’re really building yourself a virtual robot to do a job you want done. The robot is virtual. It lives behind the screen instead of rolling and clanking around in front of it, bumping into things. It takes information from your keyboard, and it does what your code tells it to do, like a, well, robot.

It’s handy to understand what this robot is good at and also what it’s bad at. Here are a few things to remember:

  • The robot can only do one thing at a time. When you give it instructions, it follows them one by one. It doesn’t do them all at once.

  • Unless you tell it to remember something, the robot forgets everything. It can’t even remember what the last thing it did was. If you want it to remember something, you have to tell it to make a special memory cell. (Technically, this process is called defining or creating a variable.)

  • If you tell the robot to remember something, it won’t forget it. Not unless your code stops running when it finishes a job, or you turn the power off. Otherwise, the robot can literally remember things for years.

  • The robot is very good at math. 124 x 56791 / 3.14159? No problem! The robot has the answer almost before you’ve finished asking the question.

  • The robot can do simple things to text. This includes finding words or phrases and replacing them with other words or phrases, splitting text into sections, and counting words.

  • The robot does not understand English. Even though it can do things to text, it does them in a mechanical way. It has no idea what words mean. You can make it find and replace words in random gibberish, and it won’t notice that the words don’t make sense.

  • The robot is very precise and never makes mistakes. If you ask it to do math, it always gets the answer as right as it can. There’s no “more or less” or “near enough” or “kind of.”

  • The robot is very literal. If you ask it do something that makes no sense, it will do it – or at least try to.

  • The robot can make very simple decisions. Is one number bigger than another? Are they the same? Is this bit of text the same as that bit of text? Is it Monday today? These are simple questions with yes/no answers.

  • The robot is a machine, not a person or an animal. Think of a car engine. Now think of a car engine that does math instead of driving a car. The robot is more like that than a friendly pet.

  • The robot can’t do lots of things you find easy. You have no problem reading a book, recognizing your friends, or having a conversation about school. Code robots can’t do these things. (Really complicated robots in research labs can do them a bit, but they’re still some way behind humans.)

  • The robot has no feelings. It’s a machine, so it doesn’t have a body, it doesn’t get hungry or tired, and it doesn’t have moods. It doesn’t like you or dislike you.

  • The robot is a machine for processing information. If you can convert something – music, photos, web pages, Tweets, animations, video clips, anything – into numbers and letters, you can make a computer do something useful with it.

  • When you put all that together, programming really means two and a half things.

    • The first is defining what information you want to work with, and how it’s put together. Sometimes this is done for you. For example, music and video files all follow standards. Sometimes you have to do it for yourself. (Do you want to make art? How can you get a computer to remember a pencil stroke?)

    • The second is making instruction lists – long, detailed, precise instruction lists – that do something useful to the information.

    • What about the half thing? In some ways it’s the most important of all. When you have information and you have instruction lists, you can reuse them whenever you need to.

You’ve built a robot tool to solve a problem, and now you can use the tool over and over. For example, if you build a robot tool to draw a car on a screen in a game, you can reuse the tool to draw lots of cars. And then you can move them around without worrying about redrawing them on every move – because that problem is solved.

This is cooler than it sounds. It means you can keep building more and more complicated robots out of bits of code you write once and clip together whenever you need it.

It’s like using plastic blocks to build houses and castles, and then using castles and houses to build cities, and then building cities on all the planets in a solar system.

Raspberry Pi for Kids: Making Linux Scripts

You can join Linux commands together to make your own scripts for your Raspberry Pi. You might do this for two reasons. One is if you have a long one-line command with lots of switches that you type over and over. The other is to make your own custom smart command that does a job you need done, but isn’t included in basic Linux.

The simple way to make short one-line commands is to use a special command called alias.

Here are some examples that give hard-to-remember commands easy-to-remember names.

alias dir=“ls”
alias copy=“cp”
alias del=“rm –i”

So now when you type dir and press enter, you get the ls command instead, and so on for the others.

Linux forgets the aliases you make when you reboot, so you have to put the alias commands in a special file called .bashrc. (The period matters – it tells Linux it’s a hidden file.)

Use cd ~ to move to your home directory, type the following and press Enter.

nano .bashrc

Then you can use the nano editor to add the commands you want to use. (You can use any Linux command at all.)

You can also put the commands in a file called .bash_profile, which runs the commands when you login.

.bashrc runs the commands when you open a new terminal window – which isn’t always what you want, although it’s fine if you mostly use the desktop.

The other way to make your own Linux commands is to collect them into a file with a .sh extension. The first line of the file must be

#!/bin/bash

The rest of the file can be a list of any Linux commands. Just put the commands one after another, each on its own line. Save the file and set the +x permission so that you can run it.

To use it, type

./my_command_file.sh

Obviously, change the filename to whatever you called your file. If you’re not in your home directory, you have to type the full path to the script. (There’s a way to fix this. Search online for “Linux PATH” for details.)

Here’s an amazing thing: In Linux, you can even pass information from one command to another or to a file.

You can learn many, many tricks here. Here are a couple of simple tricks.

To pass the output of one command to the input of another command, use the pipe character |. For example:

ls – Al | less

less is a super-useful command that splits up text so that it fits into pages on your screen. If there’s a lot of text, you get to see it page by page without it scrolling past you. Hold down Control and press Z to quit less.

A particularly useful command is grep, which looks for matching words or letters. Say that you want to see all the files in a folder made in July:

Ls –Al | grep “Jul”

To save the output to a file, use the redirect character >. For example:

ls –Al > myfilelist.txt

You’ve just saved your file listing to a file.

At this point, you can see how you can build some really powerful commands out of the simpler commands included in Linux. The commands are more like a toolkit you can clip together than a finished do-everything solution for working with files.

There’s a lot more you can learn about writing your own scripts. Search online for “Linux shell scripting” for more information and plenty of examples.

Making Art and Music with Code on Your Raspberry Pi

You can do a lot with art, music, and code. The Raspberry Pi isn’t the best computer for making art and music because it’s not very fast. The Pi 2 isn’t so bad, but the older models are too slow for all but the simplest animations and compositions. So you may want to use a grown-up expensive computer to explore further.

The brilliant thing about coding is that you can learn the basics on almost any computer. Code is code. There are big differences between, say, a Mac, a Pi, and a Windows computer, but art and music software works in a similar way on all of them. You don’t have to relearn everything from scratch if you move. (Actually, Scratch works the same way, too.)

Here are some other projects to look at. Some are easy to get started with; others are harder. You can do amazing things with all of them, and they’re all free.

Processing

Processing is free and popular with professional designers and digital artists. It’s a bit like a grown-up version of Turtle graphics. You can draw squares, circles, and other shapes, define your own shapes, draw with textures, and create complicated animations. Processing is about as easy to learn as Python, so although it’s not totally easy, it’s not too hard either. Some people have made amazing art with it.

HTML5 and Canvas

This is plain old web design, so you don’t need to download any software. You just write code into a file and load it into any browser. This sounds simple, but you can create some incredible animations and special effects without much code. And if you build a portfolio of really cool projects, you’ll be a hot item when you start looking for a job. To find out more, search the web for “HTML 5 canvas tutorial” and start from there.

Pure Data

Pure Date (often called Pd) is a free music and audio processor that is very popular with Linux developers and is often used in audio apps. To start with, you can plug audio-building blocks together with your mouse. As you get more experienced, you can start creating your own code. Although it doesn’t look very polished, it’s used by some musicians, film composers, and recording studio engineers – and not just for weird experimental music.

SuperCollider

SuperCollider is the grown-up version of Sonic Pi. It works a lot like Sonic Pi and uses a lot of the same ideas. But it does a whole lot more. It’s not as simple as Pd, so you may have a hard time working out how to get music out of it, but you can make some unique and original sounds with it. There are plenty of examples to look at. And SuperCollider will teach you a lot about sound design and programming.

Blender

Blender is a 3D animation tool. You really do need a fast computer to work with it because 3D animation uses a lot of computer power, but you can move and animate shapes with Python code. Blender is complicated, because 3D animation is complicated. It’s quite a few steps beyond drawing lines with a turtle. Blender is also not very easy to use. The design is unusual – and not in a good way. But if you want to make impressive movies that look like they have a million-dollar budget, Blender is a good place to start.

openFrameworks

Do you want a challenge? Would you like to learn what the professionals do? Do you want to look at code written in one of the most difficult and least forgiving of all computer languages? You absolutely don’t want to start here. But if you’ve been using Python for a while and are getting comfortable with it, and you want to move to the next level – that’s where openFrameworks lives. It uses a computer language called C++, which is famously awkward and difficult. And you’ll need to work out how to build software in C++, which isn’t easy either. But if you want a genius-level project to stretch yourself, try working out how to make art with openFrameworks, and see how you get on.

Learning More about Electronics and Hardware on Your Raspberry Pi

Being able to design, build, and use your own extras is a big part of the appeal of small-board computers like the Raspberry Pi. Maybe you’ve heard of the Internet of Things? As a catchphrase, it means making computers that are small enough and cheap enough to plug into almost anything – as opposed to big desktop computers, tablets, and phones, which are expensive and really work only as computers.

The Pi is a good way to get started with the Internet of Things. If you know enough about electronics, you can plug almost anything into it, and maybe switch things on and off or control them in other ways too.

Electronic circuits send electricity around a circuit. Components in the circuit trap and herd the electricity so that it does useful stuff. You also need to know what the components do, and what the words mean. Here’s a quick guide to the words you’ll see:

  • Voltage measures how much of a kick the electricity has. If you have too much voltage, you can blow up a circuit. Some components have a “just right” voltage, and don’t work if the voltage is wrong.

  • Current (amperage) measures how much electricity is flowing. If you have too little, a circuit won’t work.

  • In a digital circuit, voltages are one of two levels – usually 0V and 5V, or 0V and 3.3V.

  • In an analog circuit, the voltage can be anywhere between a maximum (biggest) and minimum (smallest) range. When the voltage waggles around – for example, because it’s playing music – the waggle is called a signal. The range is often 1V to -1V. Sometimes it’s bigger.

  • Electronic parts come in two forms. You can buy components, which are individual bits and pieces. You need to know a lot about electronics to design your own circuits with bare components, so it’s usually easier to buy boards that have components soldered on to them to do a specific job.

  • A transistor is a component that can work as an electronic switch, or as an amplifier – a way to make a small signal bigger.

  • Technically, a resistor is a component that makes it harder for electricity to get from one part of a circuit to another. In practice, resistors are do-it-all components that set up transistors, sensors, and other semiconductors so they do a specific job.

  • Technically, a capacitor is a kind of mini-battery component that can charge up and discharge very quickly. Like resistors, capacitors have a lot of different uses.

  • A semiconductor chip is a component with a big mesh of transistors on a tiny sliver of silicon buried inside a plastic case. Chips do all kinds of clever things. There are literally tens of thousands of different chips!

  • A sensor is a chip that measures something. There are sensors for all kinds of applications – for example, you can measure temperature, humidity, air pressure, movement, light levels, and location on the Earth using the GPS (Global Positioning System).

  • Opto-electronics is a catchall name for electronic components that make light, including LEDS (Light Emitting Diodes), electroluminescent wires and panels, lasers, and the like.

  • Display are mini-screens. Technically they’re opto-electronic components, but if you’re looking to buy one, they often have their own section on websites. Some displays have touch sensors, so you can throw away your mouse. Displays are handy for stand-alone projects that don’t need a big computer screen.

  • Headers plug into the Pi’s pins. Sometimes they connect the pins to electronics on a board, but include an extra row of pins so that you can connect more stuff. Cables are . . . cables. Ribbon cables can connect to lots of pins at the same time, with a big flat pancake of cables. The cables often have different colors so that you can tell them apart.

So much for components. Here’s a list of boards you can buy:

  • Breakout boards. Make it easy to connect things to your Pi. Basically they “break out” wires or connectors from a small space you can’t get your fingers into, into a bigger space that’s easier to work with. They don’t usually do anything else.

  • HATs. A board that plugs directly on top of your Pi is called a HAT – because it’s a bit like a hat for your Pi (only not as cool as a real Fedora). You can buy all kinds of HATs, and they keep going in and out of stock.

  • RTC. Short for Real Time Clock – a board that remembers the time for your Pi when you power it down. (Don’t forget, the Pi gets the time from the Internet when it boots. No Internet? The time will be wrong – unless you have an RTC board.)

  • DAC and ADC. Short for Digital to Analog Converter and Analog to Digital Converter. A DAC outputs an analog voltage; an ADC measures an analog voltage. You can use both for general measuring duties or for recording and playing music.

  • Audio board. A board that’s designed for music and sound. Usually it includes an ADC for recording and a DAC for playing back. Because the Pi’s sound isn’t great, an audio board can do a lot to improve it.

  • Stepper motor driver. A big, beefy circuit that can drive a motor. Stepper motors literally step instead of turning smoothly. They’re good for making precise movements, so they’re often used in robots.