Arducam Mega SPI Camera

KeithB

Member
Has anyone had any experience with the Arducam Mega cameras at all that could assist me.
I have a 5MP version of this camera. The camera communicates with the Teensy 4.0 via the SPI interface.
I have got the camera talking but am having trouble getting any sensible data out of the camera.
To test the camera, I have set it to 96x96 resolution.
The camera can output data in JPG, RGB and YUV formats.
If I fetch the data in JPG format and save the data to an SD card file, I can view the data on my computer and I can see the image. Therefore, I know that I am grabbing the data from the camera correctly.
However, I want the data in RGB format for additional processing later on.
When I set RGB format, I get 18432 bytes of data which makes sense if the pixel data is spread over 2 bytes.
However this data does not represent Any image. I have tried interpreting the data as 565, 555 and 444 bits. I have even reversed the bit order for the pixel word.

I am now a little lost as to what else to try. I can not find anything online regarding for data format, hence asking here.

regards
Keith
 
The C API docs here have an enumerator for CAM_IMAGE_PIX_FMT_RGB565. Looks like RGB is 565. Maybe play with that a bit more?

Pete
 
Has anyone had any experience with the Arducam Mega cameras at all that could assist me.
I have a 5MP version of this camera. The camera communicates with the Teensy 4.0 via the SPI interface.
I have got the camera talking but am having trouble getting any sensible data out of the camera.
To test the camera, I have set it to 96x96 resolution.
The camera can output data in JPG, RGB and YUV formats.
If I fetch the data in JPG format and save the data to an SD card file, I can view the data on my computer and I can see the image. Therefore, I know that I am grabbing the data from the camera correctly.
However, I want the data in RGB format for additional processing later on.
When I set RGB format, I get 18432 bytes of data which makes sense if the pixel data is spread over 2 bytes.
However this data does not represent Any image. I have tried interpreting the data as 565, 555 and 444 bits. I have even reversed the bit order for the pixel word.

I am now a little lost as to what else to try. I can not find anything online regarding for data format, hence asking here.

regards
Keith
This brings back memories of the hours I spent on various video drivers. One of the most common problems I encountered was that many cameras returned 16-bit RGB565 data--but with BYTES swapped---not with the bit order reversed. Most often, I was able to reverse the byte order either within the CSI interface or by using Pixel Processing Pipeline (PXP). You can do a brute force test like this:

Code:
repeat
Read byte1 and byte2 from input buffer
Write byte2, then write byte1 to output buffer
until done

Then you have to run some code to convert the output buffer, treated as 16-bit words, from RGB565 to an array of 3-byte R,G,B 8=-bit values.
 
I figured it out. Sharing in case someone else is stuck on the same thing.

C++:
#include <SPI.h>
#include <Arducam_Mega.h>

Arducam_Mega myCAM(SS);
DMAMEM uint8_t jpg_buf[25000];

uint8_t readBuf(uint8_t* buf, uint8_t len) {
  static uint32_t index = 0;
  if (buf[0] == 0xff && buf[1] == 0xd8) index = 0;
  memcpy(&jpg_buf[index], buf, len);
  index += len;
  jpg_len = index;
  return 1;
}

void setup() {
  myCAM.begin();
  myCAM.registerCallBack(readBuf, 255, []() {});
  myCAM.startPreview(CAM_VIDEO_MODE_0); // 320x240
}

void loop() {
  myCAM.captureThread();

  if (jpg_len > 0 && jpg_len == myCAM.getTotalLength()) {
   // process
  }
}
 
Back
Top