Hello !
In this project I use :
Arduino Mega 2560 R3
Arducam shield 5MP Plus
Adafruit 2.8" TFT Touch Shield
With the code below, I manage to capture an image in the camera FIFO, to read it and to display it on the TFT screen, the only problem is that I get weird colors, as you can see in the realtime.jpg attachment.
If I write the data to the SD card instead of pushing the colors to the TFT, the result is great, see the Preview.jpg attachment.
The camera is set to capture 320x240 RGB565 BMP.
Do you have any idea why I get this weird color palette ?
Thank you !
#include <SPI.h>
#include <Wire.h>
#include <ArduCAM.h>
#include <Adafruit_GFX.h> // Core graphics library
#include "Adafruit_ILI9341.h" // Hardware-specific library
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
const int CAM_CS = 53;
uint32_t length = 0;
byte VL,VH,dum;
uint8_t temp ;
uint8_t vid, pid;
int i,j;
uint16_t color;
ArduCAM myCAM(OV5642, CAM_CS);
void preview() {
myCAM.flush_fifo();
delay(100);
myCAM.clear_fifo_flag();
delay(100);
//Start capture
myCAM.start_capture();
while (!myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK));
Serial.println(F("CAM Capture Done."));
delay(100);
length = myCAM.read_fifo_length();
Serial.print(F("The fifo length is :"));
Serial.println(length, DEC);
dum = myCAM.read_fifo();
tft.startWrite();
tft.setAddrWindow(0, 0, 320, 240);
for (i = 0; i < 320; i++)
for (j = 0; j < 240; j++)
{
VL = myCAM.read_fifo();
VH = myCAM.read_fifo();
color = VH << 8 | VL; // build the 16bits color
tft.pushColor(color);
}
tft.endWrite();
delay(100);
}
void setup() {
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
Wire.begin();
Serial.begin(115200);
Serial.println(F("ArduCAM Start!"));
pinMode(CAM_CS, OUTPUT);
digitalWrite(CAM_CS, HIGH);
// initialize SPI:
SPI.begin();
//Reset the CPLD
myCAM.write_reg(0x07, 0x80);
delay(100);
myCAM.write_reg(0x07, 0x00);
delay(100);
myCAM.InitCAM();
while(1){
//Check if the ArduCAM SPI bus is OK
myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
temp = myCAM.read_reg(ARDUCHIP_TEST1);
if(temp != 0x55)
{
Serial.println(F("SPI interface Error!"));
delay(1000);continue;
}else{
Serial.println(F("SPI interface OK."));break;
}
}
while(1){
//Check if the camera module type is OV5642
myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid);
myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid);
if ((vid != 0x56) || (pid != 0x42)){
Serial.println(F("Can't find OV5642 module!"));
delay(1000);continue;
}else{
Serial.println(F("OV5642 detected."));break;
}
}
}
void loop() {
preview();
delay(100);
}