Evolution of a Blog

This blog has evolved as I have as a maker. It starts at the beginning of my journey where I began to re-tread my tires in the useful lore of micro electronics and the open-source software that can drive them. While building solutions around micro-electronics are still an occasional topic my more recent focus has been on the 3D Printing side of making.

Thursday, April 4, 2013

RPi as a CritterCam - Ultimately Remoting a DSLR

I have made some progress on a CritterCam based on one of my RPi's.   Here are a couple pictures of the device:

  • The base is a four battery holder for 3.7v 1850 Lithium Ion flashlight batteries with an output of 14.8v.
  • At the top is an adjustable power regulator that drops the 14.8v to 5v and delivers it via a 5.2mm power plug.
  • The power regulator is sitting on a powered USB hub that provides power to the RPi and also supports a Wi-Fi dongle (and a keyboard during debugging).  The hub is a cheap one but compatible with the RPi and is smaller than the more expensive ones I find on Amazon.
  • As mentioned above the Hub supports a USB Wi-FI dongle.   The one shown in the picture is an Edimax (larger of the two that I have).  I also have the small one but have been having some issues with dropped packets that I will discuss elsewhere.
  • In front of the USB Hub is the a 720p WebCam that is compatible with the RPi...but in my case only if plugged directly into the RPi.
  • Inside the Adafruit case is, of course, the Raspberry Pi that drives the CritterCam and it's web interface.
My goal is to use some Python code to detect motion in front of the webcam and trigger a shot by the DSLR which will be connected to the CritterCam.   The CritterCam will also support a web server running a little PHP application that will provide a preview of what the CritterCam sees.   I will talk about all of this a little later.

Right now I have a couple of issues.  First is one of power, on a couple of fronts, one being that I am using four Lithium Ion batteries to power the CritterCam and one of them has turned itself off!  I guess this is a good feature but I only have four right now but am waiting for an order from China for some more.  The other power related issue is that while I had a good test run with the Lithium Ion batteries driving the RPi for almost three hours...since then I can't get the power regulator to reliable support the RPi when connected to wall power of a variety of voltages.   The power does not seem sufficient to drive both the Hub and the RPi.   I am baffled as it worked so well with the batteries but can not retest with batteries again as I am missing one!

The other issue relates to driving the DSLR.   I have the Python code working well with the webcam on its own.   It detects motion and saves the current image.   Alas, when I try to trigger a DSLR capture at that point using the code I discuss here, it fails.   More work to do here but first I want to get the power issue sorted.

Monday, March 25, 2013

RPi as a Remote Control for a Canon DSLR - Part 2

As with many others, I have had problems with gphoto2 running on the RPi due to USB issues.   It works for a single capture, if that, and then dies.   There is a lot of discussion out there about solutions with the idea of resetting the USB Bus high among them.   Others may have had success with this but I can not seem to get it to work.   I downloaded the code from this thread in the RPi forum, got it compiled, but on execution, could not get it to work as discussed!

I have, however, come up with another idea courtesy of angryelectron.  Their observation was that the problem occurs from opening and closing the camera as gphoto2 does for every transaction.   If you do a bunch of stuff between the open and the close you don't have a failure (until you do another open/close).  

The above suits me fine as I was not planning on using gphoto2 command line but was really looking to use libgphoto2 from Python via a wrapper developed by alexdu / piggyphoto.

My initial experiments are positive though I am still encountering failures though not until a significant number of previews and captures have been done.   I am going to continue to head down this direction.

Sunday, March 24, 2013

Handy, Cheap, Small Keyboard/Pointer

I bought this keyboard last week to save some space on my desk and have a mouse and keyboard with only one USB slot...all while not spending much money.   The reviews on Amazon were mixed but I bought it anyway and am quite pleased.   It is certainly not going to become a primary keyboard but it meets my requirements.   It worked with no fuss and no muss on both wheezy and arch.

Friday, March 22, 2013

Handy Directory of Arch Linux Utilities

The Arch Linux Wiki is the end all place for documentation on Arch...though Arch for the RPi is not necessarily what is documented there!   In any case this page of that wiki is particularly useful for finding a utility (like atool for archiving).

Thursday, March 21, 2013

Raspberry Pi Inventory

Somehow I have ended up with no less than four Raspberry Pi's.   I started with the one that I wanted to build the 'Bot around.   Then I decided that I needed one for development that I could mess with and not have to dismantle the 'Bot.   Since then I used one to save me having to drill a hole in the wall of our new house to run another TV antenna lead.

Then I fried the one that I had designated as my development platform (unfortunately it was one that does not appear to have a polyfuse on the USB circuit.  The CPU is ok as the device boots, displaying status to the monitor, but never makes a network connection nor can it talk to a keyboard :-(.

So I, obviously, had to buy a fourth RPi to serve as my development platform.  It arrived non functional so I ordered another one and in the meantime returned the non-functional unit for a refund.   Got a replacement instead and just decided to keep it.  Sad but true, I now have five of the little things working and one fried.  Cheap for the entertainment value provided!

Inventory

RPi Current Use
1. Model B 256mb Fried.
2. Model B 512mb 'Bot - was running Wheezy now being ported to Arch
3. Model B 512mb TvHeadend - Serving TV to media clients (office and tablet).   Also host for ntop - running Wheezy
4. Model B 512mb Development - Miscellaneous uses
5. Model B 512mb Development - Currently being built as a CritterCam - running Wheezy.

Wireless Performance Issues on the RPis

I have been having intermittent performance issues on my wireless connections to my RPis.   As in the terminal or FTP sessions are either irritatingly slow or unusably slow.  
Unfortunately this is not a CPU usage issue. I can have the WLAN connection acting constipated while an Ethernet connection or the Console are humming along. 
 
I have multiple RPis and have had the problem with both Arch Linux and Wheezy running both Belkin N150 and Edimax dongles.
 
The Ethernet running well seems to rule out a USB issue (I think?) but that still leaves me baffled.  the choice of USB port for the dongle does seem to make a difference. In fact I may be chasing multiple problems as I have found that the remaining port on the RPi itself (after the other goes to the hub) provides the most reliable performance. Unfortunately this is not making any difference with my latest incarnation of the issue.
 
ifconfig shows pretty high rate of drops on rx and none on tx....but there are also drops on the ethernet connection rx side (though not nearly as high). I wonder if it is something on my network?
e now!

I am going to move my RPi environment to a second WLAN and see if that makes a difference. Before I do that, however, I am going to try and see if I can use ntop to shed any light on the situation. Really cool little tool. I have installed it on the RPi that serves up Live TV to my media clients. 
 
The question is...will I understand the output?

Wednesday, March 20, 2013

Arch Linux on the Raspberry Pi - Part 3 - 'Bot

The setup for my 'Bot running on Wheezy was described by an earlier post.   The below is a replication of that installation on Arch Linux based on the image that I described by the previous posts on this thread (Arch Linux on the Raspberry Pi).

With the base system built previously booted and running, I decided to work on installing the Arduino development environment.   It looked like I needed to download the source from the Arch User Repository (AUR) so I installed base-dev.   Interestingly there seemed to be a couple packages missing.  I did a "pacman -Syu"  (again as it had been done before for the image that I am using) and they downloaded!  There is a lesson here.  In any case it was all in vain as the source I downloaded apparently is not supported on the RPi!

Given the above I went to github and found the source code there and started to work on what it would take to get it to work.   I am still confused by what is needed so decided to defer the installation of the Arduino SDK.   I don't really need it running on the 'Bot as I can download the Py2Ard interface from one of my other workstations.

The 'Bot is written in Python V2 and relies on a number of Python extensions which is where I decided to begin:
pacman -S python2-imaging
pacman -S python2-pyserial

Once again there were some packages missing so I ran another synchronize.   I wonder if this was because pointers in one of the above packages were out of date?  I don't get it:
pacman -Syu
pacman -S python2 python2-numpy opencv 

With the above installed I went to test the webcam capture from within Python - it needs to be root??? I don't get this either!  I am using the shortest possible webcam capture script and it captures a zero length image without being root.

I don't actually use Python to capture my images given some issues with the camera dropping offline after a while so I pivoted to fswebcam and installed it now.  Note that I do use the above imaging libraries for a couple functions like creating an image of my radar map:
pacman - S fswebcam

My use of the GPIO bus requires one more library, again one that needed to be pulled down from GITHUB:

Finally, the last thing we need is a queue management solution called Beanstallk.  The architecture of my 'Bot is a little more complicated than it needs to be but I thought it would be cool to use some background Daemons with inter-process communications via Beanstalk.

No Arch Linux package exists for Beanstalk so I had to download the source and compile it on my target.   It seemed to work flawlessly:
git clone git://github.com/kr/beanstalkd.git 
install make
install gcc
make
sudo make install 

Now it was time to setup Beanstalk to run as a service per these instructions.  My approach was to create a service description file by cloning the one that proftpd created:
/usr/lib/systemd/system/proftpd.service -->         
                   /usr/lib/systemd/system/beanstalkd.service       

Note that you may need to add your user name to a group, per the below, assuming you want to view logs generated by an error:
sudo systemctl start beanstalkd

I also created a directory for the PID as pointed to from the service file and pointed executable to /usr/local/bin/beanstalkd.

The service can be started once as shown below:
sudo systemctl start beanstalkd

Or started at boot:
sudo systemctl enable beanstalkd

Lastly, I found a version of the beanstalkc extension for Python and copied it into the directory with my Robot source code.

One important caveat.   Something is not working at the moment!   Beanstalk is not starting reliably.   More later.