Arducam: How to rotate the image

HI all. When i take a picture with Arducam the image appear rotated of 180°.
How can i take a correct picture or rotate the picture? thanks

Links? Code?

How can i take a correct picture

Turn the camera over.

ehe it isn't the way :stuck_out_tongue:

the camera module is OV5642.
the full code is below:
(thanks)

#include <UTFT.h>
#include <SD.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <avr/pgmspace.h>

//ArduChip registers definition
#define ARDUCHIP_DDR       0x00  //GPIO direction register
#define ARDUCHIP_PORT      0x01  //GPIO output register
#define ARDUCHIP_MODE      0x02  //Mode register
#define ARDUCHIP_PIN       0x80  //GPIO input register
#define ARDUCHIP_TRIG      0x81  //Trigger source
#define ARDUCHIP_REV       0x82  //CPLD revision


const char bmp_header[54] PROGMEM =
{
      0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 
      0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 
      0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00, 
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
  
#define SD_CS 9 
#define BMPIMAGEOFFSET 54

//UTFT(byte model, int RS, int WR, int RD, int CS)
//UTFT myGLCD(ITDB32S,A2,A1,A0,10);   // Remember to change the model parameter to suit your display module!
//ArduCAM(byte model,int RS, int WR, int RD, int REG_CS, int FIFO_CS)
ArduCAM myCAM(OV5642,A2,A1,A0,A3,10);  // Remember to change the model parameter to suit your canera module!

void setup()
{
  uint8_t gpio_trig;

  pinMode(13, OUTPUT);     
  pinMode(53, OUTPUT);     //per la cam
  
  //Initialize I2C Bus
  Wire.begin();   

  //Passa alla modalità FIFO
  myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
  //Inizializza il modulo della Camera
  myCAM.InitCAM();

  myCAM.write_reg( ARDUCHIP_DDR, 0x00);  //per il PIR
  
  //Inizializza Scheda SD
  while (!SD.begin(SD_CS)) 
  {
      pinMode(13, OUTPUT);
      digitalWrite(13, HIGH);   // se ci sono problemi accendi il led
      delay(20000);
      return;
  }
  
  delay(60000); //serve a dare il tempo al pir di acquisire il background
}

void loop()
{
  char str[8];
  File outFile;
  char VH,VL;
  int i,j = 0;
  int h=3;
  uint8_t gpio_trig;
    
  static int k = 0;
  uint8_t temp;
  uint8_t start_capture;
  
  start_capture=0;
  
/*
  gpio_trig = myCAM.read_reg(ARDUCHIP_PIN);   //Leggi il trigger da GPIO0~5

  if(gpio_trig & 0x01)  
  {  
    start_capture = 1;
  }
*/

  //riduco i falsi positivi
   h=3;
  while(h!=0)
  {                      
    gpio_trig = myCAM.read_reg(ARDUCHIP_PIN);   //Leggi il trigger da GPIO0~5

    if(gpio_trig & 0x01)  
    {  
      h=h-1;
    }
    else h=3;
    if(h==0) start_capture = 1;
  }
 
 
  //Comincia a salvare la foto se il PIR ha rilevato movimento
  if(start_capture)
  {
    //Flush the FIFO 
    myCAM.flush_fifo();		 
    //Start capture
    myCAM.start_capture();		 
  }
  //Polling the capture done flag
  if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
  {
    //Crea il nome del file
    k = k + 1;
    itoa(k, str, 10); 
    strcat(str,".bmp");
    
    //apri il nuovo file
    outFile = SD.open(str,FILE_WRITE);
    if (! outFile) 
      return;
      
    //Scrivi l'header BMP
    for( i = 0; i < 54; i++)
    {
      char ch = pgm_read_byte(&bmp_header[i]);
      outFile.write((uint8_t*)&ch,1);
    }
	
    //Abilita FIFO
    myCAM.enable_fifo();
    //Read the first dummy byte from FIFO
    temp = myCAM.read_fifo();
    //Read 320x240x2 byte from FIFO
    for(i = 0; i < 240; i++)
      for(j = 0; j < 320; j++)
    {
        VH = myCAM.read_fifo();
        VL = myCAM.read_fifo();
        //RGB565 to RGB555 Conversion
        VL = (VH << 7) | ((VL & 0xC0) >> 1) | (VL & 0x1f);
        VH = VH >> 1;
        //Write image data to file
        outFile.write(VL); 
        outFile.write(VH);
    }
    //Disable FIFO when all the image data is saved to the file
    myCAM.disable_fifo();
    //Close the file  
    outFile.close(); 
    
    //Clear the capture done flag 
    myCAM.clear_fifo_flag();
    //Clear the start capture flag
    start_capture = 0;
  }
}

the camera module is OV5642.

That link doesn't work,

#include <ArduCAM.h>

Speaking of links...

  uint8_t start_capture;
  
  start_capture=0;

It's allowed, and even a good idea, to initialize the variables as it is declared. Using one line instead of 3 is generally a good idea, when readability is not sacrificed. It would actually be improved in this case.

      h=h-1;
    }
    else h=3;
    if(h==0) start_capture = 1;

Consistent use of spaces is good. This isn't.
Consistent use of curly braces is good. This isn't.

Remember, too, that the Arduino is programmed in C++, not C=C+1.

    for(i = 0; i < 240; i++)
      for(j = 0; j < 320; j++)
    {
        VH = myCAM.read_fifo();

Consistent indenting
is good,
too.
This
isn't.

Without knowing anything about the camera, except its model number, and without knowing anything about the class you use to communicate with the camera, except its name, all I can guess is that somehow, you need to tell the camera that it is upside down and that you want it to rotate the image before it gives you the data.

If that is not possible, you'll need to read the data from the camera in a different order. Since it is a bitmap file you are creating, the data in the file is written pixel by pixel, in the same order that it is read from the camera (left to right, top to bottom). You can invert the image about one axis by reading right to left, top to bottom. You can invert the image about the other axis by reading left to right, top to bottom. You can invert about both axes by reading right to left, bottom to top.

sorry but your post (and humor) is really unusefull.
anyway your idea is bad. changing the order of pixels requires to save the complete image in local memory: arduino have too little memory to save 150KB or more. unless i can change the way to write a file: append or write the head of file. it seems to be very hard.
telling the camera i want to rotate the image is exactly what i'm looking for.
thanks anyway

I think the answare is in ARDUCHIP_TRIG or ARDUCHIP_TIM register. in both there is a bit for VSYNC_MASK and VSYNC_LEVEL_MASK that seems to be vertical sync.
I tried
myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
but i keep only a white picture. same for only the second line without the first.

tried also to change if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK) in if(myCAM.read_reg(ARDUCHIP_TRIG) & VSYNC_MASK), but nothing change

anyway your idea is bad. changing the order of pixels requires to save the complete image in local memory

Given the way that the library is structured, that may be true. That doesn't mean that there aren't alternate ways to write the library, or alternate methods in the library to read the data in a different order.

You're continuing to complain without posting links isn't helpful, either. If you don't want my help, I'll butt out and wish you luck.

sweetol:
telling the camera i want to rotate the image is exactly what i'm looking for.

Assuming the camera can do that, I would recommend contacting the manufacturer of the camera module for the appropriate commands. Then you can modify the library you are using to execute those commands.

I would be very surprised if the camera module supported such rotation.

A quick search of the datasheet doesn't seem to mention anything rotation.

hye.i am a beginner in arducam codes. I am using ov5642 camera module but i have problems with the coding.
can u check the codes.please help me.i dont know why i cannot compile the codes.

arducam_forum_edited.ino (4.85 KB)

sweetol:
HI all. When i take a picture with Arducam the image appear rotated of 180°.
How can i take a correct picture or rotate the picture? thanks

Can you just rotate the camera?