Arduino Forum

Products => MKR Boards => MKRVIDOR4000 => Topic started by: a2retro on Jul 28, 2018, 05:31 pm

Title: Raspberry Pi Camera V2.1
Post by: a2retro on Jul 28, 2018, 05:31 pm
Hi Dario,

what would be involved in supporting the Pi V2.1 Camera based on the Sony IMX219 8-megapixel sensor?
Title: Re: Raspberry Pi Camera V2.1
Post by: dariopennisi on Jul 29, 2018, 12:42 am
hi,
this is in the list of TODOs. it should be fairly straightforward as you just need to copy the i2c initialization so that it ouputs 640x480 and that should be it but we didn't have time to do it.

if you look at the code for the OV camera (which if i'm not wrong is pi camera 1.3) you'll see that we basically just send a bunch of i2c commands we got from the linux driver
Title: Re: Raspberry Pi Camera V2.1
Post by: a2retro on Jul 30, 2018, 12:01 am
Hi Dario,

I am not sure what is wrong but when I try to power up the Vidor with my camera plugged in the power light comes on but but module seems frozen. The reset button has not effect and it does not connect as a USB device. This is with the Vidor EnableCam sketch loaded.
Title: Re: Raspberry Pi Camera V2.1
Post by: a2retro on Jul 30, 2018, 12:57 am
Hi Dario,

is it normal for the Arduino Logo to be present in bootloader mode (Com 7 for me) and normal terminal mode (which is com6) as I see the logo on my vidor in both cases?

I made a slight change to the sketch and display a string right after the serial port is opened then I found this odd but I let the board sit powered on with VidorEnableCam loaded (no camera attached) and after approx 7 minutes I see the Power On string from the sketch. No failure msgs were printed.

Update: It looks like vcam.begin returns success when it times out after 7 minutes.


Title: Re: Raspberry Pi Camera V2.1
Post by: dariopennisi on Jul 30, 2018, 10:35 pm
hi Glenn,
its sort of normal. SDRAM is loaded with LOGO from boot image. the application image does not clear automatically the RAM so when it starts the LOGO is still there and is displayed. if you don't clear the screen with your sketch it'll remain there and you would be just writing over it.
camera is a layer that sits behind the OSD so you won't see it until you draw a box with transparent color.
it is not normal indeed that you get a timeout of 7 seconds... need to check where that comes from
Title: Re: Raspberry Pi Camera V2.1
Post by: a2retro on Aug 02, 2018, 03:15 pm
Just to be cleear it was 7 *minutes* not 7 seconds before it came back with "Power On". With no camera attached I don't think the behavior should be unexpected like that?
Title: Re: Raspberry Pi Camera V2.1
Post by: cospan on Aug 03, 2018, 02:06 pm
I added support for the Raspberry Pi V2 camera for a board I was working on and had to port the kernel driver for it I did get 640x480 video at 90FPS working.

When looking through the Rapsberry Pi kernel I couldn't find the I2C incantation to configure the IMX219 so I ended up using a logic analyzer to capture various settings as well as looking over other kernel drivers.

Here should be the sequence of steps to get the camera running:


The I2C Address of the camera is 0x10

The first value is the register address and the rest is the data to send to that address. I still have some of my commented code in there when I experimented with it. The platform I was using only supported 10-bit CSI so the clock settings at the end are configured for 10-bit data, but there are comments showing how to configure 8-bit data output.

Also this code expects an input clock of 24MHz


Code: [Select]


/* software reset */
{0x0103, 0x01},
{0x0100, 0x00},

/* Access Code needed to access registers over 0x3000 */
{0x30EB, 0x05},
{0x30EB, 0x0C},
{0x300A, 0xFF},
{0x300B, 0xFF},
{0x30EB, 0x05},
{0x30EB, 0x09},

/* number of csi lanes = 2 (1 + 1) */
{0x0114, 0x01},

/* dphy control: Auto */
{0x0128, 0x00},

/* external clock frequency = 24MHz */
{0x012A, 0x18}, // 24 MHz
{0x012B, 0x00}, // 000 KHz






//Configure the camera for 640x480 (1280x720 with 2X2 binning)


// analogue gain setting
{0x0157, 0x00},

// Frame Length: 569
{0x0160, 0x01}, {0x0161, 0x89},

//Coarse Time = 565 (Exposure, can be adjusted while the camera is running)
{0x015A, 0x02}, {0x015B, 0x35},

// Line Length: 3559
{0x0162, 0x0D}, {0x0163, 0xE8},



// Window Width: 2279 - 1000 = 1280 - 1

// crop_rect.left: 1000
{0x0164, 0x03}, {0x0165, 0xE8},
// crop_rect.width: 2279
{0x0166, 0x08}, {0x0167, 0xE7},

// Window Height: 1711 - 752 = 960 - 1 (2 X 480)

// crop_rect.top: 752
{0x0168, 0x02}, {0x0169, 0xF0},
// crop_rect.height: 1711
{0x016A, 0x06}, {0x016B, 0xAF},

// image width = 640
{0x016C, 0x02}, {0x016D, 0x80},
// image height = 480
{0x016E, 0x01}, {0x016F, 0xE0},



/* X odd increment */
//{0x0170, 0x03},
{0x0170, 0x01},

/* Y odd increment */
//{0x0171, 0x03},
{0x0171, 0x01},

/* Binning Mode: X (2) */
//{0x0174, 0x04},
{0x0174, 0x03}, //2X Analog Binning
//{0x0174, 0x00},

/* Binning Mode: Y (2) */
{0x0175, 0x03}, //2X Analog Binning
//{0x0175, 0x00},
//{0x0175, 0x02},

//  {0x0176, 0x01},
//  {0x0177, 0x01},






//Clock Settings


// CSI data format
{0x018C, 0x0A}, {0x018D, 0x0A}, //10-Bits
//{0x018C, 0x08}, {0x018D, 0x08}, //8-Bits

// PIXEL CLOCK USED TO DRIVE SENSOR)
// VTPXCK_DIV: 4: 1/4, 5: 1/5, 8: 1/8, 10: 1/10
{0x0301, 0x05}, // 10-bit configuration
//{0x0301, 0x04},   // 8-bit configuration

// VTSYS_DIV = 1: Divide by 1
{0x0303, 0x01},

// PREPLLCK_VT_DIV: 1: 1/1, 2: 1/2, 3: 1/3
{0x0304, 0x03}, //MUST BE 3 FOR 24MHz

// PREPLLCK_OP_DIV: 1: 1/1, 2: 1/2, 3: 1/3
{0x0305, 0x03}, //MUST BE 3 FOR 24MHz

// PLL_VT_MPY = 57 (Multiplier)
{0x0306, 0x00}, {0x0307, 0x39},

// OPPXCK_DIV (pixel bit depth): 8:1/8 10:1/10
{0x0309, 0x0A}, //10-Bits
//{0x0309, 0x08},   //8-Bits

// OPSYSCK_DIV (divide by two for double data rate): 1:1/2
{0x030B, 0x01},

// PLL_OP_MPY = 114 (Multiplier)
{0x030C, 0x00}, {0x030D, 0x72},

//Pixel Clock (10-bit Config): EXCLK_FREQ / PREPLLLCK_VT_DIV * PLL_VT_MPY / VTPXCK_DIV: 24MHz / 3 * 57 / 5 = 91 MHz

// CIS tunning
{0x455E, 0x00},
{0x471E, 0x4B},
{0x4767, 0x0F},
{0x4750, 0x14},
{0x4540, 0x00},
{0x47B4, 0x14},
{0x4713, 0x30},
{0x478B, 0x10},
{0x478F, 0x10},
{0x4793, 0x10},
{0x4797, 0x0E},
{0x479B, 0x0E},





//Start Video Stream
{ 0x0100, 0x01 }, /* mode select streaming on */



This doesn't cover the exposure time or gain:

The exposure time is controlled by:

EXPOSURE SETTINGS

MINIMUM:
{0x015A, 0x00} {0x015B, 0x01}

MAXIMUM:
{0x015A, 0x0D}, {0x015B, 0xE3}




GAIN SETTINGS
MINIMUM:
{0x0157, 0x01}, {0x0158, 0x00}

MAXIMUM:
{0x0157, 0x10}, {0x0158, 0x00}




I wish I could spend more time testing this out but at least someone can get started with this.

Dave
Title: Re: Raspberry Pi Camera V2.1
Post by: a2retro on Aug 03, 2018, 03:49 pm
@cospan Thanks for the information. I still cannot get past a hard hang when my vidor powers up with the camera attached. :(
Title: Re: Raspberry Pi Camera V2.1
Post by: dariopennisi on Aug 08, 2018, 05:57 pm
hi guys,
i'm having a look at this. apparently there's something preventing the boot image to run properly with the 2.1 camera. actually i had a look at the (reverse engineered) schematics of the camera and it looks like a pin that was previously input is now an output so also the vidorgraphics image will need to be updated.
i tried that on my side and regardless the update and some changes to the init struct to reflect 8 bit rather than 10 i don't get any picture. in order for vidor to work we have to lower pixel frequency at something below 50 MHz so i changed register 0x307 to 0x14 and 0x30d to 0x28 which should be fune but it doesn't seem to work.
any suggestions from who already used this sensor?
thanks,

Dario
Title: Re: Raspberry Pi Camera V2.1
Post by: dariopennisi on Aug 09, 2018, 10:40 pm
short update:
looks like there is an inrush current issue that is causing the board to lockup at boot if pi 2.1 camera is connected. we're working on a bootloader update that should fix this.
Title: Re: Raspberry Pi Camera V2.1
Post by: a2retro on Aug 11, 2018, 02:54 am
Thanks Dario, looking forward to the update.
Title: Re: Raspberry Pi Camera V2.1
Post by: a2retro on Sep 15, 2018, 06:02 pm
Hi Dario, can you confirm the Pi v2 camera works now with the current libraries?
Title: Re: Raspberry Pi Camera V2.1
Post by: dariopennisi on Sep 20, 2018, 07:41 pm
Hi,
unfortunately no. i have been testing it for a while and it looks like there may be an issue with powering it as its inrush current is quite high and it prevents board to boot properly. we are investigating it but it is not on top of the priorities as there is a lot of other cool stuff we're dealing with right now... (see other recent posts for details)
Title: Re: Raspberry Pi Camera V2.1
Post by: Caine78 on Dec 07, 2018, 11:24 pm
I found a bit of data here. I only a little know what you are talking about, so attempt to fix it is pointless by me.

It is a PITA to find the datasheet for the Sony IMX219 PQ Pi Camera V2 CMOS IC, so here it is if you need it.
https://www.reddit.com/r/raspberry_pi/comments/5fz4jb/it_is_a_pita_to_find_the_datasheet_for_the_sony/ (https://www.reddit.com/r/raspberry_pi/comments/5fz4jb/it_is_a_pita_to_find_the_datasheet_for_the_sony/)

That day will have to come, but maybe in 2-3 years time.

Edit:
Well. I did a bit of digging. Didn't managed to get it working. At least I have Arduino logo on the screen, not black screen with 1 pixel on it.


File: imx219mipiraw_Sensor.c
Line: 1140
//sensor have two i2c address 0x6c 0x6d & 0x21 0x20, we should detect the module used i2c address
Title: Re: Raspberry Pi Camera V2.1
Post by: Caine78 on Dec 08, 2018, 03:30 am
I couldn't attach the 3MB file here. The 2MB is only allowed. I had to extract RASPBERRY PI CAMERA V2 DATASHEET IMX219PQH5_7.0.0_Datasheet_XXX.PDF from original zip and post it separately.

Now I added more data to the server.
Title: Re: Raspberry Pi Camera V2.1
Post by: nwesemann on Apr 01, 2019, 08:02 pm
hi everyone, are there any news on getting the raspi camera to work?
Title: Re: Raspberry Pi Camera V2.1
Post by: jomoengineer on Jun 08, 2019, 09:00 pm
Hi, I have the same question.  Did anyone get this to work with a Raspberry Pi Camera V2 and the VidorEnableCam example?  I have a RasPi NoIR Camera v2.1 and I can not seem to get an image to show on the Vidor 4000 HDMI output.  There is no error from the Serial console and the screen seems to be active, but no camera image.  The camera works fine on a Raspberry Pi but not on the Vidor. 

The NoIR has a Sony IMX219 8-megapixel sensor i2c according to the Raspberry Pi site for the product.

Do I need to change the i2c address for this or something to get it work with the camera to enable in the VidorEnableCam example?

Thanks,

Jon
Title: Re: Raspberry Pi Camera V2.1
Post by: Cornejo on Jul 17, 2019, 07:40 am
I'm interested in getting a couple of Vidor MKR 4000 boards, but am waiting to see the outcome of the current posts, in particular post # 16 by jomoengineer.

I have the same question.

Thanks!