Looking to use an android phone as a camera (via USB)

Hi,
I've been trying to use an old android phone (Xiaomi Mi3) as a camera for Octoprint. I used the directions provided by https://github.com/foosel/OctoPrint/wiki/Using-an-Android-phone-as-a-webcam

However, the IP Webcam app keeps crashing and is not stable on my phones (tried 2 - an LG-G2 and the Xiaomi Mi3). I was thinking if it would be possible to:

  1. Connect the phone to a raspberry pi using USB (I'm powering / charging my phone through the RasPi USB)
  2. Get image from the camera using ADB.

I'm not sure if this would work, or even how I would make it work. I think such a setup would have the following advantages:

  1. The phone camera will not be on at all times. Agreed, you will not be able to get a video stream in this case, however, I am more interested in creating time-lapses using octolapse. I believe this will also ensure that the phone does not overheat
  2. You would be able to switch on the camera only when needed
  3. You will not need a third-party app

Any help would be appreciated.

The idea is quite slick :+1:

Commands which should achieve what you want:

adb shell "am start -a android.media.action.IMAGE_CAPTURE"
adb shell "input keyevent KEYCODE_FOCUS"
adb shell "input keyevent KEYCODE_CAMERA"

To download the images from your phone use adb pull.

Hi, Did you find a solution?

I am working in a script, it is taking photos with the phone nice, but it is not working with Octolapse. Here is it:

#!/bin/bash

Put the arguments sent by Octolapse into variables for easy use

SNAPSHOT_NUMBER=$1
DELAY_SECONDS=$2
DATA_DIRECTORY=$3
SNAPSHOT_DIRECTORY=$4
SNAPSHOT_FILENAME=$5
SNAPSHOT_FULL_PATH=$6

Check to see if the snapshot directory exists

if [ ! -d "{SNAPSHOT_DIRECTORY}" ]; then echo "Creating directory: {SNAPSHOT_DIRECTORY}"
mkdir -p "${SNAPSHOT_DIRECTORY}"
fi

IMPORTANT - You must add gphoto2 to your /etc/sudoers file in order to execute gphoto2 without sudo

otherwise the following line will fail.

adb shell input keyevent KEYCODE_WAKEUP
adb shell am start -a android.media.action.STILL_IMAGE_CAMERA
adb shell "input keyevent KEYCODE_FOCUS"
sleep 2
adb shell "input keyevent KEYCODE_CAMERA"
adb shell input keyevent KEYCODE_SLEEP

if [ ! -f "{SNAPSHOT_FULL_PATH}" ]; then echo "The snapshot was not found in the expected directory: '{SNAPSHOT_FULL_PATH}'." >&2
exit 1
fi

Any ideas??
thanks

Nobody answer this? you solve it?

Rather than ask in a 5+ year old topic, you should open a new Get Help topic, fill in the template with as much information as you can so we can provide the best help possible.

1 Like