Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Last active January 28, 2022 13:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Hermann-SW/3c0387c4340e10866af32cc5a3d21036 to your computer and use it in GitHub Desktop.
Save Hermann-SW/3c0387c4340e10866af32cc5a3d21036 to your computer and use it in GitHub Desktop.
Determine Raspberry camera version connected to CSI-2
#!/bin/bash
dt=`vcgencmd get_camera | grep "detected=1"`
if [ "$dt" = "" ]; then
echo "no camera detected"
else
if [ "`which i2cdetect`" = "" ]; then
echo "i2cdetect not installed" ; exit
fi
cd `dirname $0`
if [[ ! -a camera_i2c ]]; then
wget https://raw.githubusercontent.com/6by9/raspiraw/master/camera_i2c \
2>/dev/null
fi
r=`uname -r | head --bytes 1`
if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi
bash camera_i2c 2>&1 | cat > /dev/null
v1=`i2cdetect -y $i2c 54 54 | grep " 36"`
v2=`i2cdetect -y $i2c 16 16 | grep " 10"`
hq=`i2cdetect -y $i2c 26 26 | grep " 1a"`
if [ "$v1" != "" ]; then echo -n "v1"; fi
if [ "$v2" != "" ]; then echo -n "v2"; fi
if [ "$hq" != "" ]; then echo -n "hq"; fi
echo " camera found"
fi
@hailfinger
Copy link

My current version is here.
Changelog:
Switch from decimal to hex in i2cget
Handle the TC358743 HDMI-to-CSI converter
Handle the case where tc358743 dtoverlay is active, both if TC358743 or a Pi camera are present
Remove useless use of cat
Assume camera_i2c is directly executable in $PATH
@Hermann-SW I was unable to find which license applies to the code, but I hope you'll accept the changes.

#!/bin/bash
# From Hermann Stamm-Wilbrandt, https://gist.github.com/Hermann-SW/3c0387c4340e10866af32cc5a3d21036
# Added TC358743 HDMI-to-CSI converter support (Auvidea B101) by Carl-Daniel Hailfinger
# License unclear
r=`uname -r | head --bytes 1`
if [ "$r" = "4" ]; then i2c=0; else i2c=10; fi
dt=`vcgencmd get_camera | grep "detected=1"`
# Ignore the result of vcgencmd get_camera as it claims no camera is installed if the tc358743 dtoverlay is loaded
if [ "`which i2cdetect`" = "" ]; then
  echo "i2cdetect not installed" ; exit
fi
if [ "`which camera_i2c`" = "" ]; then
  echo "camera_i2c not installed" ; exit
fi
camera_i2c >/dev/null 2>&1
v1=`i2cdetect -y $i2c 0x36 0x36 | grep " 36"`
v2=`i2cdetect -y $i2c 0x10 0x10 | grep " 10"`
hq=`i2cdetect -y $i2c 0x1a 0x1a | grep " 1a"`
tc358743hdmicapture=`i2cdetect -y $i2c 0x0f 0x0f | grep " 0f\| UU"`
if [ "$v1" != "" ]; then cam="v1 camera"; fi
if [ "$v2" != "" ]; then cam="v2 camera"; fi
if [ "$hq" != "" ]; then cam="hq camera"; fi
if [ "$tc358743hdmicapture" != "" ]; then cam="tc358743 hdmi capture"; fi
if [ "$cam" != "" ]; then
        echo "$cam found"
else
        echo "no camera detected"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment