User avatar
HermannSW
Posts: 1657
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

[email protected]:~ $ 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
[email protected]:~ $

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://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7568
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 Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
HermannSW
Posts: 1657
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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

[email protected]:~ $ raspistill -v -t 1 2>&1 | grep Width
Width 2592, Height 1944, quality 85, filename (null)
[email protected]:~ $ 
[email protected]:~ $ 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
[email protected]:~ $ 

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

Code: Select all

[email protected]:~ $ raspistill -v -t 1 2>&1 | grep Width
Width 3280, Height 2464, quality 85, filename (null)
[email protected]:~ $ 
[email protected]:~ $ 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
[email protected]:~ $ 


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

[email protected]:~/raspiraw $ raspistill -v -t 1 2>&1 | grep Width
Width 3280, Height 2464, quality 85, filename (null)
[email protected]:~/raspiraw $ 
[email protected]:~/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
[email protected]:~/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

[email protected]:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 10"
[email protected]:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 36"
30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 
[email protected]:~ $ 

Code: Select all

[email protected]:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 10"
10: 10 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
[email protected]:~ $ ( cd ~/raspiraw ; camera_i2c 2>&1 > /dev/null ; i2cdetect -y 0 ) | grep " 36"
[email protected]:~ $ 
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1657
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

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://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “Camera board”