Learning, Hacking, and the Raspberry Pi
by Shea Silverman
Disclaimer: Since the release of the Raspberry Pi only a few months ago, the community has moved very fast with software updates, new releases, and better images. The current base OS at the time of this writing is Raspbian, a Debian-based distribution with settings to take advantage of the Raspberry Pi's architecture. The following is suitable for any distribution based on Debian.
What is the Raspberry Pi
The Raspberry Pi is a $35, credit card-sized, full-featured computer. It features a Broadcom ARM processor with integrated GPU, 256 MB of RAM, SD card slot for storage, HDMI and composite outputs, two USB ports, 10/100 Ethernet port, headphone out jack, and General Purpose Input/Output (GPIO) pins.
You Can't Mess Up!
As part of the learning process, I want to reiterate that it is really hard to mess this device up. If anything goes really wrong, all you need to do is re-image the SD card with a new copy of the OS. Please go crazy. This device was meant to be an educational experience. At the very worst, you'll only be out $35 and have gained a good story.
The Raspberry Pi was built as an educational device first and foremost. The Raspberry Pi Foundation is a charity that is making and selling these devices pretty much at cost. The Pi is motivated by the BBC Micro and the computer users that learned how to program on that. Installed on all the distros is a copy of the Python programming language. The community has released many modules that allow Python to access the GPIO pins and manipulate an amazing amount of hardware.
This is a full-featured computer for less than $40, one that is capable of browsing the World Wide Web, using Firefox, Chromium, or "insert-favorite-browser-here." The world is now open to those who may not have been able to afford it before. Computer labs can be outfitted for $500 rather than $15,000+. As inexpensive as PCs have become in the years, breaking the $50 mark is incredible, and can hopefully trigger more revolutions and innovation in the educational sector.
Learning to build programs on the device forced me to think through problems that I had taken for granted on the x86 side of things. While many programs are available in the repositories, you can't just download any binary and expect it to run. You need to make sure the binaries available are made for ARM processors, or that the source is available so you can build it yourself. In the few months I've had my device, I've learned how to patch code using diff files, install multiple versions of C compilers, package binaries, and even distribute them.
Let's get on to some quick hacks. A major difference with this kind of computer is the lack of a visual BIOS that most modern motherboards include. The Raspberry Pi configures itself via a text file called config.txt in /boot at power on. Numerous settings are configurable in this file, but the fun ones are regarding the overclocking of the system. Warning: Over-volting does void the warranty, overclocking does not.
- arm_freq - Frequency of the ARM processor in MHz. Default is 700.
- core_freq - Frequency of the GPU core in MHz. Default is 250.
- sdram_freq - Frequency of SDRAM in MHz. Default is 400.
- over_voltage - Adjusts the ARM/GPU voltage. Default is 0 (1.2v). Each increment is equal to 0.025v (1 = 1.225v).
The boot partition is formatted as FAT, so config.txt is editable by other devices if your Pi won't start up properly. I have found that keeping my processor at 900 MHz is perfectly stable. With overvolting, numerous users have gotten their Pis to a stable 1000+ MHz overclock.
The Raspberry Pi includes a few rows of GPIO pins that work like the pins on an Arduino micro-controller. They are generic pins that can be either input or output, and are controlled by software running on the Pi. This allows access to power, serial communications, turning on LEDs, activating motors, reading sensors, and much more. As a warning, the GPIO pins can only handle 3.3V. They do not have any power regulators so any higher voltage can fry your board.
One of my projects has been to make a fully portable computer that can be used with minimal power. The Pi itself can be powered by a few batteries, but what kind of display can I use? Enter the Adafruit 2.0" TFT LCD. It is a tiny LCD panel with a control board that can take composite input and only requires 5V to operate. GPIO pins-2 and pin-6 provide 5V and GND respectively. Plugging the display into those pins allows it to turn on and off with the Raspberry Pi.
Now on to the fun stuff! There are tons of open-source games available for the Raspberry Pi ranging from arcade classics to modern first person shooters. A major issue with gaming on the Pi is that the GPU only has support for OpenGL ES. Games not programmed for that can run under the SDL, but only with a software renderer, meaning the GPU won't be used. Applications and games are starting to get OpenGL ES support due to the proliferation of smart phones using the same architecture as the Pi.
MAME (Multi-Arcade Machine Emulator): I've been able to get AdvanceMAME to run many games from the 1980s to the early 1990s perfectly. The later-era arcade games will either not run or have massive slowdown.
MESS (Multi-Emulator Super System): A sister project of MAME, AdvanceMESS project runs many console systems including SNES, NES, GameBoy, GameGear, Genesis, etc.
Quake 2 and Quake 3: These have been ported and use OpenGL ES, so they take full advantage of the GPU and play with high frame rates.
Descent 1 and 2: Descent has an open-source port project with OpenGL ES support, and it currently runs quite well on the Pi.
PCSX: A Playstation emulator, runs surprisingly well! You won't want to use it as your primary PSX emulator, but frame rates in the 15-20 range are average for many of the games. This will only improve as development continues.
Gngeo: A Neo Geo emulator, arguably one of the greatest and longest running arcade platforms. Gngeo is a 99 percent perfect emulator that plays a ton of the Neo Geo games at full frame rate with sound. This is my favorite application for the Raspberry Pi.
Go out and buy one! Hack! Experiment! Learn Something!
Newark/Element14 (www.newark.com/raspberry-pi) is one of the faster distributors.
Download the OS image at www.raspbian.org.
Set up an emulated development environment with QEMU.
Join the community at www.raspberrypi.org/phpBB3.
View more Raspberry Pi tutorials and news, as well as download binaries at my personal site: blog.sheasilverman.com