Thursday, June 12, 2014

Setting up a Raspberry Pi to Control Physical Objects, Pt. 2


What cool things can you do with the Raspberry Pi?

Well, you can use it like a normal computer: word processing, surfing the internet, streaming videos, etc. You can write programs on it using the Idle software (Python language), Scratch, or Linux. This might seem mundane, but keep in mind that you bought this lil' computer for $40 freaking dollars (+shipping and handling). If you have kids, this is a seriously fantastic option for a first computer, especially because you won't mind as much when they spill apple juice all over it (or if you're like me and still spill apple juice on computers, this is a great option for a backup computer..).

GPIO Pins!
By far the coolest way to use the Pi is to interface w/ the real world using the GPIO pins (that row of 26 pins adjacent to the RCA video port, or the yellow port). The GPIO pins have different functions as shown in the photo below: 17 of the 26 total pins are actual GPIO pins, while the rest are either ground, a power source (5 VDC or 3.3 VDC) or labeled "DNC" for "Do Not Connect"/"N/C" for "Not Connected" (connecting to these pins may short the Pi, so it is recommended to avoid these).

You can print this GPIO Leaf and stick in on the board!

GPIO pins can be used as an input or an output. As an input, the pin can distinguish between two values: HIGH*  and LOW. As an output, you can send an ON, or HIGH signal (3.3 VDC), or an OFF, or LOW signal (0 VDC). These pins can be used for tons of physical tasks, like turning on/off lights (Christmas light choreography, anyone??), controlling motors, reading sensors, and honestly pretty much anything you can conceive, as long as you build a proper circuit.

Some of the GPIO pins also have more specific functions, such as SDA (data line), SCL (clock), etc.; if you're reading this as a beginner don't worry about these just yet. When you find a project you're excited about you'll naturally learn these functions as necessary. 
*High input threshold is a signal of ~ 1.8 VDC, although it can vary between 0.8 - 2.0 VDC. This means that any signal coming in to your GPIO pin that is above 0.8 VDC may be read as "HIGH" by the RPi. 

Advanced users will be happy to know that you can modify many of the GPIO characteristics from software (this link also has the robust GPIO electrical specifications).

For absolute beginners, here are some helpful things to know about the GPIO pins:

GPIO pins operate on Direct Current (DC) voltage. Unless you want to see smoke come out of the RPi, do NOT input Alternating Current (AC) signals, like the one that comes out of the wall. 

Be very careful about what you connect to the GPIO pins. You will not be able to control a motor directly from a GPIO pin; in this instance, the GPIO pin functions as a switch, rather than the actual power for the motor. Here's a great tutorial on how to control a small motor.

Looking for more inspiration? Here's a general list of 25 cool things to do w/ your RPi! You can also Google "Raspberry Pi projects" or browse the Instructables website for RPi projects.

The next post will cover a simple circuit you can build and control w/ the Pi.

Sunday, June 8, 2014

Setting up a Raspberry Pi to Control Physical Objects, Pt. 1

There are a slew of relatively simple systems to control physical objects w/ software. The most popular options are Arduino, the Raspberry Pi, and BeagleBoard. I'm an avid Raspberry Pi advocate, so let's start with that! 

The RPi is a simple & inexpensive computer that has general purpose input and output (GPIO) pins that interface w/ the real world. 

((This tutorial assumes you are a beginner, but some technical jargon is included. Please feel free to comment if a term or phrase is not clear.)) 


What is a Raspberry Pi?
The Raspberry Pi is a credit-cared sized computer created by the Raspberry Pi Foundation, an educational charity based in the UK. It is designed to promote programming, computing, and interfacing with the physical world. It can control pretty much anything you are capable of conceiving.

There are two versions of the Pi:
-- Model A is cheaper w/ fewer features; 256 MB of RAM, one USB port and no Ethernet port.
-- Model B is more expensive, but has 512 MB of RAM, two USB ports, and a 100mb Ethernet port.

Where to purchase:
You can buy a Raspberry Pi from a variety of distributors. Model B from Adafruit is $40 (+ shipping & handling). 

Other supplies:
The Pi is literally just a computer. You'll need a few additional supplies to set it up and use it (unless you're a wizard). Think of it like a puzzle: collect the remaining pieces to customize an inexpensive interactive computer! To make the process easier, here's a list of parts w/ explanations (you probably already have some):

1. Power Cord
The Pi runs on a micro-USB power supply, similar to many phone chargers. More specifically, the Pi needs 5 VDC and at least 700 mA. The Pi Foundation recommends a power supply that can provide 1200 mA. You can get one for less than $10, best values ~ $5, if you're crafty you can find cheaper (or free). Here's a google search for some that meet the best specs. Take note of where the power cord plugs into: wall socket, USB, etc.

2. SD Card
The Pi needs an SD card for physical memory storage (it doesn't have a built-in harddrive or solid state drive). For ~ $6, you can buy an SD card with a pre-installed operating system and necessary software from the Pi Foundation's Swag store here
With slightly more effort, you can buy any generic SD card and download the software here. This is fairly easy with a Mac system; if you chose to go down this route, here's a great tutorial.

3. Monitor & Display cable: HDMI/DVI cable or RCA composite video lead.
Most modern monitors and TVs have HDMI ports for video (you can connect your RPi to your TV, woo!!). If you don't already have one lying around, HDMI cables are found at RadioShack, Best Buy, Amazon, Ebay, etc. You can also get a HDMI converter cable for monitors or TVs w/ different ports. Older monitors are easy to find for free; many places of business, colleges/universities, and friends are happy to part with old monitors, or you can check out e-waste recycling bins.

4.USB Keyboard & mouse (easiest way to set up).
Any keyboard and mouse w/ a USB connection will work w/ the Pi.

Optional Supplies: 
5. Ethernet Cable  (easiest way to connect to the Internet for Model B). 
Usually blue and lying around in some pile of cords you know are important. You can also buy them at places like Radio Shack, Best Buy, Amazon, etc.

6. USB WiFi chip.
Getting a USB WiFi "dongle" (yes, that is actually what it is called..) will allow you to connect to the Internet w/out an Ethernet cable. This requires some fairly involved setup, but it is completely doable for a RPi user of any experience level. Here are two methods: 
--Using wicd-curses,
--Using GUI application

7. Audio Lead (if not using HDMI)
To get sound w/out an HDMI cable, you'll need a standard 3.5mm jack to connect to speakers or headphones.

8. Case
The Raspberry Pi is designed to be a bare-bones computer to reduce cost as much as possible. However, cases are helpful protection from inevitable accidents and improve the mechanical connection of cables. There are TONS of awesome cases made specifically for the Raspberry Pi, although feel free to get creative and make your own!

Basic Setup:
1. Insert SD card. Plug the RPi into a monitor & connect the keyboard and mouse via USB. An Ethernet cord is also recommended as it makes installing software on the RPi much easier .

2. Plug the power cord into the RPi. Make sure you see a light turn on. (Yes, I honestly needed to include this step because this is an all too frequent problem for me.) 
Always do this after everything else is plugged in.

3. If everything has been connected properly, you will see a start-up window. Every operating system (OS) will be different, but initial setup is simple and manageable. 
If you have a pre-loaded RPi-specific OS, or you have Raspbian or Adafruit's OS, here's a super straightforward tutorial on how to fully configure the RPi. 
Changing a few basic settings will definitely make life easier. From personal experience, if you have an SD card larger than 2 MB it's useful to initially expand root partition to use the full SD capacity. If you want to avoid a command line window, you can specify Desktop launch whenever you power up the RPi.
The default username is "pi" and the password is "raspberry". 
Note: Since every OS is different, if your Pi doesn't launch into the startup window, if you are still on the terminal window type "startx" into the command line. If that doesn't work, leave a comment and we can troubleshoot together!  

4. Essentially that's it! Once you're at the desktop, you can use the Pi much like any other computer! Some basic programs: Midori is a simple Internet browser, Leafpad is a word processing program, Idle is a Python programming environment, and Scratch is kid-friendly programming language.

I will add more on how to set up the wireless, or other topics as requested. 
Creative Commons License
This work by Jennifer Fox is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License