RaspiCam for Computer Vision

Discussion and questions about programming with Ultibo.
Gavinmc42
Posts: 1589
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: RaspiCam for Computer Vision

Postby Gavinmc42 » Sun Nov 19, 2017 12:11 pm

Was using B model compile option
Same code on a Zero, 38 is low.
Recompiled for a Zero 38 is an input.

Zero seems a little different than B+, A+ re GPIO 38.
What GPIO is the activity LED?
Gavinmc42
Posts: 1589
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: RaspiCam for Computer Vision

Postby Gavinmc42 » Sun Nov 19, 2017 12:27 pm

Whew googled some answers
https://raspberrypi.stackexchange.com/q ... -pi3/67433

GPIO 38 is high power USB, 47 is act led.
Start.elf is probably not going to leave the CAM_GPIOs floating as inputs, so GPIO 32, 41 are the CAM_GPIOs?
Will look for more confirmation.
Gavinmc42
Posts: 1589
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: RaspiCam for Computer Vision

Postby Gavinmc42 » Sun Nov 19, 2017 1:15 pm

This explains why I could not find which goes to which on the CM schematics.
https://www.raspberrypi.org/documentati ... -camera.md
Devicetree magic ;)

Where is the devicetree source :D
https://github.com/raspberrypi/firmware ... t-blob.dts
I think dt-blob.dts is the default one in start.elf.
Wow quite some difference between Zero and Zero W

As suspected 32, 41 are the 2 camera gpio's on the A+, B+.
GPIO32 is camera led and 41 is camera shutdown.
Good clues in this device tree stuff, been avoiding it, now I understand it's usefulness.
Camera LED and shutdown external 5, 6 which would be the gpio expander on the Pi3.

So GPIO 41 will enable the camera on Zero, A+, B+ and Pi2, this means i2c0 should be able to then detect and read/write the sensor.
But that's for another day ;)
Gavinmc42
Posts: 1589
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: RaspiCam for Computer Vision

Postby Gavinmc42 » Mon Nov 20, 2017 6:09 am

This has a link
https://www.raspberrypi.org/forums/view ... 7&start=25
to this
https://github.com/6by9/userland/blob/rawcam/camera_i2c

That translates below code, but my i2cdetect cannot find the camera.
Camera is working as I can run a timelapse image program.
So is there some magic reset, reboot command the camera needs?

Try i2cdetect after raspistill has set it up and taken a picture?

This is what needs to be done to grab the V2 registers.
The IMX219 has yet to be unNDAed, the register settings are "secret" for most configurations.
By dumping the register settings after each image setting change, 6by9 can then open up raspiraw even more for the V2.

Tried putting these GPIO config changes before and after getting the PI2CDevice, no luck.
Run out of ideas :(
Need new eyes to look at this.

Code: Select all

program i2cdetect;

{$mode objfpc}{$H+}

{ Raspberry Pi Application                                                     }
{  Add your program code below, add additional units to the "uses" section if  }
{  required and create new units by selecting File, New Unit from the menu.    }
{                                                                              }
{  To compile your program select Run, Compile (or Run, Build) from the menu.  }

uses
  Initunit,
  RaspberryPi,
  GlobalConfig,
  GlobalConst,
  GlobalTypes,
  Platform,
  Threads,
  Console,
  GraphicsConsole,
  Framebuffer,
  Devices,
  GPIO,
  I2C,
  SysUtils,
  DateUtils,
  Classes,
  Ultibo,  { Add additional units here }
  UltiboUtils,  {Include Ultibo utils for some command line manipulation}
  Syscalls,     {Include the Syscalls unit to provide C library support}
  VC4;          {Include the VC4 unit to enable access to the GPU}

var

 WindowHandle:TWindowHandle;
 WindowHandle2:TWindowHandle;
 I2CDevice:PI2CDevice;
 Address:Word;
 Numbytes:LongWord;
 Register:LongWord;
 Data:Word;
 Hexadd:String;
 Hexdata:String;

 argc:int;      {Some command line arguments to pass to the C code}
 argv:PPChar;
 filename:String;
 fileno:int;

 {Link our C library to include the original example}
{$linklib raspistill}

{Import the main function of the example so we can call it from Ultibo}
function vcraspistill(argc: int; argv: PPChar): int; cdecl; external 'raspistill' name 'vcraspistill';



begin
  { Add your program code here }
 FRAMEBUFFER_CONSOLE_DEFAULT_DESKTOPCOLOR:=COLOR_BLUE;
 WindowHandle:=ConsoleWindowCreate(ConsoleDeviceGetDefault,CONSOLE_POSITION_LEFT,True);
 WindowHandle2:=ConsoleWindowCreate(ConsoleDeviceGetDefault,CONSOLE_POSITION_RIGHT,True);

 //GPIOOutputSet(GPIO_PIN_28,GPIO_PULL_UP );
 //GPIOPullSelect(GPIO_PIN_29,GPIO_PULL_UP );

 //GPIOFunctionSelect(GPIO_PIN_0,GPIO_FUNCTION_IN);
 //GPIOFunctionSelect(GPIO_PIN_1,GPIO_FUNCTION_IN);

 //GPIOFunctionSelect(GPIO_PIN_28,GPIO_FUNCTION_IN);
 //GPIOFunctionSelect(GPIO_PIN_29,GPIO_FUNCTION_IN);

// GPIOFunctionSelect(GPIO_PIN_28,GPIO_FUNCTION_ALT0);
 //GPIOFunctionSelect(GPIO_PIN_29,GPIO_FUNCTION_ALT0);

 //GPIOOutputSet(GPIO_PIN_41,1);
 //GPIOOutputSet(GPIO_PIN_32,1);



 sleep(100);

 I2CDevice:=PI2CDevice(DeviceFindByDescription('BCM2835 BSC0 Master I2C'));

 GPIOFunctionSelect(GPIO_PIN_0,GPIO_FUNCTION_IN);
 GPIOFunctionSelect(GPIO_PIN_1,GPIO_FUNCTION_IN);

 GPIOFunctionSelect(GPIO_PIN_28,GPIO_FUNCTION_IN);
 GPIOFunctionSelect(GPIO_PIN_29,GPIO_FUNCTION_IN);

 GPIOFunctionSelect(GPIO_PIN_28,GPIO_FUNCTION_ALT0);
 GPIOFunctionSelect(GPIO_PIN_29,GPIO_FUNCTION_ALT0);

 GPIOOutputSet(GPIO_PIN_41,1);
 GPIOOutputSet(GPIO_PIN_32,1);


 while True do
  begin
       if I2CDeviceStart(I2CDevice,100000) <> ERROR_SUCCESS then
       begin
            //Error Occurred
           ConsoleWindowWriteLn(WindowHandle,'i2c error!!');
       end
  else
      for Address:=$01 to $7f do
          begin
              Numbytes:=1;
              Register:=0;
              if I2CDeviceWriteRead(I2CDevice,Address,@Register, Numbytes, @Data,SizeOf(Byte),Numbytes) = ERROR_SUCCESS then
                 begin
                     Hexadd:=IntToHex(Address, 2);
                     Hexdata:=IntToHex(Data, 2);
                     ConsoleWindowWrite(WindowHandle, ' 0x' + Hexadd + ' 0x' + Hexdata );
                     ConsoleWindowWrite(WindowHandle2, 'i2c address=0x' + Hexadd + ' data=');

                     for Register:=$00 to $07 do
                         begin

                             if I2CDeviceWriteRead(I2CDevice,Address,@Register,Numbytes,@Data,SizeOf(Byte),Numbytes) = ERROR_SUCCESS then
                                 begin
                                      Hexdata:=IntToHex(Data, 2);
                                      ConsoleWindowWrite(WindowHandle2,  ' 0x' + Hexdata );
                                 end;
                         end;
                     ConsoleWindowWriteLn(WindowHandle2, '');
                     ConsoleWindowWriteLn(WindowHandle2, '');
                     if Address MOD 8 = 0 then
                        begin
                             ConsoleWindowWriteLn(WindowHandle, '');
                        end;
                 end
              else
                 begin
                     Hexadd:=IntToHex(Address, 2);
                     ConsoleWindowWrite(WindowHandle, ' 0x' + Hexadd + '____' );
                     if Address MOD 8 = 0 then
                        begin
                             ConsoleWindowWriteLn(WindowHandle, '');
                        end;

                 end;
          end;
    ConsoleWindowWriteLn(WindowHandle, ' ');
    ConsoleWindowWriteLn(WindowHandle, ' ');
   Sleep(3000);
 end;

 {We're not doing a loop this time so we better halt this thread before it exits}
 ThreadHalt(0);

end.
Gavinmc42
Posts: 1589
Joined: Sun Jun 05, 2016 12:38 pm
Location: Brisbane, Australia

Re: RaspiCam for Computer Vision

Postby Gavinmc42 » Tue Nov 21, 2017 2:39 am

An old Pi post led me to this, lots of i2c interfaces with quite a few cameras.
http://elixir.free-electrons.com/linux/ ... /media/i2c
Useful to figure out read and write methods to the registers which have 2 bytes for addressing.
I sure hope there are not 65K+ registers :o

The Pi3 can map i2c1 to the camera, so that will be my next testing.
aarondc
Posts: 3
Joined: Thu Dec 13, 2018 6:49 am

Re: RaspiCam for Computer Vision

Postby aarondc » Tue Mar 12, 2019 1:14 am

An interesting video by BlackMagic design on face detection using OpenCV: https://www.youtube.com/watch?v=K_am9oMeweA

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest