Advertisement

Friday, May 29, 2015

MMS Photo-inator Xsi -- 22-25 May session

While at the Milwaukee Makerspace for my weekly Maker-time, I continued working on my idea to use a Raspberry Pi 2 Model B to make a device that will take pictures by controlling an SLR camera. This time, I found some software to display an image, made a prototype with hardware, and wrote most of the python code.

Installed Avahi on the pi so I can connect to the Pi over a network.  This allows me to do coding on my Linux laptop and FTP the files to the Pi.  If something happens to the Pi, I won't lose the code.  The instructions to install Avahi are here.  Changed the name of the device to photoinator in both the /etc/hostname and /etc/hosts files.

I kicked around ideas for a human to interact with the photo-inator.  One of my fellow Makers suggested doing everything in web pages.  That would probably make everything easy including printing the picture but it wouldn't make much use of the Perma-Proto Pi Hat from Adafruit.  I'd like to have the user interact with the photo-inate by pressing buttons and seeing flashing lights.

Also, I would like to display a preview of the picture and let the user decide if it is good enough to keep or not.  How do I get the Pi to display a jpg file without using xwindows?

First, I tried an application called feh to display images.  This web page has the instructions for installing feh: http://feh.finalrewind.org/

After messing around with feh, I realized that it only works from within xwindows.  That does not help -- especially since gphoto2 only runs from the command line and will not work in a terminal session running in xwindows.

The application that I needed is called fbi.  I installed the app using sudo apt-get install fbi.  After that, it just worked.  I ran the program in the directory that has the photos in it.  The way to run fbi is fbi image.jpg -a -t 10 -1.  The -a will auto re-size the image to fit the screen.  -t 10 tells fbi to display the image for 10 seconds.  -1 means that fbi should exit after the timeout.

Next, I wrote a quick shell program to take a picture with gphoto2 then display it with fbi.  I pass the filename to save the picture to as a parameter.  The shell file looks like this:

gphoto2 --capture-image-and-download --filename=$1.jpgfbi $1.jpg -a -t 10 -1

The $1 lets me pass in a file name on the command line.

Next, I used a python program that I found on this Instructable and modified it a bit to control a button and an LED on the Adafruit T-cobbler Plus proto board.  It worked.  I was able to press a button to start the process.  The program flashed an LED, took a picture, and displayed it on the screen for 10 seconds.  Nice.

I spent a good part of the day on Sunday (after church of course) writing a much more robust Python program with subroutines and global variables and all of that nerdy goodness.  

Finally, I spent Memorial Day back at the Makerspace to build the prototype and debug the code.  The prototype has three buttons and four LEDs.  One button is to start the picture-taking process.  Another will let the human choose to Keep the picture they just saw.  The third button will tell the Pi to reset everything and start over.  One of the LEDs will light when the picture-inator is ready to take a picture.  The second LED will blink increasingly fast to warn the user that the picture is about to be taken.  The final two LEDs blink alternately next to the Keep and Reset buttons to encourate the human to push one.  This all works fine.  For the final version, I would like to use small light bulbs instead of LEDs to increase the brightness.  I probably need a stronger power source than the PI to light them.  I will also need a more complicated circuit that includes a transistor.  I'll design and build that in the next session.

Another idea I had was to add a toggle switch to designate the mode that the picture-inator is in -- one shot or continuous.  That should be pretty easy to do but I did not get to it this time.

One of the things I struggled with on the coding side was the GPIO.add_event_detect function.  I originally wanted the program to call a subroutine when a button was pressed.  However, I could not get that to work.  The subroutine might get called the first time the button was pressed but not after that.  Sometimes, pressing the button never did anything.  I ended up punting and doing several things to make this work.

First, the main loop uses GPIO.event_detected to see if any of the buttons were pressed.  Anytime a button is pressed or a state changes, the program turns off event detection for all buttons.  Then, it does whatever the function is meant to do, and turns on even detection for any buttons that need to have it.  Doing all of this should allow the program to always catch button presses and never have false-positives or multiple button presses.

One other problem is that I don't know how to interrupt the picture being displayed.  So, if the person pushes the Keep button while the picture is being displayed, nothing will happen.  I don't think I can fix that.  I spent a lot of time researching a way to call an external program in a separate thread but I'm not sure it is possible.

The bug I am currently working on has to do with debug mode.  When the program is running in debug mode everything works.  However, when I run the program with debug mode turned off, it turns on the ready LED but will not do anything when any button is pressed.  I have not been able to figure out why.

Another bug is if the camera is off, gphoto2 returns an error.  The program cannot handle the error.  Need to figure that out.

Here is a picture of the prototype at this point.


MMS Photo-inator Xsi -- 15 May 2015 Session

Even though I am posting this near the end of May, I am describing my efforts from 15 May 2015.

While at the Milwaukee Makerspace for my weekly Maker-time, I continued working on my idea to use a Raspberry Pi 2 Model B to make a device that will take pictures by controlling an SLR camera. 

Another New Camera
After posting my lackluster progress on the Makerspace Google Group, a Makerspace member named Matt
offered to let me use his Canon EOS Rebel Xsi DSLR camera.  Awesome!  It was waiting for me in my locker when I arrived at the 'space.  I tried using gphoto2 with the Canon.  gphoto2 detected the camera but I still had some issues.  I could not take pictures or basically do anything.

Did some searching on the internet.  One site said that the version of gphoto2 that gets installed with apt-get is not the correct version.  apt-get downloads version 2.4.14.  You need the latest version of both libgphoto and gphoto2.

First, I used sudo apt-get purge gphoto2 to remove the gphoto app.

Next, I did apt-get upgrade and update just because.

Next, I installed a bunch of libraries recommended by this website: https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=70049

Next, I downloaded the latest versions of libgphoto2 and gphoto2 using wget.  For example, I typed in wget http://sourceforge.net/projects/gphoto/files/libgphoto/2.5.7/libgphoto2-2.5.7.tar.bz2

In order to unpack the files, I typed tar xjvf libgphoto2-2.5.7.tar.bz2.  A web page that talks about this is here: http://askubuntu.com/questions/25961/how-do-i-install-a-tar-gz-or-tar-bz2-file

After unpacking, I cded to the folder.  The INSTALL file has instructions about what to do next.

Step 1: ran ./configure --prefix=/usr/local.  The second time I simply ran ./configure
Step 2: ran make
Step 3: ran sudo make install

Get some error that the install failed.  It could not remove anything in /usr/local.  I rebooted and got messages about stuff not working.  Looks like the OS on the SD card got corrupted.  The pi will no longer boot.  Yar!

I had to start completely over.  Downloaded a program to format the SD card.  Then downloaded the NOOBs files and copied them to the SD card.  The full version of NOOBs would not copy to the card.  I had to copy the lite version to the card.  That version downloads the install files over the internet when the Pi boots up.  That worked.

Did all the setup stuff again.  Downloaded libgphoto again and went through the complete install.  This time, it worked.

Rebooted.

Downloaded the gphoto2 tar file from sourforge using the same wget command.  Used tar to unpack it.  Then, ran ./configure.  It failed saying "Cannot autodetect popt.h" 

This page (http://www.yannock.be/computer/compiling-gphoto2-on-the-raspberry-pi) lists other packages that need to be installed with gphoto2.  Installed all the packages it suggested:

  1. libexif-dev
  2. libpopt-dev
  3. libfuse-dev
  4. mono-devel
  5. monodoc-base
  6. libmono-2.0.1
  7. mono-gmcs
  8. python-pyrex
After installing all of this, I had to re-run ./configure.  This time it worked.  Ran make and make install.  It all worked.

Ran gphoto2.  It worked.  

The gphoto2 auto-detect sees the camera.  Was able to take a picture with gphoto2 and save it to the computer.  You have to specify a filename or it always uses the same one.

That's enough for this week.

MMS Photo-inator Xsi -- 8 May 2015 Session

Even though I am posting this near the end of May, I am describing my efforts from 8 May 2015.

While at the Milwaukee Makerspace for my weekly Maker-time, I continued working on my idea to use a Raspberry Pi 2 Model B to make a device that will take pictures by controlling an SLR camera. 

New Camera
I found a Canon PowerShot A540 camera sitting in a drawer in the 3D printer area at the 'space.  I hooked that up to the PI to see if I would fare any better with gphoto2.

Executed gphoto2 -auto-detect.  gphoto2 will only detect the camera if the power is on.  It says that capture is not supported by the driver.  This could be a problem if I want to save power by turning the camera off when the photo-inator is not in use.  The power button is a momentary switch.  So, it has to be pushed to turn the camera on or off.  This is not the ideal situation.

The batteries are low.  Need to find a 3.15v DC power source with a male plug if I want this camera to stay on indefinitely.

I did not have much luck playing with this camera compared to the Canon A470.  Ed from the Makerspace told me about software called CHDK.  CHDK is software that runs on a Canon camera.  It gives you a new user interface and more options.  This might be an option.

The software for the Canon A540 can be found here:  http://chdk.wikia.com/wiki/A540

Not much progress this week.

MMS Photo-inator Xsi -- 1 May 2015 Session

Even though I am posting this near the end of May, I am describing my efforts from 1 May 2015.

While at the Milwaukee Makerspace for my weekly Maker-time, I started working on my idea to use a Raspberry Pi 2 Model B to make a device that will take pictures by controlling an SLR camera.  I think I will call it the MMS Photo-inator Xsi.

Setting up the Pi
The Pi came with a micro SD card that was already formatted with Raspbian and ready to go.  So I did not have to mess around with that.

First of all, as always, I ran sudo apt-get upgrade and sudo apt-get update to make sure everything was up-to-date.

Changed the password for the pi user to wrenchiron.

The keyboard was setup for British English.  Used raspi-config to change it to US E

nglish.

Camera-controlling Software
The software that will control the camera is called gphoto2.  Installed gphoto2 by typing "sudo apt-get install gphoto2".  <note> It turns out that this was not the correct way to install gphoto2.  I document the correct way to install it in a future post. </note>

Typing gphoto2 --list-ports reveals two USB ports, usb:001,003

Connected a USB cable from the pi to my Canon PowerShot A470.  gphoto2 could not find it.  I tried 3/4 USB ports.  My keyboard was plugged into the fourth USB port.

I had to turn the control knob on the back of the camera to "playback" mode.  Then, gphoto2 could see it on the USB port.

Did gphoto2 --list-cameras.  It does not list the Canon PowerShot A470.  There is a 460 and a 480 but not a 470.

The gphoto2 --auto-detect lists the camera as "Canon PowerShot A740".  That camera is in the list.

Some of the commands I tried returned errors.  For example, 
  • list-config: PTP I/O error
  • capture-image: said "your camera does not support generic capture"
I think I need to find a different camera.

Friday, May 15, 2015

Raspberry Pi Based Photo Booth -- Introduction

The Milwaukee Makerspace got some new Raspberry Pi 2 computers to use in a build night.  We are supposed to make something cool with the Pi and the Adafruit Perma Proto Pi hat.  I'm going to try making a photo booth for new members at the Makerspace.

The main idea for this came from this website: http://www.instructables.com/id/Raspberry-Pi-photo-booth-controller/?ALLSTEPS

The main software for this will be gphoto2.  Here are the steps for how the solution will work.
  1. Press start button.
  2. Turn on camera.  
  3. Display image from the camera on the screen.
  4. If timeout, power down.
  5. Push a button to take the picture.
  6. Display picture and wait for response.
    1. Delete
    2. Continue
    3. Timeout
  7. If delete or timeout, delete picture.
  8. If continue, 
    1. Print picture
    2. Send picture to Makerspace web site
  9. Return to step #3
Components needed
  • Raspberry Pi with power supply
  • Camera with usb interface
  • Start button
  • LED display
  • Monitor
  • Printer
  • Internet connection
Alternatives
Have one big button that starts the process.  Turn on the camera.  Display a countdown.  Take a picture and use it.