Arducam Mega SPI Camera example fails to compile on ESP32 (Arduino IDE)

Hey everyone, I’m trying to get my Arducam Mega SPI Camera working with an ESP32 board through the Arduino IDE. I installed the Arducam_Mega library via Library Manager and followed the official docs at MEGA SPI Camera - Arducam Wiki. Wiring looks correct, but when I try to compile the example sketch (esp32 capture), I’m getting a bunch of warnings and a fatal error. Here’s the full output:

c:\Users\jax20\OneDrive\Documents\Arduino\libraries\Arducam_Mega\src\Arducam\ArducamCamera.c:155:26: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  155 |     .cameraId          = "5MP",
      |                          ^~~~~
c:\Users\jax20\OneDrive\Documents\Arduino\libraries\Arducam_Mega\src\Arducam\ArducamCamera.c:171:26: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  171 |     .cameraId          = "3MP",
      |                          ^~~~~
c:\Users\jax20\OneDrive\Documents\Arduino\libraries\Arducam_Mega\src\Arducam\ArducamCamera.c: In function 'cameraGetSensorConfig':
c:\Users\jax20\OneDrive\Documents\Arduino\libraries\Arducam_Mega\src\Arducam\ArducamCamera.c:227:33: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  227 |         CameraInfo_5MP.cameraId = "5MP_2";
      |                                 ^
c:\Users\jax20\OneDrive\Documents\Arduino\libraries\Arducam_Mega\src\Arducam\ArducamSpi.cpp: In function 'void arducamSpiBegin()':
c:\Users\jax20\OneDrive\Documents\Arduino\libraries\Arducam_Mega\src\Arducam\ArducamSpi.cpp:18:21: error: return-statement with a value, in function returning 'void' [-fpermissive]
   18 |     return SPI.begin();
      |            ~~~~~~~~~^~
exit status 1

Compilation error: exit status 1

Anyone run into this before? Seems like the library itself might have some issues.

Quick update — I spent some time digging through the library source and I think I’ve tracked down the root causes:

  1. Fatal error in ArducamSpi.cpp (line 18): The function arducamSpiBegin() is declared void, but the body does return SPI.begin();. SPI.begin() returns a value, so you can’t return it from a void function. The fix would be either to change the return type of arducamSpiBegin() to match whatever SPI.begin() returns, or just drop the return keyword and call SPI.begin(); by itself.

  2. Const qualifier warnings in ArducamCamera.c (lines 155, 171, 227): The cameraId field in the struct appears to be declared as char* (non-const), but string literals like "5MP", "3MP", and "5MP_2" are being assigned to it. That’s what’s triggering the -Wdiscarded-qualifiers warnings. The proper fix would be to declare cameraId as const char* in the struct definition.

So it’s looking like bugs in the library itself rather than anything wrong with my setup. Has anyone patched these locally or is there an updated version of the library floating around?

Thanks for the detailed investigation — that’s really helpful. You’re spot on with both findings. The return SPI.begin() in a void function is definitely the showstopper, and those const-qualifier warnings point to some sloppiness in the struct definitions.

Before we go further down the rabbit hole — can you confirm which version of the Arducam_Mega library you have installed? You can check this in the Arduino Library Manager or by looking at the library.properties file inside the library folder. I want to see if this is something that’s already been addressed in a newer release or if it’s still present in the latest version.

Appreciate the response. I’ve since been able to sort things out on my end — ended up making the fixes directly in the library source and everything compiles and runs now. For anyone else hitting this: editing ArducamSpi.cpp to just call SPI.begin(); without the return and changing those cameraId fields to const char* in the struct got me past the errors. Not the cleanest solution if you plan to update the library later, but it works for now. Thanks!