MATLAB Answers


How do I display images taken with an Arduino in MATLAB?

Asked by Joshua Werblin on 14 Apr 2017
Latest activity Answered by sushmitha Veeralingam on 4 Jul 2019 at 15:07
I have an Arduino UNO (but once I get this working, I am switching to a much more complicated system) with an Arducam OV5642 camera shield attached. I have it taking a 640x480 photo every ~10 seconds and I want a way to show the images in real time (the photo taking can be slowed down if necessary). The relevant section of my arduino code is below (sorry about formatting, this is my first time posting code):
void loop() {
uint8_t temp = 0xff, temp_last = 0;
uint8_t start_capture = 0;
temp =;
start_capture = 1;
Serial.println(F("ACK CMD CAM start single shot."));
if(start_capture == 1)
Serial.println("capture 'if' statement");
Serial.println("capture 'if' statement 2");
Serial.println("capture 'if' statement 3");
//Start capture
Serial.println("capture has been started");
temp = 0;
Serial.println(F("ACK IMG"));
while( (temp != 0xD9) | (temp_last != 0xFF) )
//D9 is in hex=217 in decimal. FF=255
//according to the ArduCam Support, the head of the image data is 0xFF 9xD8
//and the end of the data is 0xFF 0xD9
temp_last = temp;
temp = myCAM.read_fifo();
Serial.println(F("ACK CMD CAM Capture Done."));
//Clear the capture done flag
start_capture = 0;
The serial.println statements are just checks I was using to figure out where it went wrong. As you can see in the code, the head of the image data is 0xFF 9xD8 and the end of the data is 0xFF 0xD9. This information was given to me by the ArduCam Support team on their GitHub forum. How do I receive the stream data in MATLAB and display it as an image? Thanks!


Hello, Im getting same problem as yours. Did u get any solution for this? Actually i want to trigger my arducam OV5640 to take picture by an ultrasonic sensor and then upload that picture to a MATLAB program. Any idea how can I do that?
Hello, Were you able to trigger capturing images using ultrasonic sensor? Please share the code if succesful.
Bro i need to display an image in matlab when i press a number in keypad connected to aruduino,.pls help me with this

Sign in to comment.

1 Answer

Answer by sushmitha Veeralingam on 4 Jul 2019 at 15:07

I don't know much about arduino, but i am sure you can modify the code to save images to your PC. matlab can read images in a folder realtime and give outputs. i had a camera that could be sensed by matlab, so i wrote a python code to save the images to a folder and then used matlab for image processing.(improfile)


Sign in to comment.