Introduction: RASPBERRY PI + MATLAB = WI-FI IP-CAMERA
Are you a MATLAB user? Are you interested in programming and electronics? If so, we offer a simple way to make your own WI-FI IP-camera. All you need is a few hours and a basic knowledge of MATLAB. You can use this camera anywhere: from your DIY-projects to simply taking a look at what your dog is doing while you’re at work.
Step 1: Supplies
For the project you need:
1. MathWorks MATLAB
MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment and fourth-generation programming language. A proprietary programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, Fortran and Python. It features some useful libraries for image processing like Computer Vision Toolbox, Image Processing Toolbox and Image Acquisition Toolbox.
2. Raspberry Pi 2 model B
Raspberry Pi 2 packs up a 900MHz quad-core ARM Cortex-A7 CPU, VideoCore IV 3D graphics core and 1GB RAM. It can run a full range of ARM GNU/Linux distributions, including Snappy Ubuntu Core, as well as Microsoft Windows 10 (We tried Raspberry Pi A+ model too, and it worked!).
3. Raspberry Pi case
Nothing to write home about, really. Just an ordinary housing! (Mind the place for mounting a camera - not every housing has it!)
4. Raspberry Pi Camera Board
Raspberry Pi Camera Board uses a 5-Mpx CMOS OmniVision 5647 sensor with the resolution of 2592x1944 pixels. It supports 1080p30 and 720p60. The Pi NoIR gives you everything a regular camera module offers, with one difference: it does not employ an infrared filter. (NoIR = No Infrared.) This means that pictures you take in the daylight look decidedly curious, but when fitted with infrared lighting it allows you to see in the dark.
5. Power supply
We are using Huawei Power Bank (2000 mAh), but you can use any power source suitable for Raspberry Pi 2 Model B (mind that it should be rated for at least 700mA/5V).
6. WiFi Dongle
Use any dongle that supports 802.11n/g/b standards.
7. SD card
4GB or more.
8. HDMI cable
An ordinary HDMI cable is suitable for connection with Raspberry Pi 2 Model B (and a display).
Step 2: Assembling
Raspberry Pi Camera is connected to the main board via a ribbon cable. Connect the ribbon carefully, mind that contacts are on one side only. Place your board and a camera attached to it into the housing.
Step 3: Preparing Your Software
Now we’re going to download and install a toolbox for Raspberry Pi to be able to control our board via MATLAB.
Enter this command in MATLABs’ Command Window:
Then choose “Install From Internet” and click “Next”.
Look for “Support for Raspberry Pi”; mind that you need support only for MATLAB. Click “Next”.
Log in using your MathWorks Account, accept all licence agreements and wait for the support package to be downloaded and installed.
If you want to configure an Ethernet connection between your PC and RasPi you should check this video by Mathworks:
In our case we are configuring a wireless connection for our IPcam. At first, you need to go to your already installed MATLAB support package for Raspberry Pi folder, find the “raspbian” folder and RaspbianOS in it.
Use a SD Formatter tool (https://www.sdcard.org/downloads/formatter_4/) to deploy the image on your SD card or if you’re using Linux, you can upload this .img file to the SD following these steps:
Check available devices, find your SD-card device name:
sudo fdisk -l
check if your SD-card is currently mounted:
if it is, unmount it:
dd if=/path/to/img_file of=/dev/sdx bs=4M
Check this link for a more detailed approach:
Step 4: Configuring a Wireless Network
Now plug in your HDMI cable into your board and monitor, power up the board and wait for a Raspbian console to show up - we’re going to configure wireless network on your RasPi board.
1. Log in into Raspberry Board using the following credentials:
2. Change the root password (it is needed for our further actions):
Type in your root password and remember it.
3. Check available WiFi connection points:
Sudo iwlist wlan0 scan
PRO TIP: if you know ESSID, make
sudo iwlist wlan0 scan | grep MySSID
You will see the following output “ESSID: “MySSID”.
4. Log in as root, using the password you’ve created previously:
5. Write your SSID-password pair to the configuration file:
wpa_passphrase MY_SSID my_password >> /etc/wpa_supplicant/wpa_supplicant.conf
6. Get your IP-address:
8. Log in as:
Login : pi
9. Now try to ping some web-service to check if you are connected to your network:
If you see something like this...
64 bytes from wrw0ts25-nff14.1e100.net (184.108.40.206): icmp_seq=1 ttl=55 time=40.2 ms
... then you are now connected to you access point.
10. Then you need to expand your filesystem and configure the use of SPI:
-> choose “1. Expand Filesystem” -> select “9. Advanced Options” afterwards -> “A6 SPI” -> choose “Yes” -> again choose “Yes” on “Would you like the SPI kernel module to be loaded by default?” -> click “Finish” -> “Yes” on “Would you like to reboot?”
Step 5: Connecting Raspberry to MATLAB
Check this link and download the file attached to the article:
Unzip the contents and open the RaspiRemoteControl.m file in MATLAB by pressing F5 or starting the program as usual.
(Check the README.pdf file for some details about this program).
Step 6: Using WI-FI IP Camera
Now just power up your IP-cam, launch matlab and the RaspiRemoteControl.m file, type in onboard IP of Raspberry board, connect and start streaming. Disconnect from Raspberry first if you want to close the application.
That’s how it looks like (mind that we’re using Pi NoIR Camera Board as it has no InfraRed filter - that’s why everything looks kinda reddish, so if you want to see how it looks like with a normal one, remember to check the video at the end of the tutorial!).
Our team from RoboticsBy used this method to acquire control over a mobile robot. This control system is based on some computer vision algorithms. We used SIMULINK environment, so we got even more from images acquired. Check it out following the link below:
We have a be nice policy.
Please be positive and constructive.