topamax once a day

Raspberry Pi + OpenCV

OpenCV is a suite of powerful computer vision tools. Here is a quick overview of how I installed OpenCV on my Raspberry Pi with debian6-19-04-2012.  The guide is based on the official OpenCV Installation Guide on Debian and Ubuntu. Before you begin, make sure you have expanded your SD card to allow for the install of OpenCV. Its a big package with lots of dependencies. You can follow my instructions here.  Once you have expanded the SD card, open up a terminal and install the following packages:

UPDATE: You can execute the following steps with a simple call to the Ansible playbook playbook-opencv. Note that you have to edit the pis.yml file with your pi ip address and update group_vars/pis.yml with your pi password.

git clone https://github.com/chrismeyersfsu/playbook-opencv.git
ansible-playbook site.yml -i pis.yml -vvvv

Note: The make command will take HOURS to run. Please be patient.

sudo apt-get -y install build-essential cmake cmake-qt-gui pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools

 

sudo apt-get -y install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev pkg-config

There are some dependency issues with the order of the install, mostly with regard to libjpeg issues, so be sure to install in this order. You will see some broken package errors if you attempt to install all the dependencies in one step.

Next, pull down the source files for OpenCV using wget:

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2

Once finished downloading, extract the archive, remove the no longer needed archive (to save space), change directory to the top of the source tree, make a directory for the build, and change into it:

tar -xvjpf OpenCV-2.3.1a.tar.bz2

rm OpenCV-2.3.1a.tar.bz2

cd OpenCV-2.3.1/

mkdir build

cd build

Next, you will need to configure the build using cmake. If you aren’t sure about what options you want/need or are unfamiliar with cmake, this line will create a standard configuration:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

Alternatively, you can configure the build using a GUI interface. This can be helpful to build with support for additional OpenCV features. To use the cmake GUI, run:

cmake-gui ..

In the cmake GUI, click ‘configure’ to pre-populate the build options. Select or remove any desired features, then click ‘configure’ again, check the output and ensure that there are not any modules that cmake cannot find. If everything looks good, click ‘generate’ to create the makefiles, then close cmake-gui. Now we are ready to start the build! To compile, run make, then install with make install:

make

sudo make install

As you can see from the image, this will take a LONG time… over four and a half hours to compile!

Finally, we need to make a few configurations for OpenCV. First, open the opencv.conf file with the following code:

sudo nano /etc/ld.so.conf.d/opencv.conf

Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

/usr/local/lib

Then edit the system-wide bashrc file:

sudo nano /etc/bash.bashrc

Add the following new lines to the end of the file:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH

Now that everything is installed and configured, on to the demos!  The C demos are here:

cd ~/opencv/OpenCV-2.3.1/build/bin

C demos in build/bin demos worth checking out (that don’t require a webcam):

convexhull

kmeans

drawing

The python demos are located in samples/python:

cd ~/opencv/OpenCV-2.3.1/build/bin

These demos also don’t require a webcam:

python ./minarea.py

python ./delaunay.py

python ./drawing.py

 

 

Raspberry Pi Root FS on USB Drive

This tutorial will demonstrate how to install the Debian root filestem (ie. ‘/’) on a USB drive instead of the SD card. The SD card still retains the /boot partion and swap space. This requires a modified kernel to support the USB storage. You can download the minimal modified kernel and modules here  or follow my guide on how to compile it for yourself.

In either case, begin by installing the Debian image as you normally would to an SD card. Manually format the USB drive you intend to use as the root filesystem as ext4 using a utility like gparted.

Next, copy the root filesytem from the Debian install on the SD card to the USB drive, preserving attributes with the -a flag, substituting “sdcard-rootfs-partition-uuid” and “usbdrive-rootfs-partition-uuid” with the respective identifiers as the filesystem are mounted in Ubuntu.

sudo cp -a /media/sdcard-rootfs-partition-uuid/* /media/usbdrive-rootfs-partition-uuid/

sync

Now, delete the existing kernel.img and replace it with the new one, substituting “sdcard-boot-partition-uuid” with the identifier of the partion as it is mounted in Ubuntu.

sudo rm /media/sdcard-boot-partition-uuid/kernel.img

sudo mv kernel.img /media/sdcard-boot-partition-uuid/

Next, remove the existing /lib/modules and lib/firmware directories,

sudo rm -rf /media/usbdrive-rootfs-partition-uuid/lib/modules/

sudo rm -rf /media/usbdrive-rootfs-partition-uuid/lib/firmware/

and copy the new modules and firmware in their place:

cd ../../kernel/

sudo cp -a lib/modules/ /media/usbdrive-rootfs-partition-uuid/lib/

sudo cp -a lib/firmware/ /media/usbdrive-rootfs-partition-uuid/lib/

sync

Now we need to modify the location of the root partition in the /boot partion. This is contained within the file, cmdline.txt. In this file, change:

root=/dev/mmcblk0p2

to:

root=/dev/sda1

That’s it! Plug in and boot up the root filesystem from the USB stick!

 

Raspberry Pi Kernel Compile

This tutorial will demonstrate how to cross compile the kernel for the Raspberry Pi on Ubuntu 12.04 LTS. The kernel is functional with both the Debian and Arch Linux Raspberry Pi images.

UPDATE: Alternatively, you can use the following Ansible playbook playbook-raspi_kernel_crosscompile. Note that you have to edit host_vars/localhost.yml file with your local sudo password.

git clone https://github.com/chrismeyersfsu/playbook-raspi_kernel_crosscompile
ansible-playbook -i localhost.yml site.yml -vvvv

First, install the package dependencies, git and the cross-compilation toolchain:

sudo apt-get install git-core gcc-4.6-arm-linux-gnueabi

Create a symlink for the cross compiler:

sudo ln -s /usr/bin/arm-linux-gnueabi-gcc-4.6 /usr/bin/arm-linux-gnueabi-gcc

Make a directory for the sources and tools, then clone them with git:

mkdir raspberrypi
cd raspberrypi
git clone https://github.com/raspberrypi/tools.git
git clone https://github.com/raspberrypi/linux.git
cd linux

Generate the .config file from the pre-packaged raspberry pi one:

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig

If you want to make changes to the configuration, run make menuconfig (optional):

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig

Once you have made the desired changes, save and exit the menuconfig screen. Now we are ready to start the build. You can speed up the compilation process by enabling parallel make with the -j flag. The recommended use is ‘processor cores + 1′, e.g. 5 if you have a quad core processor:

make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k -j5

Assuming the compilation was sucessful, create a directory for the modules:

mkdir ../modules

Then compile and ‘install’ the loadable modules to the temp directory:

make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/

Now we need to use imagetool-uncompressed.py from the tools repo to get the kernel ready for the Pi.

cd ../tools/mkimage/
./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

This creates a kernel.img in the current directory. Plug in the SD card of the existing Debian image that you wish to install the new kernel on. Delete the existing kernel.img and replace it with the new one, substituting “boot-partition-uuid” with the identifier of the partion as it is mounted in Ubuntu.

sudo rm /media/boot-partition-uuid/kernel.img
sudo mv kernel.img /media/boot-partition-uuid/

Next, remove the existing /lib/modules and lib/firmware directories, substituting “rootfs-partition-uuid” with the identifier of the root filesystem partion mounted in Ubuntu.

sudo rm -rf /media/rootfs-partition-uuid/lib/modules/
sudo rm -rf /media/rootfs-partition-uuid/lib/firmware/

Go to the destination directory of the previous make modules_install, and copy the new modules and firmware in their place:

cd ../../modules/
sudo cp -a lib/modules/ /media/rootfs-partition-uuid/lib/
sudo cp -a lib/firmware/ /media/rootfs-partition-uuid/lib/
sync

That’s it! Exject the SD card, and boot the new kernel on the Raspberry Pi!

 

WordPress on Raspberry Pi

This tutorial will demonstrate how to install and host WordPress on Raspberry Pi. This process assumes you have Debian for Raspberry Pi installed on an SD card. If not, see RPi Easy SD card setup.

Install Apache

WordPress runs on the Apache2 web server. To setup Apache, follow the instructions in my previous post, Raspberry Pi and Apache.

Install MySQL and PHP

Begin by installing the required dependencies. From a terminal:

sudo apt-get install mysql-server-5.5 php5 php5-mysql php5-gd

Next run the MySQL init script:

sudo mysql_install_db

Download and Extract WordPress

Download the latest wordpress source files

wget http://wordpress.org/latest.tar.gz

Extract the downloaded archive:

tar -xvzf latest.tar.gz

Create a directory in /var/www for the WordPress install:

sudo mkdir /var/www/wordpress

Copy over the extacted files:

sudo cp -r ~/wordpress/* /var/www/wordpress

Configure Apache

Next, make a backup of the apache config file, then open it in a text editor:

sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf.bak
sudo vim.tiny /etc/apache2/apache2.conf

Add this line to the end of the file:

AddType application/x-httpd-php .html

And restart Apache

sudo /etc/init.d/apache2 restart

Configure MySQL

The next step is to configure MySQL for use with WordPress. WordPress needs a database and user, and permissions set correctly for access. Start the mysql config:

mysql -u root -p

Enter the root MySQL password, then arrive at the mysql prompt

mysql>

Create a database for WordPress, create a user for the database, and set password set the permissions:

CREATE DATABASE wordpress;
CREATE USER wordpressuser;
SET PASSWORD FOR wordpressuser= PASSWORD(“1234”);
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser IDENTIFIED BY ‘1234’;
FLUSH TABLES;

Then quit the MySQL client:

exit

Now create a new wordpress configuration based on the sample:

sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

And open it up for edit in an editor:

sudo vim.tiny /var/www/wordpress/wp-config.php

Change this:

/** The name of the database for WordPress */
define(‘DB_NAME’, ‘database_name_here’);

/** MySQL database username */
define(‘DB_USER’, ‘username_here’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘password_here’);

to this (substituting password_here with your own from above):

/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress’);

/** MySQL database username */
define(‘DB_USER’, ‘wordpressuser’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘password_here’);

Finalizing the install

The hard part is over! Now open up a browser and head to the site and finalize the install. To do this, navigate from a browser on another machine on your local network, only substitute the local address of the Raspberry Pi. To find the address of the Raspberry Pi, open a terminal and run:

ifconfig

Then navigate to that address with a trailing /wordpress from a browser on the same local network:

http://192.168.1.100/wordpress

 

Raspberry Pi + Apache


Its quite easy to install the Apache web server on the Raspberry Pi. This process assumes you have Debian for Raspberry Pi installed on an SD card. If not, see RPi Easy SD card setup. Open a terminal (or login via SSH) and install the package with apt-get:

sudo apt-get install apache2

UPDATE: 9/18/12: The following group creation error appears to have been corrected in an updated package and should no longer be necessary.  

However, the install will not complete successfully:

Setting up apache2-mpm-worker (2.2.16-6+squeeze7) …
Starting web server: apache2apache2: bad group name www-data
Action ‘start’ failed.
The Apache error log may have more information.
failed!
invoke-rc.d: initscript apache2, action “start” failed.

While the errors suggests that the Apache error log may have more information… it does not! However, bad group name is a clue. For some reason, apache user www-data gets created correctly, but the apache group does not. This is corrected by the following actions:

sudo addgroup www-data
sudo usermod -a -G www-data www-data

And then restart the apache web server:

sudo /etc/init.d/apache2 restart

That’s it! You can confirm that it is working by opening a browser and navigating to the web server root. To do this locally on the Raspberry Pi, open up a web browser such as Midori, the pre-installed browser on the Debian image, and navigate to:

http://127.0.0.1/

Alternatively, navigate from a browser on another machine on your local network, only substitute the local address of the Raspberry Pi. To find the address of the Raspberry Pi, open a terminal and run:

ifconfig

Then navigate to the corresponding IP address of the Pi.

 

Easy GUI Install & Re-Partition Raspberry Pi on Ubuntu

Easy Install & Resize the SD Card on the Raspberry Pi on Ubuntu.

First, open a terminal and install the ImageWriter and GParted utilities with apt-get

sudo apt-get install usb-imagewriter gparted

Assuming you are starting with a fresh install, download the newest release from the Raspberry Pi download site:

http://www.raspberrypi.org/downloads

Extract the downloaded archive, and then open ImageWriter:

imagewriter

Select the desired .img file and target device, in this case, debian6-19-04-2012.img, and /dev/mmcblk0

 

Once the image write has completed, the next task is to repartition the SD card.  Note: this process can be done at any later as well, it is not limited to only during initial setup!  In any case, open a terminal, and start Gparted:

sudo gparted

The screen will display the current partition layout on the SD card, notably how much extra space is currently unused, in this case, almost 2GB.

The first step is to delete the swap partition at the bottom of the table  To do this, right click partition 3 (/dev/mmcblkp03) and select delete.  Notice that the operations pending section now displays this change.

Note: If the partitions are locked, they will need to first be unmounted before they can be modified.  To do so, right click on the partition, and select ‘unmount’ (Thanks Anand).

Now, right click partition 2 (/dev/mmcblkp02) and select resize/move.  A pop-up will allow you to configure the partition:

Expand the partition, leaving free space at the end to be used for swap (512 MB below).  Make sure the 1 MB free space preceding doesn’t change, and select None in the Align to box:

Click the Resize/Move button, and you will return to the main screen.  Notice that the operations pending now also shows the grow operation.  Note:  If this displays move and grow, instead of just grow, cancel the operation and try again.

Now we create the swap partition at the end. Right click on the remining unallocated space, and click new.  Expand the partition to fill the maximum available space, and set the file system type to linux-swap:

Click add, and return again to the main screen, which now displays all three pending operations:

If everything looks good, click the checkmark in the header bar to apply the changes, and confirm the pop-up warnings.  Once finished, you will see the final result:

Close out of GParted, and eject the SD card.  It is already unmounted from the partitioning operation. Enjoy the extra space on your Raspberry Pi!

 

Ralink/Realtek Wireless Dongle (rt3070) on the Raspberry Pi

Realtek WiFi dongle

Realtek WiFi dongle

Scenario

You have a HAWKING HWUN3 Hi-Gain Wireless Adapter dongle that you want to use on your Raspberry Pi running debian.

Note: the same set of steps will probably work for other variations of Ralink/Realtek wifi dongles [rt2561,rt2661,rt2860,rt2870,rt3070,rt3071,rt3090].

The Problem

The standard release (debian6-19-04-2012.zip) contains the needed drivers however, the firmware needed is not included. The following tutorial will describe how to get and “install” the needed firmware.
You will notice the firmware problem if after plugging in your wifi dongle you type dmesg and it complains about not being able to find the firmware.

dmesg

usb 1-1.2: USB disconnect, device number 4
usb 1-1.2: new high speed USB device number 6 using dwc_otg
usb 1-1.2: New USB device found, idVendor=0e66, idProduct=0013
usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1.2: Product: 802.11 n WLAN
usb 1-1.2: Manufacturer: Ralink
usb 1-1.2: SerialNumber: 1.0
cfg80211: Calling CRDA to update world regulatory domain
usb 1-1.2: reset high speed USB device number 6 using dwc_otg
ieee80211 phy0: Selected rate control algorithm ‘minstrel_ht’
Registered led device: rt2800usb-phy0::radio
Registered led device: rt2800usb-phy0::assoc
Registered led device: rt2800usb-phy0::quality
usbcore: registered new interface driver rt2800usb
phy0 -> rt2x00lib_request_firmware: Error – Failed to request Firmware.
phy0 -> rt2x00lib_request_firmware: Error – Failed to request Firmware.
phy0 -> rt2x00lib_request_firmware: Error – Failed to request Firmware.
phy0 -> rt2x00lib_request_firmware: Error – Failed to request Firmware.

The Solution

To fix the described problem we need to make the firmware available to the system by placing it in /lib/firmware/. How do you know if the solution provided works or not? The kernel will continually complain about not being able to find the firmware. Then, when the firmware is found, the kernel will stop complaining. You can monitor the complaints with the tail command.

Execute lsusb after you have inserted the wireless usb dongle to get more information about your device.

lsusb

Bus 001 Device 006: ID 0e66:0013 Hawking Technologies HWUN3 Hi-Gain Wireless-N Adapter [Ralink RT3070]
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 005: ID 413c:2003 Dell Computer Corp. Keyboard
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Ensure that the kernel you are running has loaded the required modules.

lsmod

Module Size Used by
arc4 764 2
rt2800usb 9148 0
rt2800lib 37652 1 rt2800usb
crc_ccitt 932 1 rt2800lib
rt2x00usb 6532 1 rt2800usb
rt2x00lib 25780 3 rt2800usb,rt2800lib,rt2x00usb
mac80211 171628 3 rt2800lib,rt2x00usb,rt2x00lib
cfg80211 123084 2 rt2x00lib,mac80211
fuse 49036 1
evdev 6404 1
joydev 7576 0

Monitoring the status of the firmware fix.

tail -f /var/log/syslog
or
tail -f /var/log/messages

Acquiring and installing the firmware.

sudo apt-get install git-core
git clone http://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git
cp linux-firmware/rt2870.bin /lib/firmware/rt2870.bin