Skip to content

Raspberry Pi Getting Started

danthemellowman edited this page Jan 6, 2013 · 64 revisions

##Getting your Raspberry Pi ready for openFrameworks:

  1. Install the latest Raspbian image, according to the instructions in the Official Quickstart Guide.

    • Make sure you are working with the the "hard float" version of wheezy (aka "Raspbian"), not the soft-float version (aka "Soft-float Debian “wheezy”).
  2. Please note if you are booting for the first time you will need to have a USB keyboard and either a HDMI Monitor or a HDMI to DVI||VGA adapter depending on your setup. Please read this guide as it contains a lot of useful information about bringing up your pi for the first time. Please select the following options from the configuration screen described in this this guide.

    • expand_rootfs, this expands the root file-system to your full SD card.
    • ssh, enable sshd at boot (if you wish to ssh into your pi instead of using a USB keyboard)
    • memory_split, you should configure the GPU/CPU memory split to be 50/50 between the GPU and CPU
    • if you already have a working pi you should do the following
    • run sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update
    • then execute the sudo rpi-update
    • edit /boot/config.txt and set gpu_mem option to gpu_mem=128 for the 256MB pi and gpu_mem=256 for the 512MB pi
    • you will need to reboot your pi after this step sudo reboot
  3. Once you are logged in to the RPI on the command line (via SSH or plugged into a screen) make sure your system is up-to-date.

    • sudo apt-get clean
    • sudo apt-get update
    • sudo apt-get upgrade
    • Note: The above steps may take a little while.
    • If you are still having issues updating apt-get run the following command then repeat the steps from above: sudo rm /var/lib/apt/lists/* -vf
    • install git: sudo apt-get install git
    • install and enable Multicast DNS (mDNS) for board to be reachable at raspberrypi.local. from machines on the same network: sudo apt-get install libnss-mdns
  4. Then clone this repo:

    • git clone https://github.com/openFrameworks-RaspberryPi/openFrameworks/
    • Note: If you want to contribute code to the this project, create your own branch and submit a pull request to the develop-raspberrypi branch of this repo.
    • Note: For purposes of discussion below, $(OF_ROOT) is will be the location of the openFrameworks root folder you created during this cloning process. (suggested root dir ~\src\openframeworks)
  5. Then move into your newly created directory ...

    • cd openFrameworks
  6. ... and checkout the master-raspberrypi branch:

    • git checkout master-raspberrypi
    • or if you want to live in the dangerzone
    • git checkout develop-raspberrypi
    • Note: The master-raspberrypi branch is our best effort at a "it was working the last time we checked" branch. master-raspberrypi is almost always a little bit behind the develop-raspberrypi branch, which is usually working, but is currently being developed at a rapid pace, so don't be surprised if you get odd errors. Either one you choose, if you find errors, please leave bug reports in our issue tracker. To use the develop branch, git checkout develop-raspberrypi.

Building openFrameworks and an oF App:

###Before We Get Started You are now entering the world of embedded linux development. You'll be using mostly bash scripts, gcc, and your preferred commandline Text Editor. It this world screen is your friend, from bash type man screen to learn more. If you are completely new to the idea of doing linux development from a command line and have no idea what a commandline Text Editor is, you're in luck we'll show you how to get started and point you in the right direction to learn more. Note: If you are a seasoned vet and use vim+regX to refactor your code move along to Installing dependencies and Compiling the openFrameworks Core

####The [Bash](http://en.wikipedia.org/wiki/Bash_(Unix_shell) Shell Bash is a command-line interpreter or shell that provides a traditional text based user interface to linux or *nix OS. If you use a Mac as your daily computer you have a bash terminal built right in, simply open Applications> Utilities >Terminal. Bash lets you run command-line applications and utilities such as mk-dir foo which makes a new directory named foo. Or you can use the copy command cp or move command mv to copy or move files or directories from one place to another Note: for copying directories you will need to use cp -R for recursive copying. You can also find out the IP address of your machine by running ifconfig from bash. This will most likely spit out something like:

pi@raspberrypi ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:ca:c2:da  
          inet addr:192.168.2.7  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:151 errors:0 dropped:0 overruns:0 frame:0
          TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:19899 (19.4 KiB)  TX bytes:10646 (10.3 KiB)

 lo       Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1104 (1.0 KiB)  TX bytes:1104 (1.0 KiB)

For compiling the the openFrameworks Core and an oF App we use gcc and GNU make. GCC or the GNU Compiler Collection dates back to the early years of computing. It is written by Richard Stallman the founder of the Free Software Foundation, GNU, Emac, and a few other things. GCC was around before Linux because you can't build the Linux Kernel without GCC and GNU make. For more information on make please read the GNU make manual or this fine tutorial.

For more information on bash and bash scripting please read this bash scripting tutorial or this bash tutorial and this wonderful pdf bash cheat sheet make a great reference.

####Picking a Text Editor While some hardcore nerds and hackers like to pick fights over text editors, there is no right answer as to which one is the best. You have many to choose from but here are 3 that work very well. nano is a very simple text editor. All of your commands are base of a control+Key style, so if control is the right place it is very easy to use. If you are first starting out I would suggest using nano. emacs is a very powerful text editor that verges on being a complete IDE or OS. We could spend weeks talking about Emacs but here is a nice tutorial to get started. You might need to run sudo apt-get install emacs if your linux image doesn't include it by default. Lastly, vim is the go to text editor for hardcore linux users. But you can be hardcore too if you want to learn this complicated beast via this interactive tutorial or this fun game.

Installing dependencies and Compiling the openFrameworks Core:

  1. First, you will need to install the dependencies and codecs oF uses using the following commands:
    • cd $(OF_ROOT)/scripts/linux/debian_armv6l
    • sudo ./install_codecs.sh
    • sudo ./install_dependencies.sh
  2. Next you need to build the core openFrameworks libraries. To do so, navigate to the $(OF_ROOT)/libs/openFrameworksCompiled/project folder on your RPI and run: _Note:this is going to take a while
    • make to build the Release library.
    • or
    • make Debug to build the debug library.
    • or
    • make -j2 which uses the jobs option in make aka make^2, Note:this lets you run concurrently compiling jobs. google: "make -j option" to learn more.

Note:This will use the new makefile system to automatically detect your system and will load the platform specific configurations found in the linuxarmv6l subfolder. This platform specific makefile is used for compiling BOTH core libraries AND compiling specific oF projects. If you are experimenting with missing features, you may need to modify that file at some point. It is very well documented (in fact all of the new makefile system is heavily commented, so feel free to look around and make suggestions!). Note: If you have the need for speed and have an Ubuntu desktop machine to spare (or VM!), see the Raspberry Pi Cross Compiling Guide.

###Compiling Your First App Currently the base makefiles are located in $(OF_ROOT)/scripts/linux/template/linuxarmv6l but now we are going to copy the following files to your home directory for easy access.

  • cd $(OF_ROOT)/scripts/linux/template/linuxarmv6l
  • cp Makefile ~/
  • cp config.make ~/

Now we are going to navigate to $(OF_ROOT)/apps/devApps folder and try out a few simple RPI apps. You'll find the following apps:

  • cd $(OF_ROOT)/apps/devApps
  • raspberrypi_hello_world
  • raspberrypi_hello_world_gles2

If the Makefiles are not present in these projets lets copy our Makefiles from our home directory into these projects and compile the projects:

Note: you should do this for any RPI apps you want to build.

  • cp ~/Makefile ./PROJECT_DIRECTORY
  • cp ~/config.make ./raspberrypi_hello_world
  • type make and follow the instructions on the screen after the successful builds.

Note: if you find any errors at this step compiling or running either raspberrypi_hello_world_gles2 or raspberrypi_hello_world please file them on github. Also note that gles2 might work better using develop-raspberrypi

After you have built your first app, play around with the examples in $(OF_ROOT)/examples some great ones are below:

  • windowExample in $(OF_ROOT)/examples/utils on develop-raspberrypi
  • openCVExample in $(OF_ROOT)/examples/addons/
  • soundPlayerExample in $(OF_ROOT)/examples/sound/
  • soundPlayerFFTExample in $(OF_ROOT)/examples/sound/

Note: Most of the above apps will require a USB Keyboard and/or USB mouse as it uses our experimental code which currently requires develop-raspberrypi. The experimental code allows for input devices and windowing outside of X11 on the Raspberry Pi so if you find any errors with the above apps please file them on github.

To run other examples or try out your own program, for the moment we recommend copying the raspberrypi_hello_world example. In the future, a command line or GUI projectGenerator will make this easier. Note: If you are a developer, please take a look at the config.make file and the addons.make files in the project directory. ##Notes: For doing development on your pi from OS X via SSH you should perform the following steps:

  • On your Raspberry Pi enable sshd to start at boot
  • On your Mac from Finder select Apple>System Preferences>Sharing>Internet Sharing
  • Check Internet with 'Share Your Connection from: WiFi' and 'To Computers Using: Ethernet'
  • Plug an ethernet cable from your Raspberry Pi into your Mac
  • Restart your Raspberry Pi

OSX uses the range 192.168.2.2-254 as its DHCP range for devices connected via the ethernet jack your pi will probably be 192.168.2.2 but it could be 192.168.2.7You might have to run nmap to find the IP of your pi if you do not have a USB keyboard handy nmap -v -sP 192.168.2.2-254 should do the trick

If you have enabled mDNS (see above) or are using an earlier version of Raspbian with mDNS pre-enabled, the board will be reachable at raspberrypi.local. (or raspberry.local.) and you can SSH with the username pi: ssh [email protected].

If you haven't enabled mDNS open terminal and run the SSH command ssh [email protected] if everything went well you should be presented with a password prompt.