Skip to content

Instantly share code, notes, and snippets.

@tuyenld
Forked from Hermann-SW/camver
Created Nov 6, 2020
Embed
What would you like to do?
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
bash camera_i2c 2>&1 | cat > /dev/null
v1=`i2cdetect -y 0 54 54 | grep " 36"`
v2=`i2cdetect -y 0 16 16 | grep " 10"`
hq=`i2cdetect -y 0 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
@tuyenld

This comment has been minimized.

Copy link
Owner Author

@tuyenld tuyenld commented Nov 6, 2020

For linux 5.4 as 6by9's comment

#!/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
  bash camera_i2c 2>&1 | cat > /dev/null
  v1=`i2cdetect -y 10 54 54 | grep " 36"`
  v2=`i2cdetect -y 10 16 16 | grep " 10"`
  hq=`i2cdetect -y 10 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

Tested with v1 camera

 i2cdetect -y 10  54 54                                                                                                                      
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                                                 
10:                                                 
20:                                                 
30:                   36                            
40:                                                 
50:                                                 
60:                                                 
70: 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment