Matlab cannot connect to the raspberry cameraboard

14 views (last 30 days)
Hi i'm trying to use my raspberry and the camera to do data acquisition and control with matlab but after the connection to the raspberry, matlab is not connecting to the camera. it's for a project and without that i can't do anything.
This is the error i receive with this both lines :
i've tried each and the result was the same.
cam = cameraboard(mypi, 'Resolution', '1280x720');
cam = mypi.cameraboard;
Warning: Response size for request ID 0xF150 is expected as 4 but received as 0.
> In matlabshared.ioclient/IOProtocol/isReservedRequestID
In matlabshared.ioclient/IOProtocol/getDataDecodePacketExternal
In matlabshared.ioclient/IOProtocol/processBufferedData
In matlabshared.ioclient/IOProtocol/fetchDataPtForUniqueIdFromTransportLayer
In matlabshared.ioclient/IOProtocol/commandResponse
In matlabshared.ioclient/IOProtocol/rawReadInternal
In matlabshared.ioclient/IOProtocol/processCommandQueue
In matlabshared.ioclient/IOProtocol/rawRead
In raspi.internal/LibCamera/open (line 725)
In raspi.internal/LibCamera (line 158)
In raspi.internal/RaspiBase/cameraboard (line 309)
In raspi.internal/RaspiHWSDKController/processInternal (line 1775)
In raspi.internal/RaspiHWSDKController/cameraboard (line 694)
In raspi/cameraboard (line 855)
Cannot connect to the Camera Board.
Caused by:
Index exceeds the number of array elements. Index must not exceed 1.
  4 Comments
Eduardo
Eduardo on 17 May 2025
Same problem, Rasberry Pi5 has support for camera???

Sign in to comment.

Answers (1)

Harsh
Harsh on 18 Aug 2025
I have encountered a similar issue before, and I recommend using only the Raspberry Pi operating systems listed on the following page:
From what I can gather from the comments is that you are using a 64-bit OS, but MATLAB R2024a only supports 32-bit operating systems. I suggest flashing your Raspberry Pi with a fresh 32-bit OS. Once you have installed the new OS, you can clean the existing MATLAB installation on your Raspberry Pi by running these commands in the terminal:
$ sudo pkill mwUnifiedSrvr
$ sudo rm -rf /opt/MATLAB
After this, you can proceed with creating a new "raspi" object and the "cameraboard" command should run fine. If you still encounter issues, I recommend contacting MathWorks Technical Support. You can create a support ticket using the following link:
I hope this helps, thanks!
  1 Comment
Matthew J
Matthew J 1 minute ago
I am having a similar issue. I am using matlab R2025b and Raspberry Pi 5. I've used both the raspberry pi OS 64-bit legacy (bookworm at the time of this posting) and the 32-bit with the same effect. Older versions of debian are not available on the latest Raspberry Pi Imager v1.9.3. I am running matlab from Debian 12 (bookworm) (amd64). My camera is the RPi HQ (12.3 MP) camera which uses an IMX477R sensor.
Running the code below, matlab occationally (~50%) errors out on cameraboard with error 1 below. Then the other 50% of the time the camera initiallized correctly and proceeded to take images, but never made it through a full 100 captures before error #2 below.
Harsh's pkill mwUnifiedSrvr and removing /opt/MATLAB fixed error #2, I now make it through a full 100 cycles when error #1 doesn't trigger.
clear rpi
clear cam
rpi = raspi(a,b,c);
cam = cameraboard(rpi,'Resolution','640x480');
for i = 1:100
img = snapshot(cam);
image(img);
drawnow;
end
% Error number 1
Error using captureImage (line 4)
Cannot connect to the Camera Board.
Caused by:
Error using matlabshared.ioclient.IOProtocol/rawRead
Timeout while receiving data from remote server
% Error number 2
Error using captureImage (line 6)
Error while capturing image.
If anyone is able to get this working on their end, please let me know what your setup is.

Sign in to comment.

Categories

Find more on Raspberry Pi Hardware in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!