ArduCAM/BeagleboneBlack

ov5640 problem

Opened this issue · 15 comments

el-j commented

i try to use the cam with the pocketbeagle.
sadly everything is for 5642 only. is there any idea how i get this to work with the 5640 variant. i just need to capture a picture.

i try to find an answer in the orginal arduino-library. sadly without any luck.
someone have any advice how i can use this cam?

el-j commented

ok, i managed to get the code from BBBCAM_OV5642_DigitalCamera to find the OV5640.
I added the related code from the original ArduCam.h and ArduCam.c to BBBCam.h and BBBCam.c
since that i got the output that the cam is found.

now the problem is that my Setup() ends with InitCAM() and seems never to return back to the main-void which will do the capturing logic. any idea why this happens?

/*
 ============================================================================
 Name        : BBBCAM_OV5640_DigitalCamera.c
 Author      : Lee
 Version     : V1.0
 Copyright   : ArduCAM demo (C)2015 Lee
 Description :
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
// #include "memorysaver.h"
#include "UTFT_SPI.h"
#include "BBBCAM.h"

#define BOOL int
#define TRUE 1
#define FALSE 0

#define OV5640_CHIPID_HIGH 0x300a
#define OV5640_CHIPID_LOW 0x300b
#define OV5640_MAX_FIFO_SIZE		0x7FFFFF		//8MByte
#define SHUTTER_MASK       		0x02
#define BUF_SIZE 4096
// #define CAM1_CS 0x15c

void setup()
{
  uint8_t vid,pid;
  uint8_t temp;

  UTFT();
  ArduCAM(OV5640);
  printf("ArduCAM Start!\n");



  //Check if the ArduCAM SPI bus is OK
  write_reg(ARDUCHIP_TEST1, 0x55);
  temp = read_reg(ARDUCHIP_TEST1);
  // printf(temp);
  if(temp != 0x55)
  {
  	printf("SPI interface Error!\n");
  	while(1);
  }
  else
    printf("SPI interface SEEMS OK!!!\n");

  //Change MCU mode
  write_reg(ARDUCHIP_MODE, 0x00);

  // InitLCD();

  //Check if the camera module type is OV5640
  rdSensorReg16_8(OV5640_CHIPID_HIGH, &vid);
  printf("vid is : %x",vid);
  rdSensorReg16_8(OV5640_CHIPID_LOW, &pid);
  printf("   pid is : %x\n",pid);
  if((vid != 0x56) || (pid != 0x40))
  	printf("Can't find OV5640 module!\n");
  else
  	printf("OV5640 detected\n");

  //Change to BMP capture mode and initialize the OV5640 module
  set_format(JPEG);

  InitCAM();

}

int  main(void)
{
	BOOL isShowFlag = TRUE;
	int nmemb = 1;
  // set_format(BMP);

	setup();
  printf("after setup");

  printf("after initCam in setup");

	while(1)
	{
		uint8_t buf[256];
		static int i = 0;
		static int k = 0;
		static int n = 0;
		uint8_t temp,temp_last;
		uint8_t start_capture = 0;
    // printf("%d\n",read_reg(ARDUCHIP_TRIG));
    // printf("wait trigger");

		//Wait trigger from shutter buttom
		if(read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK)
		{
      printf("read something\n");
			isShowFlag = FALSE;
			write_reg(ARDUCHIP_MODE, 0x00);
			set_format(JPEG);
			InitCAM();
			write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);		//VSYNC is active HIGH

			//Wait until buttom released
			while(read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK);
			delayms(1000);
			start_capture = 1;

		}
		else
		{
			if(isShowFlag )
			{
				temp = read_reg(ARDUCHIP_TRIG);
				if(!(temp & VSYNC_MASK))				 			//New Frame is coming
				{
          // printf("else and isShowFlag");
					write_reg(ARDUCHIP_MODE, 0x00);    		//Switch to MCU
					resetXY();
					write_reg(ARDUCHIP_MODE, 0x01);    		//Switch to CAM
					while(!(read_reg(ARDUCHIP_TRIG)&0x01)); 	//Wait for VSYNC is gone
				}
			}
		}
		if(start_capture)
		{
      printf("try to Capture\n");

			//Flush the FIFO
			flush_fifo();
			//Clear the capture done flag
			clear_fifo_flag();
			//Start capture
			capture();
      printf("Start Capture\n");
		}

		if(read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
		{

			printf("Capture Done!\n");

			//Construct a file name
			memset(filePath,0,20);
			strcat(filePath,"/home/debian/");
			getnowtime();
			strcat(filePath,nowtime);
			strcat(filePath,".bmp");
			//Open the new file
			fp = fopen(filePath,"w+");
			if (fp == NULL)
			{
				printf("open file failed");
				return 0;

			}
			i = 0;
			temp = read_fifo();
			//Write first image data to buffer
			buf[i++] = temp;
      // printf("%d\n",temp);
			//Read JPEG data from FIFO
			while( (temp != 0xD9) | (temp_last != 0xFF) )
			{

				temp_last = temp;
				temp = read_fifo();
        // printf("%d\n",temp);
				//Write image data to buffer if not full
				if(i < 256)
					buf[i++] = temp;
				else
				{
					//Write 256 uint8_ts image data to file
					fwrite(buf,256,nmemb,fp);
					i = 0;
					buf[i++] = temp;
				}
			}
			//Write the remain uint8_ts in the buffer
			if(i > 0)
				fwrite(buf,i,nmemb,fp);

			//Close the file
			fclose(fp);

			//Clear the capture done flag
			clear_fifo_flag();
			//Clear the start capture flag
			start_capture = 0;

			set_format(BMP);
			InitCAM();
			isShowFlag = TRUE;
		}
	}
}

el-j commented

hi there. thank for your reply. i use the ArduCam Mini-5Mp-Plus Module attached to spi0 and i2c-1.

20171220_130021
20171220_130029

el-j commented

ok i tested with arduino uno and everything works fine with the module.
20171220_134646

so i will switch back to the beaglebone. any idea how i can get this to work?

el-j commented

how do i do this? i switched the sda sdl to my arduino and the spi pins to the bone. the app now prints out a spi error when i try to connect:
image

el-j commented

ok i try this without any progress. but now i realize the vid and pid changed after this test. how is this possible?

el-j commented

ok this was a strange bug. now they are back to

vid = 0x56
pid = 0x40

but no real image. shouldn't it be possible when the programm is running that i get connection via ArduCAM_Host_V2?

el-j commented

so the programm runs till InitCAM() gets the case for the camera model,
but seems to stand still after reaching the first wrSensorReg16_8 methode.

image

maybe you could be more specific in how i can test the cam with beaglebone and arduino ...

el-j commented

hello, after a while of experimenting, i have a problem with the arduChip_Trig.
when i use the bmp mode, the Arduchip_trig changes from 1 to 8 and leaves the capture while.
but when i change the format to JPEG it ARDUCHIP_TRIG does not change. the while loop runs infinit.

while (!(read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK))

do you have any suggestion why this happens?

i used the // ArduCAM Mini 5MP demo (C)2017 Lee and the newest ArduCam library and add alle the differences to the BBBCam library. i really need to get this to work. so any help or idea why the "capture done" flag does not change will help me.

thank you very much

int main(void)
{

  uint8_t temp;
  uint8_t tempData = 0, tempData_last = 0;

  printf("tut er was ? \n");
    setup();
  printf("back from setup \n");
  delayms(1000);
  //VSYNC is active HIGH
  // Flush the FIFO
  flush_fifo();
  // Clear the capture done flag
  clear_fifo_flag();

  // Start capture
  printf("Start capture\n");
  temp = read_reg(ARDUCHIP_TRIG);
  printf("after capture ARDUCHIP_TRIG %x \n", temp);

  capture();
  // while (!(read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)){
  while ((read_reg(ARDUCHIP_TRIG) == 1) ){
    temp = read_reg(ARDUCHIP_TRIG);
    printf("CAPTURING %x \n", temp);
}
//never reaches this point. stuck in while loop ARDUCHIP_TRIG stays at 1
  printf("CAM Capture Done %x \n", temp);

void setup()
{
  uint8_t temp;
  uint8_t vid,pid;
  printf("im Setup \n");
  // system(DECONFIGCSPIN);
  ArduCAM(OV5640);

  write_reg(ARDUCHIP_TEST1, 0x54);
  // delayms(1000);
  temp = read_reg(ARDUCHIP_TEST1);
  printf( "ARDUCHIP_TEST1: %X \n", temp);

  write_reg(ARDUCHIP_TEST2, 0x84);
  // delayms(1000);
  temp = read_reg(ARDUCHIP_TEST2);
  printf( "ARDUCHIP_TEST2: %X \n", temp);

  printf( "SensorAddress: %X \n", myCAM.sensor_addr);

  write_reg(ARDUCHIP_MODE, 0x00);
  // delayms(1000);
  temp = read_reg(ARDUCHIP_MODE);
  printf( "ARDUCHIP_MODE: %X \n", temp);
  //
  rdSensorReg16_8(OV5640_CHIPID_HIGH, &vid);
  printf( "OV5640_CHIPID_HIGH:%x \n", vid);

  rdSensorReg16_8(OV5640_CHIPID_LOW, &pid);
  printf( "OV5640_CHIPID_LOW:%x \n", pid);

  if((vid != 0x56) || (pid != 0x40))
  printf("Can't find OV5640 module!");
   else
   printf("OV5640 detected.\n");

   set_format(JPEG);
   OV5640_set_JPEG_size(OV5640_320x240);
   delayms(1000);
   InitCAM();
   write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
   printf("after set VSYNC active HIGH \n");
   // OV5640_set_JPEG_size(OV5640_2592x1944); //2592x1944 QSXGA

   // Let auto exposure do it's thing after changing image settings
   delayms(1000);
   // Clear the capture done flag
   clear_fifo_flag();
}

Hi,
Do you have any progress here?
I'm using PocketBeagle, however, images are broken.
I can communicate with a camera with both I2C and SPI:

screenshot_20180528_121300

By Using Arduino Mega ADK and the code from github, I can capture images from the camera.

However, on a BeagleBone (pocket in my case) the captured data is not a relevant jpeg.