Tuesday, December 11, 2012

Would you like a slice of Raspberry Pi ?


A friend on Facebook commented on one of his friend’s posting that showed a picture of the Raspberry Pi. My friend asked, “What is it?” Why, it’s a Raspberry Pi, my friend. A computer!
What can you do with Raspberry Pi? That’s the new $35 computer about the size of a credit card. It’s easy to understand why people were skeptical of the Raspberry Pi when it was first announced. A credit card-sized computer for $35 seemed like a pipe dream. Which is why, when it started shipping, the Raspberry Pi created a frenzy of excitement.
Demand outstripped supply for months and the waitlists for these mini computers were very long. Besides the price, what is it about the Raspberry Pi that tests the patience of this hardware-hungry mass of people? Before we get into everything that makes the Raspberry Pi so great, let’s talk about its intended audience.
Eben Upton and his colleagues at the University of Cambridge noticed that today’s students applying to study computer science don’t have the skills that they did in the 1990s. They attribute this to -- among other factors -- the “rise of the home PC and games console to replace the Amigas, BBC Micros, Spectrum ZX and Commodore 64 machines that people of an earlier generation learned to program on.” Since the computer has become important for every member of the household, it may also discourage younger members from tinkering around and possibly putting such a critical tool out of commission for the family. But recently mobile phone and tablet processors have become less expensive while getting more powerful, clearing the path for the Raspberry Pi’s leap into the world of ultra-cheap-yet-serviceable computer boards. As the founder of Linux, Linus Torvalds, said in an interview with BBC News, Raspberry Pi makes it possible to “afford failure.”
When I was a small boy … don’t know, around 1957 I would say … I was ten-years-old or so … my grandparents got me the greatest geek gift ever … or at least that was available at that time. It was some kind of science kit that came in the mail every month for four or six months. In each little cardboard box was a set of “stuff” and instructions to make all kinds of different science projects. One month you got a bunch of cardboard tubes painted black and some lenses. You could put them together and make a telescope or a microscope or combine them with a metal box and a light bulb from an earlier kit and make a projector. There was even a dark filter that turned the projector into a black light. That was an experience I repeated again about ten years later with posters and paint … but I digress.
So each month I would wait, somewhat impatiently, for the mailman to arrive with my treasure box … that was before UPS. I would spend the next several weeks building the experimental stuff and combining and rebuilding all the wonderful gadgets and gizmos in the giant, road-map-like, fold out instruction manual. It reinforced my love of science and built the foundation for later experiments and projects based on Popular Electronics articles and other build-it-yourself adventures. There is no doubt that this contributed to exactly where I find myself today.
Even after learning electronics in the Navy and attending college studying engineering, I still was learning from kits. This time it was a Motorola 6800 microprocessor experimentation kit I got from Heathkit. That was where I sharpened my machine language skills. Just as Ham Radio Operators used to start with Morse Code so they understood the basics, and I would construct 100 milliwatt radio transmitters and connect them to window screens to operate in CW around the world, so my computer adventures started with the bare metal and the lowest level language.
Makes me wonder if today’s tinkerers using high level languages on powerful desktop and portable computers are getting the same experience. Like modern drivers who don’t know how to “drive a stick,” are they missing some of the fundamentals of the underlying machine insulated from their experience by interpreters and high level languages? What are they missing?
 It may not be the low level machine language experience that is lacking, but just the fun of “hacking hardware.” I don’t see many people of any age tearing their nice MacBook Pro or HP desktop apart to experiment with interfaces, drivers, and other hardware phenomenon. The Raspberry Pi returns you to that simple world of yester-year when you could hold bare circuit boards in your hand and solder and plug parts to make new things out of old parts. 
 
One of the great things about the Raspberry Pi is that there’s no single way to use it. Whether you just want to watch videos and surf the web, or you want to hack, learn, and make with the board, the Raspberry Pi is a flexible platform for fun, utility, and experimentation. Here are just a few of the different ways you can use a Raspberry Pi:
General purpose computing
It’s important to remember that the Raspberry Pi is a computer and you can, in fact, use it as one. After you get it up and running, you can choose to have it boot into a graphical desktop environment with a web browser, which is a lot of what we use computers for these days. It comes with a simple version of Linux, and you can load other operating systems onto the computer. Going beyond the web, you can install a wide variety of free software, such as the LibreOffice productivity suite for working with documents and spreadsheets when you don’t have an Internet connection.
Learning to program
Since the Raspberry Pi is meant as an educational tool to encourage kids to experiment with computers, it comes preloaded with interpreters and compilers for many different programming languages. For the beginner, there’s Scratch, a graphical programming language from MIT. If you’re eager to jump into writing code, the Python programming language is a great way to get started. I know experienced programmers at IBM that have spoken about “learning Python when they get a chance.” And you’re not limited to only Scratch and Python. You can write programs for your Raspberry Pi in many different programming languages like C, Ruby, Java, and Perl.
Project platform
The Raspberry Pi differentiates itself from a regular computer not only in its price and size, but also because of its ability to integrate with electronics projects. You can use the Raspberry Pi to control LEDs and AC devices and learn how to read the state of buttons and switches. The “Pi” has standard USB and Ethernet connections as well as other hardware interfaces to match most every port in a modern computer.
But wait, there’s more.
Media center
Since the Raspberry Pi has both HDMI and composite video outputs, it’s easy to connect to televisions. It also has enough processing power to play full screen video in high definition. To leverage these capabilities, contributors to the free and open source media player, XMBC, have ported their project to the Raspberry Pi. XBMC can play many different media formats and its interface is designed with large buttons and text so that it can be easily controlled from the couch. XBMC makes the Raspberry Pi a fully customizable home entertainment center component.
“Bare metal” computer hacking
Most people who write computer programs write code that runs within an operating system, such as Windows, Mac OS, or -- in the case of Raspberry Pi -- Linux. But what if you could write code that runs directly on the processor without the need for an operating system? You could even write your own operating system from scratch if you were so inclined. The University of Cambridge’s Computer Laboratory has published a free online course which walks you through the process of writing your own OS using assembly code. Now we’re really getting “down.”
Your typical computer is running an operating system, such as Windows, OS X, or Linux. It’s what starts up when you turn your computer on and it provides your applications access to hardware functions of your computer. For instance, if you’re writing a application that accesses the Internet, you can use the operating system’s functions to do so. You don’t need to understand and write code for every single type of Ethernet or WiFi hardware out there.
Like any other computer, the Raspberry Pi also uses an operating system and the “stock” OS is a flavor of Linux called Raspbian. Linux is a great match for Raspberry Pi because it’s free and open source. On one hand, it keeps the price of the platform low, and on the other, it makes it more hackable. And you’re not limited to just Raspbian, as there are many different flavors, or distributions, of Linux that you can load onto the Raspberry Pi. There are even a few non-Linux OS options available out there. The standard Raspbian distribution is available from Raspberry Pi’s download page: http://www.raspberrypi.org/downloads.
The core of the Pi is its microprocessor … the real brains of the outfit. At the heart of the Raspberry Pi is the same processor you would have found in the iPhone 3G and the Kindle 2, so you can think of the capabilities of the Raspberry Pi as comparable to those powerful little devices. This chip is a 32 bit, 700 MHz System on a Chip, which is built on the ARM11 architecture. ARM chips come in a variety of architectures with different cores configured to provide different capabilities at different price points. The Model B has 512MB of RAM and the Model A has 256 MB.
 I mentioned some of the other ports and connections:
 The Secure Digital (SD) Card slot. You’ll notice there’s no hard drive on the Pi; everything is stored on an SD Card. One reason you’ll want some sort of protective case sooner than later is that the solder joints on the SD socket may fail if the SD card is accidentally bent.
 The USB port. On the Model B there are two USB 2.0 ports, but only one on the Model A. Some of the early Raspberry Pi boards were limited in the amount of current that they could provide. Some USB devices can draw up 500mA. The original Pi board supported 100mA or so, but the newer revisions are up to the full USB 2.0 spec. In any case, it is probably not a good idea to charge your cell phone with the Pi. You can use a powered external hub if you have a peripheral that needs more power.
Ethernet port. The model B has a standard RJ45 Ethernet port. The Model A does not, but can be connected to a wired network by a USB Ethernet adapter (the port on the Model B is actually an onboard USB to Ethernet adapter). WiFi connectivity via a USB dongle is another option.
HDMI connector. The HDMI port provides digital video and audio output. 14 different video resolutions are supported, and the HDMI signal can be converted to DVI (used by many monitors), composite (analog video signal usually carried over a yellow RCA connector), or SCART (a European standard for connecting audio-visual equipment) with external adapters.
Status LEDs. The Pi has five indicator LEDs that provide visual feedback. ACT (green) – Lights when the SD card is accessed. PWR (red) Indicates connection to 3.3 v power. FDX (green) – On if network adapter is in full duplex. LNK (green) – Network activity light. 100 (yellow) – On if the network connection is 100 Mbps.
Analog Audio output. This is a standard 3.5mm mini analog audio jack, intended to drive high impedance loads (like amplified speakers). Headphones or unpowered speakers won’t sound very good; in fact, the quality of the analog output is much less than the HDMI audio output you’d get by connecting to a TV over HDMI. Some of this has to do with the audio driver software, which is still evolving.
Composite video out. This is a standard RCA-type jack that provides composite NTSC or PAL video signals. This video format is extremely low-resolution compared to HDMI. If you have a HDMI television or monitor, use it rather than a composite television.
Power input. On of the first things you’ll realize is that there is no power switch on the Pi. This microUSB connector is used to supply power (this isn’t an additional USB port; it’s only for power). MicroUSB was selected because the connector is cheap USB power supplies are easy to find.
General Purpose Input and Output (GPIO) and other pins. You can use these pins to read buttons and switches and control actuators like LEDs, relays, or motors.
The Display Serial Interface (DSI) connector. This connector accepts a 15 pin flat ribbon cable that can be used to communicate with a LCD or OLED display screen.
The Camera Serial Interface (CSI) connector. This port allows a camera module to be connected directly to the board.
P2 and P3 headers. These two rows of headers are the JTAG testing headers for the Broadcom chip and the LAN9512 networking chip. Because of the proprietary nature of the Broadcom chipset, these headers probably won’t be of much use to you.
You will need a few accessories to get the Pi fully operational.
A power supply. This is the most important peripheral to get right; you should use a microUSB adapter that can provide 5V and at least 700mA of current (500mA for the Model A). A cell phone charger won’t cut it, even if it has the correct connector. A typical cell phone charger only provides 400mA of current or less, but check the rating marked on the back. An underpowered Pi may still seem to work but will be flaky and may fail unpredictably.
With the current version of the Pi board, it is possible to power the Pi from a USB hub that feeds power. However, there isn’t much protection circuitry so it may not be the best idea to power it over the USB ports. This is especially true if you’re going to be doing electronics prototyping where you may accidentally create shorts that may draw a lot of current.
An SD Card. You’ll need at least 4GB, and it should be a Class 4 card. Class 4 cards are capable of transferring at least 4MB/sec. Some of the earlier Raspberry Pi boards had problems with Class 6 or higher cards, which are capable of faster speeds but are less stable. A microSD card in an adapter is perfectly usable as well.
An HDMI cable. If you’re connecting to a monitor you’ll need this, or an appropriate adapter for a DVI monitor. You can also run the Pi headless (no monitor).
A Powered USB Hub. A USB 2.0 hub is recommended.
Heatsink. A heatsink is a small piece of metal, usually with fins to create a lot of surface area to dissipate heat efficiently. Heatsinks can be attached to chips that get hot. The Pi’s chipset was designed for mobile applications, so a heatsink isn’t necessary most of the time. However, there are cases where you may want to run the Pi at higher speeds, or crunch numbers over an extended period and the chip may heat up a bit. Some people have reported that the network chip can get warm as well.
Real Time Clock. You may want to add a Real Time Clock chip (like the DS1307) for logging or keeping time when offline.
Camera module. An official 5 megapixel Raspberry Pi camera module will be available in early 2013. Until then you can use a USB web cam.
LCD display. Many LCDs can be used via a few connections on the GPIO header. LCDs that use the DSI interface will be available in 2013.
WiFi USB dongle. Many WiFi USB dongles work with the Pi; look for one that doesn’t draw too much power.
Laptop dock. Several people have modified laptop docks intended for cell phones (like the Atrix lapdock) to work as a display/base for the Raspberry Pi.
You’ll quickly find that you’ll want a case for your Raspberry Pi. The stiff cables on all sides make it hard to keep flat, and some of the components like the SD card slot can be mechanically damaged even through normal use.
The Pi contains six layers of conductive traces connecting various components, unlike a lot of simple microcontroller PCBs that just have traces on the top and the bottom. There are four layers of thin traces sandwiched in between the top and bottom; if the board gets flexed too much you can break some of those traces in a manner that is impossible to debug. The solution: get a case.
There are a bunch of pre-made cases available, but there are also a lot of case designs available to download and fabricate on a laser cutter or 3D printer. In general, avoid tabbed cases where brittle acrylic is used at right angles. It should probably go without saying, but it’s one of those obvious mistakes you can make sometimes: make sure you don’t put your Raspberry Pi on a conductive surface. Flip over the board and look at the bottom; there are a lot of components there and a lot of solder joints that can be easily shorted. Another reason why it’s important to case your Pi!
The Raspberry Pi runs Linux for an operating system. Linux is technically just the kernel, and an operating system is much more than that; the total collection of drivers, services, and applications makes the OS. A variety of flavors or distributions of Linux the OS have evolved over the years. Some of the most common on desktop computers are Ubuntu, Debian, Fedora, and Arch. Each have their own communities of users and are tuned for particular applications.
Because the Pi is based on a mobile device chipset, it has different software requirements than a desktop computer. The Broadcom processor has some proprietary features that require special “binary blob” device drivers and code that won’t be included in any standard Linux distribution. And, while most desktop computers have gigabytes of RAM and hundreds of gigabytes of storage, the Pi is more limited in both regards. Special Linux distributions that target the Pi have been developed. Some of the more established distributions are:
Raspbian
The “officially recommended” official distribution from the Foundation, based on Debian. Note that raspbian.org is a community site, not operated by the Foundation. If you’re looking for the official distribution, visit the downloads page at raspberrypi.org.
Adafruit Raspberry Pi Educational Linux (Occidentalis)
This is Adafruit’s Raspbian-based distribution that includes tools and drivers useful for teaching electronics.
Arch Linux
Arch Linux specifically targets ARM-based computers, so they supported the Pi very early on.
Xbian
This is a distribution based on Raspbian for users who want to use the Raspberry Pi as a media center (see also OpenELEC and Raspbme).
OtonPi
A distribution based on the Qt 5 framework.
If you’re going to get the most out of your Raspberry Pi, you’ll need to learn a little Linux. Raspbian comes with the Lightweight X11 Desktop Environment (LXDE) graphical desktop environment installed. This is a trimmed-down desktop environment for the X Window System that has been powering the GUIs of Unix and Linux computers since the 80s. Some of the tools you see on the Desktop and in the menu are bundled with LXDE (the Leafpad text editor and the LXTerminal shell, for instance).
Running on top of LXDE is Openbox, a window manager that handles the look and feel of windows and menus. Unlike OS X or Windows, it is relatively easy to completely customize your desktop environment or install alternate window mangers. Some of the other distributions for Raspberry Pi have different environments tuned for applications like set top media boxes, phone systems or network firewalls.
The real fun starts when you start programming. Although many languages are available on the Pi, I recommend playing a bit with Python. Python is a great first programming language; it’s clear and easy to get up and running. More important, there are a lot of other users to share code with and ask questions.
Guido van Rossum created Python, and very early on recognized its use as a first language for computing. In 1999, van Rossum put together a widely-read proposal called “Computer Programming for Everybody” that laid out a vision for an ambitious program to teach programming in the elementary and secondary grade schools using Python. More than a decade later, it looks like it is actually happening with the coming of the Raspberry Pi.
Python is an interpreted language, which means that you can write a program or script and execute it directly rather than compiling it into machine code. Interpreted languages are a bit quicker to program with, and you get a few side benefits. For example, in Python you don’t have to explicitly tell the computer whether a variable is a number, a list, or a string; the interpreter figures out the data types when you execute the script.
The Python interpreter can be run in two ways: as an interactive shell to execute individual commands directly from the Linux command line, or as a command line program to execute standalone scripts. The integrated development environment (IDE) bundled with Python and the Raspberry Pi is called IDLE.
So there you have it. This magnificent little device gives all the HW and SW tools you might need to play and play and play some more. Doesn’t this look much more interesting and educational than playing a video game on an Xbox? If only the kids today would get involved with something like this, then real careers would sprout from this fertile ground. America is still the land of opportunity and freedom, and it is my most sincere hope that schools around this country will realize the value of the Raspberry Pi and start building classes and clubs and organizations around this device like the old Ham Radio clubs of the 30’s and 40’s.
This is really neat stuff. Makes me wish I was a kid again. That and the pain in my right knee … didn’t have that when I was a kid either. So, happy computing and “live long and prosper."

No comments:

Post a Comment