Two cameras with chdkptp - General Help and Assistance on using CHDK stable releases - CHDK Forum

Two cameras with chdkptp

  • 2 Replies
  • 1292 Views
Two cameras with chdkptp
« on: 05 / February / 2021, 21:15:36 »
Advertisements

Is it possible to connect to two cameras with chdkptp and shoot simultaneously?

I am building a book scanner with 2 Cannon PowerShot Elph 180s and a Raspberry Pi 4. I have successfully got one camera at a time working with the command line script chdkptp.sh But I would like to connect to both cameras.

Also I would love to trigger the shots with a keyboard hot-key, like the spacebar, if that is possible.

Any help is appreciated.

*

Offline reyalp

  • ******
  • 14125
Re: Two cameras with chdkptp
« Reply #1 on: 05 / February / 2021, 22:53:44 »

Is it possible to connect to two cameras with chdkptp and shoot simultaneously?
Yes, with some limitations. You can find some resources on https://chdk.fandom.com/wiki/Multiple_Cameras_using_CHDK although much of it is oriented to larger rigs with many cameras and more stringent synchronization requirements.

For normal chdkptp CLI commands like shoot, remoteshoot and the file management commands, chdkptp only supports one "current" connection at a time. So to work with multiple cameras you can either use a chdkptp script like the included multicam.lua, run multiple instances of chdkptp, or use script to switch the current connection between cameras.

If you use multiple instances, you need connect to each one using bus/device ID, to ensure they don't step on each other's connections.

Quote
Also I would love to trigger the shots with a keyboard hot-key, like the spacebar, if that is possible.
In CLI mode, chdkptp only does line oriented input, so you could easily make a script that uses enter to trigger a shot, just using lua io.read(). If you script the GUI, you could respond to other keys.

Alternatively, you could do your keyboard input in another program, and control chdkptp either by piping to its input, or reading from your process using popen.
Don't forget what the H stands for.

Re: Two cameras with chdkptp
« Reply #2 on: 11 / February / 2021, 11:22:00 »
Great. Thank you so much!

I am not a programmer  and I am new to this, so it took me a while to figure it out. It may not be the most elegant solution, but it works for me.

Basically, I wrote two shell scripts, multicam.sh and multicamshoot.sh

The first one simply echos the multicam.lua commands

Code: [Select]
#!/bin/bash
# This file is multicam.sh
echo "!mc=require('multicam')"
echo "!mc:connect()"
echo "!mc:start()"
echo "!return mc:cmdwait('rec')"
echo "!return mc:cmdwait('preshoot')"
echo "!return mc:cmdwait('shoot')"
echo "!return mc:cmdwait('play')"
echo "!mc:cmd('exit')"

The second script looks for any keyboard input and pipes the commands in multicam.sh to chdkptp.sh

Code: [Select]
#!/bin/bash
# This file is mulicamshoot.sh
echo "Press any key to shoot, "q" to exit"
count=1
while : ; do
read -n 1 k <&1
if [[ $k = q ]] ; then
((count=$count-1))
printf "\nQuitting... $count shots triggered.\n"
break
else
  ./multicam.sh | ./chdkptp.sh
printf "\nMultiCamShootCount: $count \n"
 ((count=$count+1))
echo "Press anykey to shoot again, 'q' to exit"
fi
done

With this setup I just have to run

Code: [Select]
$./multicamshoot.sh
It will trigger both of my cameras by hitting any key, and quits with "q."

If this can be improved, I am open to suggestions. But I am one step closer to having my book scanner working. :)

 

Related Topics


SimplePortal © 2008-2014, SimplePortal