Raspberry Pi 3 & MathWorks Learn-to-Program Pack - Review

Table of contents

RoadTest: Raspberry Pi 3 & MathWorks Learn-to-Program Pack

Author: ralphjy

Creation date:

Evaluation Type: Development Boards & Tools

Did you receive all parts the manufacturer stated would be included in the package?: True

What other parts do you consider comparable to this product?: OpenCV

What were the biggest problems encountered?: It was difficult for me to determine whether the MathWorks package had the specific capabilities that I required until I actually tried to implement the program. Though there were many examples and tutorials available on the Internet, most referenced older versions of the software and hardware. And since the software was the student version, no application support was available.

Detailed Review:

I have been working on a video monitoring system for my house using IP cameras.  I would like to add the capability for image recognition to identify and alert when certain type of activity occurs.  I applied for this RoadTest to evaluate whether the Raspberry Pi 3 could provide this capability using MATLAB and Simulink.

 

Unboxing

The package arrived from Element14 via UPS about a week after I was accepted as a RoadTester.  The product was contained in a single lightweight box packed within the shipping carton.

image

 

Contents

The Raspberry Pi 3 Learn to Program Pack contained the following items:

Raspberry Pi 3 Model B & 16GB NOOBS microSD card

Raspberry Pi Hat Case

Power Supply

MATLAB and Simulink Student Suite Activation Information

image

 

Hardware Overview

I have used Raspberry Pi hardware before so there were no surprises.  Here is a quick description of the hardware:

 

Power Supply

Stontronics Switching Adapter Model DSA-13PFC-05

Rated output: 5.1V @2.5A

Measured output: Unloaded 5.33V, w/load as tested 5.24V (max current was only ~600mA)

RMS ripple (DMM): 3-4mV

DC power cord: micro usb, not removeable, 58" length

Interchangeable international plugs included (used US)

image

 

Case

Raspberry Pi Hat Case

Designed for Raspberry Pi 3 Model B+ and compatible models

ABS construction with clear removeable lid to add accessories

Space to fit most hats (did not verify as I don't use hats)

Cut-out for Micro SD access

No heatsinks included

Dimensions: 94x64x27mm

 

Raspberry Pi 3 Model B+ V1.2

SoC: Broadcom BCM2837 (roughly 50% faster than the Pi 2)

CPU: 1.2 GHZ quad-core ARM Cortex A53 (ARMv8 Instruction Set)

GPU: Broadcom VideoCore IV @ 400 MHz

Memory: 1 GB LPDDR2-900 SDRAM

USB ports: 4

Network: 10/100 MBPS Ethernet, 802.11n Wireless LAN, Bluetooth 4.0

 

Micro SD Card

16GB preprogrammed w/NOOBS V2.1, Nov 24, 2016

image

 

Additional hardware required but not supplied (for my roadtest)

HDMI display

USB Keyboard

USB mouse

HD camera (intended to use FDT 7903 IP camera, used Logitech C525 webcam)

PIR sensor

Pi T Cobbler breakout kit (40 pin board and ribbon cable)

Solderless breadboard and jumper wires

Misc components - LED, resistor

 

PC Configuration (for running MatLab and Simulink)

Processor: i5-650, 3.2GHz, dual core, 4MB cache

Memory: 4GB

OS: Windows 10 Pro Version 1703 (Build 15063.608), 64-bit

Disk: 256GB solid state drive, 70GB free

 

System Requirements for Software

image

 

Hardware Setup

Installed the RPi into the case, good fit, no issues

Attached the keyboard, mouse, monitor, and micro SD card

Powered up Pi and selected Raspbian OS to install

Installed over WiFi (decided later to run with wired ethernet but did not have any issues with WiFi)

Required 4GB of space and took 22 minutes to download and install

OS installed was Raspbian Stretch 4.9 (Linux 8)

Enabled SSH

Set Locale to US Pacific (Time, Keyboard, WiFi Country) using raspi-config

Set Hostname and new password for user Pi

Default browser is Chromium

 

Software Overview

MATLAB and Simulink Student Suite Products Included (licensed):

MATLAB

Simulink

Control System Toolbox

Data Acquisition Toolbox

DSP System Toolbox

Image Processing Toolbox

Instrument Control Toolbox

Optimization Toolbox

Signal Processing Toolbox

Simulink Control Design

Statistics and Machine Learning Toolbox

Symbolic Math Toolbox

 

Hardware Support Packages Required

MATLAB Support Package for Raspberry Pi Hardware

MATLAB Support Package for USB Webcams

Simulink Support Package for Raspberry Pi Hardware

 

Software Setup

The first issue I encountered was an lack of precision in the activation instructions. It said to use the activation key inside the booklet.  There wasn't anything labeled as an activation key.  It turns out that the activation key is the serial number which I deduced because it had the correct number of characters and fields (5 fields of 5 numbers).  The next requirement is that you have a MathWorks account.  I had one from using ThingSpeak previously, so I just used that account.  The Student Suite comes with a single system license.

 

Installed size of the suite is 10GB.  I used the online install.  There is an offline version available.  My download time was 4 minutes and install time was 7 minutes.  The installed software was MatLab 9.3 and Simulink 9.0 (R2017b).

 

I ran into a problem trying to activate the software after installation.  The installer gave me a connection error.  I could log into MathWorks with a browser, so the problem was in the installer.  After repeated attempts I gave up and re-ran the installation.  The second time everything worked and the product activated.

image

 

The next step is to install the MatLab Hardware Support Package for Raspberry Pi.  Before doing that I thought that I would look at the MatLab Example: Getting Started with MatLab Support Package for Raspberry Pi.  I ran into a problem that MathWorks videos require Adobe Flash so I wasn't able to use Chrome which is my default browser (I decided to use the Edge browser rather to reconfigure Chrome).  I also tried to use the Document Link - Quick Start Guide: Learn the basics of using MATLAB and Simulink from the Element14 Raspberry Pi 3 and MathWorks Learn to Program Pack Starter Kit webpage (https://www.element14.com/community/docs/DOC-77882/l/raspberry-pi-3-and-mathworks-learn-to-program-pack-starter-kit), but the link (https://www.element14.com/community/external-link.jspa?url=http%3A%2F%2Fuk.mathworks.com%2Facademia%2Fgetting-started.html%3Fs_tid%3Dgn_ac_sv_gs) was broken.

 

Following the MatLab documentation, I acquired, installed and configured the Support Package for Raspberry Pi Hardware.  Since I had already configured and tested my Raspberry Pi, I chose the 'customize existing operating system' option (the other option is to write a totally new SD card image).  Unfortunately, the install failed in that I could not build the MatLab I/O Server on the RPi.

 

Build Error:

     ### Updating Raspberry Pi I/O server...

     ### Connecting to board...

     ### Connected to 10.0.0.10...

     ### Creating server folder...

     ### Transferring source files...

     ### Building MATLAB I/O server...

     Error using raspi.internal.updateServer (line 90)

     Error executing command "make -C /opt/MATLAB/server_v17.2.0 -f Makefile". Details:

 

     STDERR: In file included from /usr/include/string.h:630:0,

                      from devices.c:4:

     devices.c:56:11: error: expected identifier or ‘(’ before ‘__extension__’

          char *strndup(const char *s, size_t n)

 

 

I tried to use the Request Support button in MatLab, but I got an error on the Support Request Submission: "Valid Integer License is required".  It turns out that with the Student License, you cannot submit a support request from the MatLab program - you must go to the MathWorks website.  Further, I found out that "MATLAB Student access to the MathWorks technical support team is primarily for installation issues and bug reporting".  Therefore, there is no application support.  I guess in an academic environment you are supposed to have support of local experts.  For MathWorks support you need to buy a full license.

 

The build problem turns out to be that the current version of the Hardware Support Package only supports Raspbian Jessie and since NOOBs installs the latest Raspbian version I was running Stretch.  I tried the other install method allowing MatLab to create a new OS image and that did work (image was Raspbian Jessie 4.4).  The good news is that the technical support person did provide me a workaround for Stretch so I ended up using that.

 

Stretch Workaround:

     1. If you have the support package installed, replace the below mentioned files with the attached two files. If the support package for Raspberry Pi is not installed, please install it and then replace. The two files are typically installed at the below location. Please make sure you take a backup of the original file. Files attached to review (had to rename file to raspi.m.txt to allow attachment).

 

      C:\ProgramData\MATLAB\SupportPackages\R2017b\toolbox\realtime\targets\raspi\@raspi\raspi.m

      C:\ProgramData\MATLAB\SupportPackages\R2017b\toolbox\realtime\targets\raspi\server\devices.c

 

     2. Once these files are replaced, execute the following commands at MATLAB command window:

 

     >> clear pcode;

     >> clear classes;

     >> rehash path;

     >> rehash toolbox;

     >> rehash pathreset;

     >> rehash toolboxreset;

     >> rehash toolboxcache;

 

     3. Type the 'targetupdater' command at the MATLAB command window and use the following documentation to update the firmware on the Raspberry Pi.

     https://www.mathworks.com/matlabcentral/answers/uploaded_files/5422/Raspberry%20Pi%20Firmware%20Upgrade%20Guide.pdf

 

 

The next problem that I encountered is the MatLab didn't retain the device address (ipaddr) that I had entered during the install.  After I manually entered it in the device object (raspi) then it stuck.  At this point I was ready to try out MatLab with my RPi.

 

I discovered that in this context, Google is not your best friend, because I found many interesting examples but they were somewhat dated (RPi support in MatLab has been around since 2013).  Using older examples is problematic and in many cases it was difficult to find the associated code.  The other problem is that examples might use toolboxes that are not available (licensed) in your software suite.  I found that the best way to find current examples was to stay within the MathWorks ecosystem.  To find examples that are part of R2017b, the easiest way is to use Help -> Documentation (F1) within MatLab.  That will open a page with documentation links to all of your installed products.  Select MatLab Support Package for Raspberry Pi Hardware and it will bring you to a page of all the supported functions and hardware for the RPi.  Select examples and it will get you to all the current examples available for RPi.  This may miss some of the more exotic applications, but is very good for learning.  I went through the basic examples of using the GPIO to interface with an LED and a Motion Sensor.  Now I felt ready to try to implement my application.

 

Breadboard with LED and PIR sensor using Pi Cobbler to interface to GPIO pins

image

 

RoadTest Application

I use a Pan/Tilt IP camera to monitor front area of my house.  I can move the camera to monitor the driveway, front yard, or my front door.  I would like to use the camera to detect activity in these various zones and to alert me when certain types of activity occurs.  For the roadtest I wanted to see if I could implement image recognition using MatLab/Simulink with the Raspberry Pi to detect when mail is delivered to the mailbox on the street.  This would require being able to recognize the image of the mail truck.  I expected the challenges to be with being able to isolate an image in various lighting conditions against a changing background (because this is an outdoor application).  The camera that I use is an FDT 7903 which can stream H264 video over RTSP.

image

The first problem that I ran into is that the Image Acquisition Toolbox is required for MatLab IP Camera support.  And the second is that MatLab IP Camera only supports IP Cameras that use Motion JPEG (MJPEG) streaming over HTTP with basic authentication.  Using Google I found a third party package, HebiCam, that is supposed to support both MJPEG and H264 over both HTTP and RTSP.  Unfortunately, this was configured only for MatLab and not Simulink but I decided to try it anyway.  I installed it as a third party library but I was not able to get it to work with RTSP streaming.  Using a different camera I was able to verify that it would support MJPEG with HTTP.  So, I decided in the timeframe of this roadtest that I would just try to implement various existing examples on the Rpi using MatLab and Simulink.  And rather than use an IP Camera, I would use a webcam (other alternative would have been an RPi camera but I didn't have one available).

 

 

Examples implemented

Motion Sensor Camera

This example uses an HC-SR501 PIR module for motion detection and turns on an LED and captures a snapshot from the webcam when motion is detected.  I needed to install the Support Package for USB Webcams.

I implemented this in MatLab then I installed the Simulink RPi Hardware Support Package and also implemented it in Simulink.  The only issue that I had initially with Simulink was that after the Support Package install I had to restart the MatLab program to get it to work.  The fixes that allow MatLab to work with Raspbian Stretch also work for Simulink.

image

 

Image Inversion

This example takes the webcam image stream and inverts it and displays the inverted image.  Simulink works in two modes.  The external mode runs the model on the Pi but allows you to change variables and monitor outputs on the program computer.  In this case the image would display on the program computer.  In the deployed mode, the program runs entirely on the Pi and the image is diplayed on the HDMI monitor attached to the Pi.

image

 

Track Green Object

This example works by separating the red, green, and blue components of the image and then subtracting the red and blue components.  Then the image is adjusted to find green intensity above a given threshold.  A red square is then positioned over the original image at the center of the green values above the threshold.  Here is a video showing how the tracking picks up a green object moving into the field of view.  The green threshold is set so that target is initially a light green box near the center of the image and then changes to a bright green object entering from the right side of the image.

image

 

 

 

 

Conclusion

MatLab and Simulink are very capable tools especially with the addition of specialty toolboxes, but determining which toolboxes are required for specific applications before implementation can be problematic.  In my case I couldn't implement my application with the stock set of tools.  That is not to say that the application could not be implemented using MatLab and Simulink.  I'm sure that it could, but it would have been much more of a learning experience than allowed for in the timeframe of a roadtest.  The other hurdle with the Student Suite is that there is no application support from MathWorks.  I tried using the MathWorks community but did not have any luck (no responses) and the timestamps and quantity of answers to questions seem to indicate that the community is not very active.  What I disliked most about the MathWorks software is that things never seemed to work the first time.  It always seemed to take multiple tries with activation, installation, etc.  Simulink also had a problem where it would periodically "lose connection" with the RPi even though I could successfully ping the Pi from the command line and could also connect via the MatLab raspi object.  The only fix was to restart the MatLab program.

 

 

The RPi hardware worked as expected.  The RPi 3 is a great value and I plan to use more of them in home automation applications.  My primary issue with the RPi is the intolerance to unexpected power failure.  Seems like I have to re-image the SD card half of the time.  Backups are critical with the RPi.

 

 

As far as developing my intended application I think that I will investigate Open Source tools like OpenCV.  I am sure that there will be a steep learning curve there also, but there seems to be a much larger community using open source tools.

Anonymous
  • Really great detailed explanation. However, I've replaced the devices.c and raspi files, type the clear codes on command window but to no avail.

    I think this is because I'm using MATLAB R2018b, Support package version 18.2.1 .

    Really appreciate your help to guide me with Stretch workaround

  • Great detailed review. I understand your pain points relating to installing the support package and such and will try and take as much feedback to development organization as I possibly can. As you mentioned, the initial setup and stuff is the hard part and now that you have gotten past it, I would recommend you to attempt completing the project using MATLAB and SImulink in future. When you do get your project to work (with or without MathWorks tools), please post it on this road test if you can as I am eager to learn more from your project.

     

    Madhu

  • Great Review! congratulation - specially for your success with solving the problem with attempt to build the MATLAB server on the RPi  -  "raspi" command.

    I lost time trying to find the solution. Thank you for the advise!