[AN] anup narkhede

Programmer, Hobbyist, Jack of many trades, Master of some

Pi Shairport

| Comments

There are plenty of posts floating aroud to help you install and configure Airplay on a Raspberry Pi. This puppet recipe, based on shairport, simply automates the installation process for you. With just three steps, you can turn your Raspberry Pi into an Airplay speaker.

Requirements

  • Raspberry Pi running raspbian wheezy
  • SSH enabled and connected to the network

Getting started

Once the Pi is booted, note down its ip address by looking at the attached device list on your router.

Step 1: Copy your public key to the Raspberry Pi to allow ssh login without a password (optional).

cat ~/.ssh/id_rsa.pub | ssh pi@<ip-address> "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

Step 2: Bootstrap raspbian wheezy by running the following script on the Pi.

curl -sSL https://raw2.github.com/railsbob/puppet-pi_shairport/master/bootstrap.sh | sudo bash

This will install all packages required to run the puppet recipe.

Step 3: Initiate a puppet run from your machine.

git clone git@github.com:railsbob/puppet-pi_shairport.git
cd puppet-pi_shairport
./puppet-run.sh <ip-address>

That’s it! The puppet run will install shairport and configure it to run on the boot. Reboot the Pi and you should see an Airplay logo on your iTunes status bar. Select ‘Shairport on raspberrypi’ and test the streaming by connecting a speaker to the 3.5mm audio port.

Mimo USB Monitor and Raspberry Pi

| Comments

Since past few weeks, I’ve been trying to put my Mimo UM-740 touchscreen monitor to a good use. Sounds old school, but yeah we are talking about pre-ipad age when I used it as a touch screen skypephone device.

Follow this tutorial to configure the monitor as a primary display for raspberry-pi. Although I have explained the steps against Nanovision Mimo UM740, they should work with any displaylink USB monitor.

My setup:

  • 7 port powered USB hub
  • RaspberryPi running raspbian wheezy
  • Mimo UM740 touchscreen monitor
  • Ubuntu 12.04 machine for kernel compilation

Step 1: Prepare SD card

  1. Setup SD card with raspbian wheezy
  2. Boot using a standard hdml monitor
  3. Using raspi-config, enable ssh server and disable the GUI mode on startup. This will enable us to work on it without a monitor.

Step 2: Compile Kernel with udlfb support

First, we need to enable Displaylink framebuffer support in the kernel. I have followed these steps to compile the kernel on Ubuntu 12.04.

2.1: Install dependencies

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

2.2: Symlink the cross compiler

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

2.3: Checkout source code

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

2.4: Configure

cd linux
cp arch/arm/configs/bcmrpi_cutdown_defconfig .config
make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- oldconfig
#optional#make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- menuconfig

Make sure that displaylink framebuffer support is enabled:

  1. Follow ‘Device Drivers’ > ‘Graphics Support’ > ‘Support for Framebuffer support’.

  2. Enable ‘Displaylink USB Framebuffer support’ by selecting ‘M’.

2.5: Compile

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

References:

Step 3: Replace kernel.img on SD card

Once compilation is successful, package the kernel image:

mkdir ../modules
make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
cd ../tools/mkimage/
./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

This will create kernel.img in the current directory. Mount the SD card and replace existing kernel.img with the one which we just built.

Connect the monitor through a powered USB hub and reboot the pi. If everything has gone well, you should see a green screen.

Troubleshooting

Connect to ethernet & check if monitor was detected correctly:

$ dmesg | grep DisplayLink
usb 1-1.2.2.4: Manufacturer: DisplayLink
udlfb: DisplayLink nanovision MiMo - serial #USM700-8B280858
udlfb: DisplayLink USB device /dev/fb1 attached. 800x480 resolution. Using 1504K framebuffer memory

You should see two framebuffer devices, one for the hdmi adapter (fb0) and other for the USB monitor (fb1).

$ ls /dev | grep fb
fb0
fb1

Step 4: Configure Xorg

Using ssh, create /etc/X11/xorg.conf on the pi using following configuration:

Section "Device" 
  Identifier "uga" 
  driver "fbdev" 
  Option "fbdev" "/dev/fb1" 
  Option "ShadowFB" "off"
EndSection 

Section "Monitor" 
  Identifier "monitor" 
EndSection 

Section "Screen" 
  Identifier "screen" 
  Device "uga" 
  Monitor "monitor" 
EndSection 

Section "ServerLayout" 
  Identifier "default" 
  Screen 0 "screen" 0 0 
EndSection

Start the GUI mode using ‘startx’ and you are done!

Raspbmc and Wifi

| Comments

In this post, I share my experience with raspbmc and making it work with a wifi dongle. If you are looking to get rid of ethernet cable and keyboard, make the xbmc stand alone and control it using the web remote, this post is for you.

Bear in mind that not all wifi dongles have supported drivers for debian. As a safe bet, pick one from the list of verified wifi adpaters. I used Tenda W311U wireless adapter as it is well tested with debian and comes at a decent price.

To install the supported drivers, you’ll need to access the terminal on raspbmc. Follow these tips to switch between terminal and xbmc.

To Access terminal from xbmc

Click on Power icon, Exit. When the splash screen comes up, press escape. You will be shown a login prompt. Use login: pi, password: raspberry.

To Launch xbmc from terminal

%sudo initctl start xbmc

Install drivers

Once you are logged on to the terminal, update sources for aptitude and install drivers by following steps below:

%sudo nano /etc/apt/sources.list

add line:

deb http://ftp.uk.debian.org/debian/ squeeze main non-free

Then install the driver:

%sudo apt-get update
%sudo apt-get install firmware-ralink

Check device status:

%nmcli dev
=>
eth0   802-3-ethernet  connected
wlan   802-11-wireless unmanaged

Scan for wifi access points:

%nmcli dev wifi list

You should see a list of available wireless access points.

Configure the wireless network interface

Once you have the device drivers installed, you need to configure the network interface.

%sudo nano /etc/network/interfaces

Add following lines:

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa.conf

Create the wpa.conf

%sudo nano /etc/wpa.conf

Add following lines:

network={
ssid="NETWORK_SSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="NETWORK_PASSWORD"
}

Note: Replace NETWORK_SSID and NETWORK_PASSWORD with the wifi credentials.

Disconnect ethernet and run:

sudo ifdown wlan0
sudo ifup wlan0

You should be connected. Now test the connection status (ex: ping google.com).

Enable wifi connection after reboot

If you want to set the wifi as default connection after power on, follow these steps.

%sudo nano /etc/init.d/wifi.sh

add content:

#!/bin/bash
sudo ifdown wlan0
sudo ifup wlan0

Make it executable and register:

%sudo chmod +x /etc/init.d/wifi.sh
%sudo update-rc.d wifi.sh defaults 100

Every time the raspbmc boots up, it will automatically connect to the configured wireless access point.

Bye bye keyboard

Xbmc comes with a web interface, this allows us to control it without a keyboard. Just hit http://:8080/ from your ipad or laptop and start controlling. You can even use the official xbmc remotes for apple and android which are much better.

Nice, now you can have a standalone media center connected using wifi.

Raspberry Pi: Getting Started

| Comments

After a wait of over 4 weeks, I finally received my raspberry pi from RS components. This tiny motherboard comes with a great number of features for a modest price of 30£ and is already being considered as a hacker’s paradise. Getting started with Raspbian ‘Wheezy’ was simple, thanks to the quick start guide. However, I came across raspbmc, which is a minimal distribution of debian linux with xbmc pre-configured and optimized for your raspberry pi. This blog post is about my experience to get raspbmc up and running.

My setup:

  • Scandisk SD card
  • My HTC desire charger to power the board (you can even use an iPad charger)
  • HDMI to DVI-D adapter, to connect my BenQ monitor
  • Speakers
  • Ethernet cable
  • USB keyboard

Unlike Wheezy, raspbmc doesn’t come with a complete bootable OS distrubution. Instead, it provides an installer images which requires a working internet connection to download and configure the OS.

Configuring SD card with the installer is simple. Insert the SD card and run:

wget http://svn.stmlabs.com/svn/raspbmc/testing/installers/python/install.py
sudo chmod +x install.py
sudo python install.py

Proceed with the on screen instructions and select the SD card (for me it was disk1s1). Once it finishes, you’ll see a message ‘Raspbmc is now ready to finish setup on your Pi, please insert the SD card with an active internet connection.’.

Plug the SD card in the pi and power it up. It starts with downloading and installation of kernel modules & libraries, and it reboots. For some reason, the pi wouldn’t come up after the reboot. As suggested by the good eggs from internet, I replaced the bootcode.bin on the SD card with this version and then it booted properly.

Next, I was stuck at the following message:

Raspbmc Updater
Downloading a new XBMC build.. (stuck at 21%)

Turning the power off and on fixed it (Worked in the 3rd attempt).

And here’s my raspberry pi running xbmc!

Ultrasonic Range Finder

| Comments

SRF05 is an ultrasonic ranger module for arduino. Using the previously posted GLCD setup, I have built a simple range finder.

Interface

Trigger and echo pins of sensor module are connected to I/O pins 12 and 13 respectively.

Demo

Code

#include <glcd.h>
#include <fonts/allFonts.h>

int trigger = 12;
int echo    = 13;

void setup()
{
 GLCD.Init();
 GLCD.SelectFont(System5x7);
 pinMode(trigger, OUTPUT);
 pinMode(echo, INPUT); 
}

void loop(){
  int distance  = calculateDistance();
  displayOutput(distance);
  delay(100);
}

int calculateDistance(){
  digitalWrite(trigger, LOW);
  delayMicroseconds(2);
  digitalWrite(trigger, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigger, LOW);
  return (pulseIn(echo, HIGH)/58);
}

void displayOutput(int distance){
  GLCD.ClearScreen();
  GLCD.print("Distance: ");
  GLCD.print(distance);
  GLCD.print("cm");
}

Em-serialport

| Comments

I was looking for a way to send interrupts from Arduino to my macbook, without performing polling on a port. Here is a simple attempt to make it work. em-serialport is eventmachine compatible asynchronous library based on ruby-serialport.

The operation is simple. Whenever data is is available over serial port, on_data callback gets invoked. Similarly send_data writes the data on serial port.

Installation

gem install em-serialport

Usage

If you are on Mac, you need to set up a virtual USB serial port by installing a driver from http://www.ftdichip.com/Drivers/VCP.htm. Identify your serial port device. For ex: /dev/tty.usbserial-xxxxxxxx

EM.run do
  serial = EventMachine.open_serial('/dev/tty.usbserial-xxxxxxxx', 9600, 8, 1, 0)
  serial.send_data "foo"

  serial.on_data do |data|
    # you got data. Eat it.
  end
end

Serial Monitor

The gem comes with a simple command line Serial Monitor. Launch it as:

bundle exec serial-monitor /dev/tty.usbserial-xxxxxxxx

Here is a working example, tested with an https://github.com/railsbob/arduino-examples/tree/master/echo_server. It simply reads and writes data to serial port from command line.

Serial monitor initialized. Enter data followed by a newline character.
Ctrl-C to stop
hello
received: hello
A very long sentence
received: A v
received: ery long
received:  sentence

Interface LCD TM12864L With Arduino

| Comments

I bought TM12864L LCD display off ebay, however it came without any datasheet or documentation. After looking for help in forums, I was finally able to make it work. Here is a guide to interface TM12864L LCD display with Arduino Mega (1280).

Connections

GLCD Library

Once the module is wired in, you need to set up GLCD library in Arduino SDK. Follow these steps for OSX:

  • Assuming that your SDK is configured at ~/Documents/Arduino, create a folder ‘libraries’ inside Arduino folder.
  • Unzip GLCD library & move it to ~/Documents/Arduino/libraries/glcd
  • Start Arduino SDK and you should see ‘glcd’ under Sketch > Import Library > Contributed menu.

Running Examples

GLCD library comes with extensive code samples. If you have configured the library correctly, you should be able to see and compile demo examples from: File > Examples > glcd menu.

Resources