User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

How to verify camera version with i2cset/i2cget?

Thu Feb 22, 2018 10:55 pm

I did capture I2C traffic with logic analyzer for "raspistill -v" command, this is start:

Code: Select all

Time [s], Analyzer Name, Decoded Protocol Result
1.480686500000000,I2C,Setup Write to [0x6C] + NAK
1.480796500000000,I2C,Setup Read to [0x6D] + NAK
1.480918000000000,I2C,Setup Write to [0x6C] + NAK
1.481028000000000,I2C,Setup Read to [0x6D] + NAK
1.481149000000000,I2C,Setup Write to [0x6C] + NAK
1.481259000000000,I2C,Setup Read to [0x6D] + NAK
1.482386500000000,I2C,Setup Write to [0x6C] + ACK
1.482476500000000,I2C,0x30 + ACK
1.482566500000000,I2C,0x0A + ACK
1.482676500000000,I2C,Setup Read to [0x6D] + ACK
1.482766500000000,I2C,0x56 + ACK
1.482856500000000,I2C,0x47 + NAK
...

There are 3 "empty" write to 6C, read from 6D, followed by write 0x30 0x0A and read back camera ID 0x56 0x47.

Now I tried to do same with I2C tools command sequence with this script (12298 is 0x300A):

Code: Select all

$ cat doit 
#!/bin/bash
yes | sudo i2cget 0 0x36 0
yes | sudo i2cget 0 0x36 0
yes | sudo i2cget 0 0x36 0

yes | sudo i2cset 0 0x36 1 12298 w

yes | sudo i2cget 0 0x36 0 w
$

I did capture traffic with logic analyzer again, and this is all what I saw:

Code: Select all

Time [s], Analyzer Name, Decoded Protocol Result
1.413943000000000,I2C,Setup Write to [0x6C] + NAK
1.414053000000000,I2C,Setup Read to [0x6D] + NAK
1.500663000000000,I2C,Setup Write to [0x6C] + NAK
1.500773000000000,I2C,Setup Read to [0x6D] + NAK
1.570027500000000,I2C,Setup Write to [0x6C] + NAK
1.570137500000000,I2C,Setup Read to [0x6D] + NAK
1.640882500000000,I2C,Setup Write to [0x6C] + NAK
1.710209000000000,I2C,Setup Write to [0x6C] + NAK
1.710319000000000,I2C,Setup Read to [0x6D] + NAK

And that although the errors in script execution.
But since I captured I2C commands, something worked despite the errors.
And "data 0x300a" seen should write what is needed:

Code: Select all

pi@raspberrypi2B:~ $ sudo ./doit 
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x36, data address
0x00, using read byte data.
Continue? [Y/n] Error: Read failed
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x36, data address
0x00, using read byte data.
Continue? [Y/n] Error: Read failed
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x36, data address
0x00, using read byte data.
Continue? [Y/n] Error: Read failed
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will write to device file /dev/i2c-0, chip address 0x36, data address
0x01, data 0x300a, mode word.
Continue? [Y/n] Error: Write failed
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-0, chip address 0x36, data address
0x00, using read word data.
Continue? [Y/n] Error: Read failed
pi@raspberrypi2B:~ $

Captured I2C traffic looks identical for the 3 "empty" write to 6C, read from 6D, but after that things go wrong.

How do I need to change the i2cset command that it does what "raspistill -v" does at that point?
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 15294
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to verify camera version with i2cset/i2cget?

Fri Feb 23, 2018 9:42 am

Simply don't.
Use the vc.camera_info component in the same way RaspiStill does to determine what the max resolution should be, and name to stick in the EXIF. That gives you back a MMAL_PARAMETER_CAMERA_INFO_T, which includes the string name for the camera.
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: How to verify camera version with i2cset/i2cget?

Fri Feb 23, 2018 8:54 pm

6by9 wrote: Simply don't.
Use the vc.camera_info component in the same way RaspiStill does to determine what the max resolution should be, and name to stick in the EXIF. That gives you back a MMAL_PARAMETER_CAMERA_INFO_T, which includes the string name for the camera.
I did use exactly the method you proposed in my latest commit to my userland fork 2 days ago:
https://github.com/Hermann-SW/userland/ ... 1a52b3L498


But my question was on a simple method to detect whether a v1 or a v2 camera is connected on command line.
Like "vcgencmd get_camera" for determining whether camera is detected.

And just now I found the simple solution, really too simple to be true.
We know that v1 camera has 0x36 I2C device address, and v2 camera has 0x10.
And we have your "raspiraw" tool "camera_i2c"!
Just two "i2cget"s tell us which camera is connected.

Here you can see detection of a v1 camera, 1st read succeeds (0x00), 2nd read fails:

Code: Select all

pi@raspberrypi2B:~ $ raspistill -v -t 1 2>&1 | grep Width
Width 2592, Height 1944, quality 85, filename (null)
pi@raspberrypi2B:~ $ 
pi@raspberrypi2B:~ $ camera_i2c ; i2cget -y 0 0x36 0 ; i2cget -y 0 0x10 0
setting GPIO for board revsion: a01041
A+, B+, and B2 all revisions - I2C 0 on GPIOs 28 & 29. GPIOs 32 & 41 for LED and power
0x00
Error: Read failed
pi@raspberrypi2B:~ $ 

And after shutdown, changing to v2 camera and powering up this detects v2 camera, 1st read fails, 2nd read succeeds (0x00)!

Code: Select all

pi@raspberrypi2B:~ $ raspistill -v -t 1 2>&1 | grep Width
Width 3280, Height 2464, quality 85, filename (null)
pi@raspberrypi2B:~ $ 
pi@raspberrypi2B:~ $ camera_i2c ; i2cget -y 0 0x36 0 ; i2cget -y 0 0x10 0
setting GPIO for board revsion: a01041
A+, B+, and B2 all revisions - I2C 0 on GPIOs 28 & 29. GPIOs 32 & 41 for LED and power
Error: Read failed
0x00
pi@raspberrypi2B:~ $ 


P.S:
On a Pi 3B "camera_i2c" needs to be started in "raspiraw" directory, but then detection works as well.
For Pi 3B the "i2cget"s are not needed, the "rpi3-gpiovirtbuf" called by "camera_i2c" shows either 0x10 (v2) or 0x36 (v1) camera connected.

Code: Select all

pi@raspberrypi3B:~/raspiraw $ raspistill -v -t 1 2>&1 | grep Width
Width 3280, Height 2464, quality 85, filename (null)
pi@raspberrypi3B:~/raspiraw $ 
pi@raspberrypi3B:~/raspiraw $ ./camera_i2c ; i2cget -y 0 0x36 0 ; i2cget -y 0 0x10 0
setting GPIO for board revsion: a02082
Raspberry Pi3
Set state of 133 to 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: 10 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- 64 -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
Error: Read failed
0x00
pi@raspberrypi3B:~/raspiraw $ 

P.P.S:
It is even easier, no "i2cget", but "i2cdetect" as done in your "camera_i2c" already for Pi 3B:

Code: Select all

pi@raspberrypi2B:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 10"
pi@raspberrypi2B:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 36"
30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 
pi@raspberrypi2B:~ $ 

Code: Select all

pi@raspberrypi3B:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 10"
10: 10 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
pi@raspberrypi3B:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 36"
pi@raspberrypi3B:~ $ 
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: How to verify camera version with i2cset/i2cget?

Sat Feb 24, 2018 9:56 pm

With "i2c-tools" package installed this tells you about the Raspberry camera connected.
You just need to store "camver" somewhere onto your $PATH:

Code: Select all

$ camver
v1 camera found
$ 

Code: Select all

$ cat camver 
#!/bin/bash
dt=`vcgencmd get_camera | grep "detected=1"`
if [ "$dt" = "" ]; then
  echo "no camera detected"
else 
  cd ~/raspiraw ; ./camera_i2c 2>&1 | cat > /dev/null
  v1=`i2cdetect -y 0 54 54 | grep " 36"` ; v2=`i2cdetect -y 0 16 16 | grep " 10"`
  if [ "$v1" != "" ]; then echo -n "v1"; fi
  if [ "$v2" != "" ]; then echo -n "v2"; fi
  echo " camera found"
fi
$ 
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: How to verify camera version with i2cset/i2cget?

Thu May 07, 2020 7:30 am

New version of "camver" can deal with v1, v2 and new HQ camera:
https://gist.github.com/Hermann-SW/3c03 ... c5a3d21036

Tool is not dependent on raspiraw anymore.
It aborts in case i2cdetect is not installed.
In case it does not find "camera_i2c" in same directory as "camver", it uses wget to download from 6by9's repo.
v1 camera is on 0x36, v2 camera on 0x10, and new HQ camera on 0x1A.

This tool is useful in case you have several PIs and many different cameras, avoids walking to the Pi and see.
Here is demonstration that camera_i2c gets downloaded -- needs internet access of course:

Code: Select all

🍓 which camver
/home/pi/.local/bin/camver
🍓 rm /home/pi/.local/bin/camera_i2c
🍓 camver
hq camera found
🍓 
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 15294
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: How to verify camera version with i2cset/i2cget?

Thu May 07, 2020 8:14 am

Just a heads up, the 5.4 kernel now uses kernel magic (aka a kernel module called i2c-mux-pinctrl) to leave i2c-0 on GPIOs 0&1, and have an /dev/i2c-10 for a correctly platform mapped I2C bus to the camera/display connectors. Directly messing with the pinmuxing as camera_i2c does will cause grief!
Software Engineer at Raspberry Pi Ltd. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
HermannSW
Posts: 6093
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany

Re: How to verify camera version with i2cset/i2cget?

Sat Nov 07, 2020 1:20 am

Updated the gist
https://gist.github.com/Hermann-SW/3c03 ... c5a3d21036
based on tuyenld's git comment
https://gist.github.com/Hermann-SW/3c03 ... nt-3518633
referring to 6by9's comment (keeping it backwards compatible):
camver.updated.png
camver.updated.png
camver.updated.png (45.94 KiB) Viewed 2594 times
https://github.com/Hermann-SW/RSA_numbers_factored
https://stamm-wilbrandt.de/GS_cam_1152x192@304fps
https://hermann-sw.github.io/planar_graph_playground
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/

carldani
Posts: 113
Joined: Wed Jan 11, 2012 12:08 am

Re: How to verify camera version with i2cset/i2cget?

Mon Nov 23, 2020 8:28 pm

I rewrote a few parts of the script to handle the HDMI-to-CSI bridge case and the Pi Camera case both if the TC358743 (Auvidea B101) dtoverlay is present or not. https://gist.github.com/Hermann-SW/3c03 ... nt-3537997

Return to “Camera board”