Interfacing Camera with PIC Microcontroller via Matlab GUI

For project on security systems, Interfacing Camera with PIC Microcontroller via Matlab GUI is mostly desirable. But size internal ROM and RAM of PIC16F877 is very small. So it is very difficult or other word imposible to direct Interfacing Camera with PIC16f877 Microcontroller . But we can do it to introducing Matlab GUI and interfacing PIC16F877 with Matlab via UART communication using serial cable.

 Interfacing Camera with PIC16f877 Microcontroller via Matlab GUI

Project description:

In this project “Interfacing Camera with PIC Microcontroller via Matlab GUI”, we can do interfacing camera via Matlab. By using Matlab command we can easily initialized camera attaching with Computer. So if we establish communication between matlab with microcontroller (PIC16F877) and take control of Matlab command using Matlab GUI from microcontroller then we can easily control camera from our microcontroller. Using this logic we connect two push switch with microcontroller

  • 1>     Push button 1 :- If we press that then Camera will initialized.
  • 2>     Push Button 2 :- If we press that then Camera will take snapshot and store it to Hard Disk.

 In bellow I give the circuit diagram of this project.

camera circuit

Project Operation: – In this project we have to work on two different sectors.

1>     Create own Matlab GUI for interfacing Camera attach with Computer.

2>     Write a Program for sending control data via UART from PIC16F877.

Matlab GUI for interfacing Camera:

Now question is how to make Matlab GUI? And for that see the bellow video for making  simple push button via Matlab GUI or visit this post for know How to make matlab GUI.

 

And for our project we have write different program for our project Interfacing Camera with PIC Microcontroller via Matlab GUI.

Matlab Code

x=0;
while (x==0)
s = serial(‘COM1′,’BaudRate’,9600);
fopen(s);
    out=fscanf(s);
if (out==’a’)
vid = videoinput(‘winvideo’, 2, ‘YUY2_320x240’);
%to open preview window
preview(vid);
pause(5.0);
end
if (out==’b’)
%to capture image
data = getsnapshot(vid);
%to display capture image
figure
imshow(data)
delete (vid);
pause(5.0);
fclose(s);
clc;
end
pause(5.0);
fclose(s);
end

 


Program for sending control data via UART :

So as per above program I easily understand that we have to send character “a” via UART port when we press push button 1 for initializing Camera  and we have to send character “b” via UART port when we press push button 2 to take a snapshot.

Embedded C Code
// Name : Interfacing Camera with PIC Microcontroller via Matlab GUI

// Author : Subham Dutta
// Date : 24-03-14
// Website : www.nbcafe.in
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;void main() {
lcd_init();
Lcd_Cmd(_LCD_CLEAR);
lcd_out(1,1,”Camera Interface”);
lcd_out(2,1,”Left Button = On “);
trisb=1;
portb=0;
while(1)
{
if(portb==0b00000001)
{
Lcd_Cmd(_LCD_CLEAR);
lcd_out(1,1,”Wait….”);UART1_Init(9600); // Initialize UART module at 4800 bps
UART1_Write_Text(“a”);
Delay_ms(1000);
lcd_out(2,1,”intialized”);
}
if(portb==0b00000010)
{
UART1_Init(9600); // Initialize UART module at 4800 bps
UART1_Write_Text(“b”);
Delay_ms(1000);}
}
}

Must see the tutorial simulation video of our project

“Interfacing Camera with PIC Microcontroller via Matlab GUI”