Raspberry Pi Slideshow

Wanting to do something productive with my Raspberry Pi, I decided to at least get it showing me new art each day. As it turns out… its a little more challenging than I had originally expected. The main reason was resources on the Pi. Many image viewers, both command line and x windows based like to do some crazy things that tend to blow up the memory consumption on my Raspberry. As a result, the kernel will, in turn, enjoy killing the offending process. The following is how I overcame the challenges.

The Equipment:
Raspberry Pi running Raspbian “wheezy” on a 4GB SD Card
HDMI Monitor
An Internet connection

The Overview:
The idea is to get updated images from Deviantart nightly and display them via slide show over the course of the day.

The Steps:
With a fresh install of Raspbian I booted up the Pi. The initial wizard gives you a few options, here is what I did.
1. Expand the root partition to fill the SD Card
2. Changed the keyboard to the US layout
3. Changed the timezone to reflect where I live
4. Changed the boot into desktop to yes (meaning it will start the desktop after boot).
5. As a matter of security, I also updated the password for the pi user.

Reboot the Pi and you should find yourself looking at the desktop once you log in.

Add Auto Login:
You can skip this part if you don’t want to auto login, it wont affect the outcome unless you reboot your machine.
Making this as automated as possible, we need to set up the Pi to auto login the pi user. Here’s how we do that.

Edit /etc/inittab using vi. Of course vi is just my preferred text editor, feel free to use your own favorite. I’ve heard quite a few people like nano.

sudo vi /etc/inittab

Scroll down till you see the following line:

1:2345:respawn:/sbin/getty --noclear 38400 tty1

Comment it out by adding a pound sign (#) in front of it. Insert a new line and add the following.

1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

Your file should now look something like this:

#1:2345:respawn:/sbin/getty --noclear 38400 tty1
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

NOTE: If your using a user different than ‘pi’ you will want to change the user, pi, to your user.

Close and save the file.

Go ahead and reboot your Pi just to make sure your changes have properly taken affect.

sudo shutdown -r now

Update and Install pqiv
Once the machine comes back up, it should automatically boot you into LXDE (the default desktop environment). Go ahead and open a terminal window and update the apt-get repository.

sudo apt-get update

Normally we would issue a simple apt-get install pqiv to install pqiv; however, due to issues with version in the raspbian repository we will need to download, fix, compile, and install pqiv manually. Don’t forget to remove pqiv if you’ve already installed it at some point.

sudo apt-get remove pqiv

Install git and the dependency gtk2 library for pqiv.

sudo apt-get install git libgtk2.0-dev

We have what we need to build the application, now we need to download the source.

cd
git clone https://github.com/phillipberndt/pqiv.git -b 0.12

Now that you’ve downloaded the pqiv source, you will notice a new directory in your home directory called pqiv. Go into this directory and run ./configure to validate all preconditions are met and create a platform specific make file.

cd pqiv
./configure

Now we need to fix the source code by replacing the gchar option; with gint option; in the main() function in the pqiv.c file. The line we are looking for is around 2233.

/*gchar option;*/
gint option;

Save and exit vi. Now you’ve fixed the bug, we will run make and install the application.

sudo make all install

You now have the fixed version of pqiv running on your Pi.

Get the slide show images:
Now we need to create the process to download the images from Deviant art. To do this, first create a directory in your home directory. Open a terminal session and type in the following commands.

cd
mkdir images
mkdir scripts
cd scripts

Now we need to create the script to get the images from DeviantArt. Create a new file in the scripts directory.

vi ~/scripts/get_images.sh

Inside the script copy and paste the following code.

NOTE: Updated wget line to adapt to the change in RSS format from Deviantart.

#!/bin/bash

cd /home/pi/images

rm *.jpg *.png

# go get the files
#landscape files
wget -q -O- "http://backend.deviantart.com/rss.xml?q=boost%3Apopular+in%3Adigitalart%2Fpaintings%2Flandscapes+max_age%3A72h&type=deviation" | grep -o '<media:content url="[^"]*' | grep -o '[^"]*$' | xargs wget -c

FILES=/home/pi/images/*
count=0
one=1

for f in $FILES
  do
    file -b $f
    echo "Checking file number $count"
    count=$(($count + $one))
    if [ "$(file $f|grep JPEG)" ]; then
      mv ${f} $RANDOM.jpg
    elif [ "$(file $f|grep PNG)" ]; then
      mv ${f} $RANDOM.png
    elif [ "$(file $f|grep ASCII)" ]; then
      echo ”Skip Script file”
    else
      echo "unknown file type $f"
    fi
  done
Once you've added the script, save your file and make it executable.
chmod +x ~/scripts/get_images.sh

Just to be sure your script is working execute it via the command line.

cd ~/scripts
./get_images.sh

So… whats this script do you might ask? For starters, using wget, it reaches out and pulls down images from DeviantArt via their RSS feeds. Using grep and sed we save the resulting downloaded file to the images directory. The second part of the script looks at all the files downloaded (some of them end up not being images) and gives them random file names. These random file names are what make the slide show seem a little more “random”.

But we want this pull to be a automated. To do this we add the script to cron. To edit cron:

crontab -e

And then add the following line at the end of the file.

00 01 * * * /home/pi/scripts/get_images.sh > /home/pi/get_images.log 2>&1

The line above kicks off your script every night at 1:00 am and outputs both output and error to a log file in the home directory of pi. (this is really only to help with troubleshooting if needed).

Slide show Image Swapping
Next we need to create a set of scripts to refresh the slide show file and make sure the slide show continues to run.

First up is a really simple script to continually refresh the slide show image. Create a new script file in your scripts directory.

cd ~/scripts
vi update_slideshow_image.sh

Copy and paste this script into your new file.

#!/bin/bash

cd /home/pi/images
while true;
  do for i in *;
    do cp $i /home/pi/slideshow.jpg;
      echo $i;
      sleep 30;
    done;
  done

Save your file and make it executable.

chmod +x update_slideshow_images.sh

Here is a quick outline of what the above script does.

It first changes its current directory to the images directory. Once there, it goes into an infinite loop. Once inside the loop it gets a list of files from your images directory. It then copies the first file to your home directory calling the file slideshow.jpg. The script then waits 30 seconds and then copies the second file, overwriting the existing slideshow.jpg with this new one. The script will do this for each file until it goes through all of them. Then it starts from the begging and does it all over again. At 1:00 am the get_images script will download a new set of images and because the update_slideshow_image get a new file list each time it loops, these new files will get added to the list to be displayed. This may not make much sense now, but it will after in a moment.

Using pqiv to display images:
Now we need to create the script to display the images.

cd ~/scripts
vi start_slideshow.sh

Copy and past this script into your new file.

#!/bin/bash

# Lets start and restart the slideshow if needed
until /usr/bin/pqiv -i -f -s -w /home/pi/slideshow.jpg; do
  echo "Slideshow crashed with exit code $?. Restarting..." >&2
  sleep 2
done

Save your script and make it executable.

chmod +x start_slideshow.sh

This script is really quite simple. Most of the actual slide show work is done by pqiv. This script’s only duty is to kick off pqiv. If the program crashes the script will echo the reason it crashed and then wait a few seconds before restarting the slide show. Why do I do this you might ask? Memory resources on a Raspberry Pi are limited and image viewing software isn’t all that great at being memory friendly, especially when trying to load larger files, scale them, and then display them. Do that over a hundred times and you will quickly get killed by the kernel.

As a side note, I tried several other image viewing programs like fbi, fim, and feh. While they worked, they each had some small issues and more importantly, they were not fond of refreshing the image when the underlying file changed.

Autostart the slide show:
To have our slide show kick off automaticly once the Pi reboots. To do this we need to add two .desktop files to autostart. One file will run our update_slideshow_image script that the other will run the start_slideshow script.

Here is how you create the first file.

cd /etc/xdg/autostart
sudo vi slideshow_image_changer.desktop

Inside this file add the following.

[Desktop Entry]
Type=Application
Name=Slideshow Image Changer
Comment=Slideshow Image Changer
Exec=/home/pi/scripts/update_slideshow_image.sh
Terminal=true

Save this file and create the second file.

sudo vi slideshow_start.desktop

Add the following to this new desktop file.

[Desktop Entry]
Type=Application
Name=Slideshow Image Changer
Comment=Slideshow Image Changer
Exec=/home/pi/scripts/start_slideshow.sh
Terminal=true

Save and close this file.

Prevent the Raspberry from going to sleep:
We are almost done… one thing that drove me nuts for a little while was how the Raspberry would occasionally turn off the monitor. I couldn’t really narrow down what I did to fix the issue. I updated the following config settings and they seem to work as expected.

Update the kbd config file.

sudo vi /etc/kbd/config

Scroll down till you see the BLANK_TIME setting and change it to 0.

# screen blanking timeout. monitor remains on, but the screen is cleared to
# range: 0-60 min (0==never) kernels I've looked at default to 10 minutes.
# (see linux/drivers/char/console.c)
#BLANK_TIME=30
BLANK_TIME=0

Scroll down a little more till you see the POWERDOWN_TIME setting and change it to 0

# Powerdown time. The console will go to DPMS Off mode POWERDOWN_TIME
# minutes _after_ blanking. (POWERDOWN_TIME + BLANK_TIME after the last input)
#POWERDOWN_TIME=30
POWERDOWN_TIME=0

Save and close the config file.

Next I ended updating the lightdm.conf file.

sudo vi /etc/lightdm/lightdm.conf

Scroll down till you see the [SeatDefault] section and add a line towards the end of it.

xserver-command=X -s 0 dpms

My screen no longer goes blank and I have the pleasure of having a dynamic slide show all day.

Reboot your Raspberry Pi. Provided everything goes as planned, your slide show should start shortly after booting into the LXDE desktop… congratulations!

LED mod for 2012 Ninja Instrument Cluster

Over the weekend I decided to update the LEDs in my instrument cluster. I have a green 2012 650 and I liked the factory white back lighting but I thought it would be cool to have a green tachometer needle and green speed display. I had seen people do a complete replacement of the 09-11 clusters and that look easy enough… Man was I in for a surprise! The new instrument cluster was completely redesigned for the 2012 model and the new assembly provides a new set of challenges.

  1. Disconnect the battery.
  2. Remove the “meter unit” as its called in the service manual. This was easy, simply remove the upper inner fairing and the three mounting screws.
  3. Once the unit is removed from the bike remove the inner circuit board from the housing (four black screws on the back and four silver screws on the inside.)
  4. Very carefully remove the tach needle. I used a fork and slowly wedged it up under the button. With a little convincing it popped off.
  5. WARNING: According to the service manual you should not leave the board upside down (gauges facing down) for any length of time. There is a good chance the unit will later malfunction.
  6. Flip the board upside down (yea I know I just told you not to) and remove the solder from the pins holding the display to the board.
  7. Carefully separate the display and circuit board making sure not to bend any of the display pins.
  8. Remove and replace the desired LEDs. I bought OSRAM LTT68C Green LEDs from ebay for $1 shipped. For this project I only used four. (I’m now looking for more places to add green LED lighting).

    Make sure you solder the LED’s back in the same way you took them out.
    The LED’s have a little notch in one corner and that should be soldered in opposite the “A” on the board (see the white arrow below). Here is a closeup of the stock LED (white and yellow) and the new green one (white and black).
  9. Here’s a photo of the LED’s I replaced (the green ones).
  10. To reassemble the unit make sure you have all of the LCD display pins firmly soldered back to the board.
  11. The tach has a “stop” point when turned all the way to the left. Make sure you turn the gauge all the way to the stop point and then push the needle back onto the pin with the needle pointing to zero. I thought i did this and the first time it ended up being about 300 rpm off.
  12. Here is a photo with the garage door closed and lights out. The photo really doesn’t do it justice because at night the green shows up much brighter.

    Start to finish the project took about 4 hours. Most of that time is attributed to cleanly removing all of the solder to separate the display from the circuit board.

2012 Ninja Fender Mod

The new-ness of my bike has worn off and I’ve started modifying it a bit to make it “my own”. I recently posted my Garage Door opener mod. I recently had a bit more time so I decided to mod my fender, using all factory parts. Here are the before and after photos:

The great thing about this mod is, besides a little time, I didn’t spend a dime. With a hacksaw you too can mod your fender and save some coin.

  1. Remove the fender.
    • The fender on the 2012 Ninja is held on by three bolts and one screw (why, I have no idea)
  2. Now that you have the fender off, strip it down to the core structure leaving an elephant like looking object.
  3. I wanted to retain the tie down loops because my bike didn’t come with the grab handles (none of the 2012′s did). As a result I hacked off the bottom of the fender support after the loops.

    Here is what the support looks like on the bike without the lights or plates.
  4. The brackets that are welded to the tie downs have a bolt hole in them where the plastic factory fender was bolted. Using a little of the stock plate from underside of the stock fender I cut out L brackets. I then used these to mount the turn signals to the fender support.
  5. I reused the license plate holder and using the space between the tag and inspection sticker I drilled a hole large enough to mount the license plate light (facing up onto the plate).
  6. All of the wiring was re-run up through the support and under the seat where it all plugged back in with no issues.
  7. Here is the modified fender prior to mounting back up to the bike.

The whole process took about 5 hours simply because I was learning as I went. Thinking back on it I bet it would only take an hour or two depending on your skill with a hacksaw, hammer, and drill. Here are a few pics of the fender on the bike.

2012 Ninja Fender Eliminator Mod for $0

The new-ness of my bike has worn off a little. Its now time to start modifying it a bit to make it “my own”. I recently posted my Garage Door opener mod. This weekend I had a bit more time so I decided to make my own fender eliminator using all factory parts. This is what it looked like before I started cutting bits off:

Here is the end result:

The bracket holding on the factory fender is actually quite sturdy and has some nice tie-down hooks and I didn’t want to loose those, I carry stuff on my back seat from time to time. As a result I hacked off the bracket right after the hooks.

Then, I used the factory license plate bracket to attach the plate to the fender bracket. The license plate light from the factory fender is attached directly to the plate frame between my inspection sticker (required in Texas) and the frame. I used some of the left over parts from the original fender to make little L brackets for the turn signals and mounted them above the tie-down hooks. All of the wires are routed back up under the bracket and under the seat.

Granted, its not as cool as simply NOT having a license plate but its still MUCH better than the factory fender.

Adding Garage Door Button To A Motorcycle

I’ve heard of people using the Flash to Pass button as a garage door opener but when I went to hook that up, my remote didn’t like the switch (meaning it was using an open loop or something). At any rate, I switched gears and managed to “make” a switch using the turn signal button. Here is a pic of the “switch”.

The yellow wire is connected to the button that when pushed in (canceling the turn signal) makes contact with the lead from the white wire, completing the circuit. The gold little bracket holds the white wire in place.

The actual garage door remote is zip-tied up under the instrument cluster and the wire is fed up through the wiring harness. It’s works great and makes pulling into the garage super easy because I don’t have to dig around in my pocket looking for the remote.

Building a sensor mount for the ar.Drone

Parrot’s ar.Drone is a wonderful platform to tinker with. Despite being built to be sold to the masses, the Linux OS coupled with directions from MAPGPS and his ardudrone project. You too can easily expand on the features and functionality of what your drone can do for you.

I’ve set a goal to convert my drone to an autonomous UAV that has the smarts to avoid objects while on its predetermined routs. To do this I needed a mounting platform for the array of ultrasound sensors. My fist attempts at creating a modified outdoor shell failed in brilliant ball of foam!… well okay box of foam.

My second attempt was to make something simple and spacious with an ease of use for multiple types of sensors and storage space. I give you the Multi-Directional Sensor Mount.

ar.Drone_Sensor_Mount_v2

The idea is actually quite simple. You have a flat mounting surface facing all of the required directions if you have something like a wide angle ultrasound sensor (which I will be adding shortly).

I designed the hexagon so when the drone hovers the sensors will be level. Of course you can modify the design, slope, and size to fit your every need. I’ve added the template so you too can start adding great things to your drone.

Drone_Multi-Directional_Mount_v2_template

Click me to download the template.

Next steps are to wrap the hexagon with plastic to build a tough shell. I plan on using a 3 liter bottle and a heat gun.

Arduino hooked up to Graphic LCD (vk5121)

I’ve had this Graphic LCD sitting in the bottom of my “cool parts” drawer for a while. When I picked up my Arduino Uno the first thing I did was pull out my cool parts and start getting to know them again. I’ve never been able to properly get the LCD working when using the Basic Stamp but thought I would give it another try.

 

The vk5121 GLCD is made by Altronix and is 120 pixels wide by 32 pixels high. This module uses 2 sed1520 chips each controlling one half of the display. It also contains an onboard contrast pot along with a high voltage blue elctroluminescent backlight with onboard high voltage power supply. The backlight can be turned on/off via EL control pin. This Display is very easy to hook up as it needs no additional components. The backlight can be hardwired on, off, or can even be controlled by a AVR Pin. The pixels are slightly taller than they are wide (0.42mm x 0.53mm) so that things like circles may look slightly squished. The datasheet was a little more difficult to find. To save you the trouble I’ve saved it here.

Wiring the module to the Arduino turned out to be a bit more involved than any of the LiquidCrystal examples provided with the Arduino software. Because each side of the display is controlled by sed1520 chips you end up using all 16 leads, leaving only 4 pins on the Ardunio Uno for expansion.

Here is the wiring diagram, notice it uses all 8 data pins (db0 – db7) as well as both Enable pins (e1 & e2).

After connecting the wires, here is a photo of the module connected to my Arduino.

With the backlight wired to pin 13 to turn it on and off.Once the module was properly wired up, I needed to figure out how to control it. This is where the glcd-ardunio library comes into play. My hats go off to Michael Margolis, and Bill Perry. They’ve built an Ardunio Graphic LCD (glcd-arduino) library that easily integrates in your existing Arduino Library structure. Simply download the file and add it to your ardunio_install_folder/libraries folder. Highlights of the library include support for additional glcd chips, support for all Arduino print methods, user definable scrolling text areas, as well as a new method of configuring i/o pins that is much simpler and allows any AVR pin to be assigned to any glcd hardware pin.

The library was built primarily to handle ks0108 type GLCD modules however if you have one of these vk5121 modules, like I do, they provide the configuration for it too. For the examples to work with the vk5121 module you have to modify the ardunio_install_folder/libraries/glcd/glcd_Config.h file and update the Autoconfig section.

/*
* autoconfig includes - (comment this out if using manual configurations, see below)
*/
//#include "config/ks0108_Panel.h"          // <-- comment out or remove
#include "config/Modvk5121_Manual_Config.h" // auto config lib for vk5121

Now you should be ready to open the example and upload your sketch. The glcd comes with a number of good clean examples. To get to the examples click on

File > Examples > glcd > GLCDdemo

Compile, upload, and enjoy.

My AR.Drone

I’ve been wanting to build an autonomous robot for quite a while now. My first few attempts have been to hack an old Radio Shack RC and while that was mildly successful I still hadn’t reached my goal of a fully PC wifi controlled autonomous robot that would do my bidding at 3:00 am while I sat in bed with nothing but a laptop.

Along came Parrots AR.Drone. While it still isn’t quite autonomous its a really simple platform to start with and who doesn’t like something that looks like its been made by Skynet to take over the world?

At any rate, this little quadcopter has all the makings of a great platform to hack and reprogram to fit my needs. Here is a breakdown of the specs of the AR.Drone.

EMBEDDED COMPUTER SYSTEM

  • ARM9 468 MHz
  • DDR 128 Mbyte at 200MHz
  • Wifi b/g
  • USB high speed
  • Linux OS

INERTIAL GUIDANCE SYSTEMS
WITH MEMS

  • 3 axis accelerometer
  • 2 axis gyrometer
  • 1 axis yaw precision gyrometer

SPECIFICATIONS

  • Running speed: 5 m/s; 18 km/h
    (16.4 ft per second; 11.2 miles per hour)
  • Weight:
    - 380 g with outdoor hull (0.8 pounds)
    - 420 g with indoor hull (0.9 pounds)
  • Flying time: about 12 minutes

SAFETY SYSTEM

  • EPP hull for indoor flight
  • Automatic locking of propellers in the
    event of contact
  • UL2054 battery
  • Control interface with emergency button
    to stop the motors

AERONAUTIC STRUCTURE

  • High-efficiency propellers(specially designed for the Parrot
    AR.Drone)
  • Carbon-fiber tube structure

MOTORS AND ENERGY

  • 4 brushless motors, (35,000 rpm, power: 15W)
  • Lithium polymer battery (3 cells, 11,1V, 1000 mAh)
  • Discharge capacity: 10C
  • Battery charging time: 90 minutes

FRONT CAMERA: WIDE ANGLE CAMERA

  • 93° wide-angle diagonal lens camera, CMOS sensor
  • Encoding and live streaming of images on iPhone
  • Camera resolution 640×480 pixels (VGA)
    Other AR.Drone detection
    - Validation of shots fired at enemy drones
    - Estimate of distance
    - Detection distance: 5 meters(16.4 ft)
    3D tag detection
    - Positioning of virtual objects
    - Calculation of markers of virtual objects
    - Detection distance: 30 centimeters to 5 meters (1ft to 16.4 ft)
  • Video feedback on the iPod touch /iPhone screen

ULTRASOUND ALTIMETER

  • Emission frequency: – 40kHz
  • Range 6 meters (19.7 ft) Vertical stabilization

VERTICAL CAMERA: HIGH SPEED CAMERA

  • 64° diagonal lens, CMOS sensor
  • Video frequency: 60 fps
  • Allows stabilization even with a light wind