Simulink with Raspberry Pi Camera Capture

25 views (last 30 days)
Hi all,
As is documented here, http://www.mathworks.co.uk/help/simulink/raspberry-pi.html, simulink offers hardware functionality with the Pi, however there are no functions or examples for using the new pi cameras. Such as image capture, instead there is only support for webcam video capture.
Would using the camera be easy to implement without this support, or do I need to find another method other than simulink?
Thanks

Accepted Answer

Murat Belge
Murat Belge on 19 Mar 2014
The Raspberry Pi camera is supported by the Simulink. The Raspberry Pi Simulink Block library has a block called "V4L2 Video Capture". This block can capture images from any camera that has a V4L2 driver. Raspberry Pi foundation has recently released a V4L2 driver for the pi camera. Hence this block is compatible with the Raspberry Pi camera. Also note that the new (R2014a) MATLAB Support Package for Raspberry Pi Hardware supports capturing images from the Raspberry Pi camera module directly from the MATLAB command line.
In order to use V4L2 Video Capture Simulink block with the Raspberry Pi camera module, follow the instructions below (step 1 & 2 below is needed only for R2013a/R2013b releases):
1. Upgrade your Raspbian image to the latest to get the official V4L2 driver for Camera Board:
# sudo apt-get update
# sudo apt-get dist-upgrade
# sudo rpi-update
2. Reboot
# sudo reboot
3. After reboot, execute the following command to load the V4L2 driver for the Raspberry Pi Camera:
# sudo modprobe bcm2835-v4l2
After this step, you should see a /dev/video0 device (check by "ls -al /dev/vid*") that corresponds to the Camera Board. Now use the V4L2 Video Capture Block to capture images from this video device.
Note that you need to perform step 3 above every time you reboot your board. You can incorporate the command in step 3 into "/etc/rc.local" to automatically load the V4L2 driver at boot time.
  3 Comments
Jose
Jose on 12 Sep 2014
Hi Chris,
You can put that line in rc.local before "exit 0" line:
[...]
su -c "sudo modprobe bcm2835-v4l2" pi
exit 0
Zuzanna
Zuzanna on 7 Jan 2016
Edited: Zuzanna on 7 Jan 2016
For me it wasn't working. After tuning off and on the Raspberry Pi I had to type sudo modprobe bcm2835-v4l2 again...
But this tutorial helped me a lot:
I think that crucial thing is to load drivers manualy (modprobe bcm2835-v4l2) and than add sth to any file.

Sign in to comment.

More Answers (1)

Will
Will on 19 Mar 2014
Thanks Murat, Greatly appreciated.
  1 Comment
Hamza Idris
Hamza Idris on 7 Jan 2017
hey Murat! after the process you defined above. I have a code of matlab fcn taking snapshot using command image=snapshot(cam) let cam be camera function do i need to use this command now. please help..

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!