czwartek, 4 kwietnia 2013

Raspberry Pi: some progress with time-lapse photography

I have made some progress in accessing still camera with gphoto2 (cf. here). The detailed description of my set-up will be disclosed within a few weeks (as I am still not sure if it is 100% success:-). In short:

I changed camera from Canon A620 to Nikon S3000.

I connected camera with active USB hub.

On every capture USB port is reset with usb_reset utility (cf here and here)

Multiple cameras

I use two Nikon S3000 compact cameras so there is a problem how to identify which is which.


$gphoto2 --auto-detect
Model Port
----------------------------------------------------------
Nikon Coolpix S3000 (PTP mode) usb:001,022
Nikon Coolpix S3000 (PTP mode) usb:001,021

So one can use --port usb:001,022 option to access first attached camera and --port usb:001,021 to access the second one. Of course hard-coded port numbers are troublesome as they are not fixed and change if the device is disconnected/connected again. Better way to identify the camera is to use it's serial number:


## $gphoto2 --get-config serialnumber --port PORT
## example
$gphoto2 --get-config serialnumber --port usb:001,022
Label: Serial Number
Type: TEXT
Current: 000047514512

I have black Nikon with 000041076602 serial number and pink one with 000047514512 serial number. I use the following bash script to access the cameras:


#!/bin/bash
PINK_CAM_ID='000047514512'
BLACK_CAM_ID='000041076602'

while test $# -gt 0; do
case "$1" in
-b|--black) REQ_CAM="$BLACK_CAM_ID";;
-p|--pink) REQ_CAM="$PINK_CAM_ID";;
esac
shift
done

## Picture filename:
FILENAME="NIK`date +"%Y%m%d%H%M"`.jpg"

## Scan all attached cameras:
while read PORT_ID
do
##echo $PORT_ID
## -n means string is non-empty
if [ -n "$PORT_ID" ] ; then
CAM_ID=`gphoto2 --get-config serialnumber --port $PORT_ID | awk '/Current:/ { print $2 }' `
if [ $CAM_ID = "$REQ_CAM" ] ; then
REQ_CAM_PORT="$PORT_ID"
##echo "*** Req Camera ID: #$CAM_ID."
fi
fi

done <<< "`gphoto2 --auto-detect | grep usb | awk '{ print $6}'`"


if [ -z "$REQ_CAM_PORT" ] ; then
echo "*** Error: Camera $REQ_CAM not found ***"
## sent a SMS cf http://pinkaccordions.blogspot.com/2013/03/automatic-sms-alerts-using-google.html
sms_reminder.sh
exit 1
fi

## reset the USB device
REQ_CAM_PORT_DEVNAME=`echo $REQ_CAM_PORT | sed 's/^.*://' | sed 's/,/\//'`
usb_reset /dev/bus/usb/${REQ_CAM_PORT_DEVNAME}

LANG=C gphoto2 --port "$REQ_CAM_PORT" --force-overwrite --set-config flashmode=1 \
--set-config d002=4 \
--capture-image-and-download --filename "$FILENAME"

## reset the USB device again
usb_reset /dev/bus/usb/${REQ_CAM_PORT_DEVNAME}

Property d002 sets picture resolution (4 means 2592x1944).

Value 1 of flashmode turns-off flash.

It seems that without usb_reset there are problems with battery charging (why?)

Brak komentarzy:

Prześlij komentarz