getting started with matlab simulink and raspberry pi

Upload: pedro-catunda-marques

Post on 16-Oct-2015

1.421 views

Category:

Documents


50 download

TRANSCRIPT

  • Getting Started with Matlab Simulink and Raspberry Pi

    Agus Kurniawan

    1st Edition, 2013

    ISBN:978-1-300-95391-3

    Copyright @ 2013 Agus Kurniawan

  • Table of Contents

    Preface

    1. Introduction to Raspberry Pi

    1.1Raspberry Pi

    1.2Getting Hardware

    2. Matlab Simulink and Raspberrv Pi

    2.1 Matlab

    2.2 Installin

    2.3 Running Raspberry Pi

    2.4 SSH

    3. Helio World - Matlab Simulink and Raspberry Pi

    3.1 Helio World

    3.2 Creating Raspberrv Pi Simulink

    3.2.1 Configuring Raspberry Pi LED

    3.2.2 Configuring Data Type Conversion

    3.2.3 Configuring Sine Wave

    3.3 Running Simulink

    4. Simulink with Raspberry Pi GPIO

    4.1 GPIO

    4.2 Preparation

    4.3 Simulink with GPIO Write

    4.3.1 Building Simulink Madel

    4.3.2 Testinz

    4.4 Simulink with GPIO Read

    4.4.1 Creating Application for Arduino

    4.4.2 Building Simulink Model

    4.4.3 Testing

    5. Simulink and Video Capture

    S.l Prcparation

    5.2 Creating Simulink

    S.3Testing

    Contact

  • Preface

    This book was written to help anyone wants to get started in Raspberry Pi and Matlab Simulink. It describes alI the ba-sic elements of the Raspberry Pi and Matlab Simulink with step-by-step approach.

    Agus Kurniawan

    Berlin, April 2013

  • I. Introduction to Raspberry Pi

    1.1 Raspberry Pi

    The Raspberry Pi is a small size computer (85.60mm x 56mm x 21mm) with completed features so that you can play mul-timedia or run an application. This device is developed by the Raspberry Pi Foundation in UK. There ara two type of Rasp-berry Pi:

    Model A with 256 Mb RAM Model B with 512 Mb RAM

    111efollowing is technical specification of Raspberry Pi device:

    SoC Broadcom BCM2835 (CPU, GPU, OSP, SORAM) CPU: 700 MHz ARMI176JZF-S core (ARMll family) GPU: Broadcom VideoCore IV, OpenGL ES 2.0, 1080p30 h.264/MPEG-4 AVC high-profile decoder Memory (SORAM): 512 Megabytes (MiB) Video outputs: Composite RCA, HOMI Audio outputs: 3.5 mm jack, HOMI Onboard storage: SO, MMC, SOlO card slot 10/100 Ethernet RJ45 onboard network Storage via SOl MMCI SOlO card slot

    You can see Raspberry Pi device with model B on the Figure below.

  • SPBER Y PI MODELBRCA VIDEO AUDIO

    POWER~

    (source: http://www.raspberrypi.org/wp-content/uploads/20 11/07 /RaspiModelB.png)

    For further information, you can visit on Raspberry Pi, http://www.raspberrypi.org.

    1.2 Getting Hardware

    How to get Raspberry Pi device?

    Officially you can buy it from the official distributor

    RS, http://uk.rs-online.com/web/generalDisplay.html?id=raspberrypi Element 14, http://www.element14.com/raspberrypi

  • You a1so buy Raspberry Pi periphera1 devices for instance, keyboard, mouse, HDMI cab1e, SD card, USE hub, etc.

    I tried to 100k for buying Raspberry Pi device and found that there are another options to buy

    lhe Pi Hut, http://thepihut.com EXP- Tech, http://www.exp-tech.de/Mainboards/raspberry-pi.htm1 Cooking -hack, http://w w.cooking-hacks.com/index. php/ shoplraspberry -pi.htm1 Amazon, http://www.amazon.com Ebay, http://www.ebay.com

  • 2. Matlab Simulink and Raspberry Pi

    This chapter explains how to work with MatIab Simulink and Raspberry Pi Software.

    2.1 Matlab

    You can work with MatIab Simulink with targeting on Raspberry Pi using MatIab lOBa or the Iatest version. You aIso canwork with MatIab lOBa Student Version.

    (""l'e"~ fOl\)I,J U,fflt ~

    li.'S"OC.j) 7.:~Gt) (l\}O ,..

    7."'~O " H~OO 7. ?'O,;, ~.~

    $ D' S. fOr:;:) ~~?)(!O

    2.2 Installing Raspberry Pi for Simulink Target

    Firstly, you prepare to provide SD card devices. I use SanDisk SDHC 4 GB.

    Insert this card into your computer.

  • Now you are ready to install Raspberry Pi and MatIab Simulink for Raspberry Pi. You also need internet eonneetion todownload Raspberry Pi paekage.

    Run your Matlab and then cliek Add-Ons. You ean see the menu as below.

    Search DoclJmentation P

    Get More AppsGet Apps from File Exchange

    Get Hardware 5upport PackagesFind and install hardware support packages

    ValuePurchase MathWorks ProdudsVisit Web Store

    Seleet Get Hardware Support Packages.

    Then you will obtain a dialog, ealled Support Package Installer.

    Min

    Support Package Insta ler

    Install or update support package

    Where do you want to instaI! or update from?

    @ Internet (recommended)

    O Folder

    c: V'1ATLAB \$upportPackages \f'.20 130:lownioads

    Seleet Internet (recommended).

    After that, cliek Next button.

    8rowse...

  • ~ Support Package Installer 1-Select a support package

    Select a support package to install or update.

    Action Support Package for Installed lates1 Required Base Produd Supported Host PIVersion Version

    1 D Reinstall Arduino 3.0 3,0 Simulink Windows 132-bit),\,-

    D Install I2 BeagleBoard 3.0 ' Simulink Windows 132-bit),\3 D Install Gumstix Overo 1.0 Simulink Windows (32-bit),\4 D Install LEGOMINDSTORMSNXT 3.0 Simulink Windows (32-bit),\-5 D Install PandaBoard 3,0 Simulink V.lindows 132-bit),\

    '/ -- . ", '. ~oo -- - .' '""""" ":-... 6 ~ Install Raspberry Pi 1.0 Simulink Windows 132-bit),\

    , , , "7 L-J Imtall USRP{RJR.adio 5.0 Communicatons SystemToolbox Windows (32-bitl,\

    8 D Install Digilent Analog Discovery 1.1.1 Data Acquisition Toolbox Windows 132-bit),\r

    9 i Install A.n310gDevices DSPs 2.0 Embedded Coder Windows (32-bitl,\., -10 ~ Install Green Htlls r.."ULTI 3.0 Embedded Coder Windows 132-bitl,\

    11 l~ Install Xilinx Zynq-7000 1.0 Embedded Coder Windows (32-bit),\

    Installation fulder: IC:Vv\ATLAB\5upportPackages~20 13a I[~ Why are some rows disabled?

    Find more supported hardware I I[

    Check Raspberry Pi and then click Next button.

    You wil see a license agreement as below.

  • Support Package.lnstaHer

    MATHWORKS AUXILlARY SOFTWARE UCENSE AGREEMENT

    IMPORTANT NOTICE================

    REAO THE TERMS ANO CONomONS OF THIS MATHWORKS AUXILIARY SOFTWARE LICENSEAGREEMENT (THE "AGREEMEN) CAREFULLY BEFORE CHECKING 1 ACCEPr OR ACCESSING THESEMATERIALS (AS DEfINED BELOW).

    THIS AGREEMENT REPRESENTS THE ENTIRE AGREEMENT BETWEEN VOU (lHE LICENSEE") ANO THEMATHWORKS, INC. fMATHWORKS") CONCERNING THE SOFTWARE AND OOCUMENTATION MADEAVAILABLE fOR ACCESS HEREUNOER (COLLECTIVELY, THE 'MATERIALS").

    BY CHECKING 1 ACCEPI OR ACCESSING THESE MATERIALS I VOU ACCEPT THE TERMS OF THISAGREEMENT.

    1. DEFINmONS.

    1. 1. Licensee' means vou, whether an individual or an entity, to whom MathWorks grants theLicense, and who is responsible for complying with the contractual obligations of the License, andensuring that anyone permitted access to the Materiais also complies with such obligations.

    1.2. "Documentation" means the user guides, if any, accompanying delivery of the Materiais, as maybe updated from time to time, as 'Neli as any reports or other reedback that MathWorks may, in its soledisaetion, provide to Licensee. Documentation may be delivered in printed and/or online forms, and inone or more languages.

    ~ I accept

    Next > I I Cancel I! Help

    Cheeked I accept. If done, cliek Next button.

  • Support Pack:age Installer

    Third-party software licenses

    Vou have chosen to instaU Simulink Support Pack.age for Raspberry Pi Hardware.

    Software Vl'illbe installed from the following locations:

    SDlWget for Windows]-zip

    http://wVl'w.libsdl.orghttp://gnuwin32.sourceforge.net/pack.ages/wget.htmhttp://www.]-zip.org

    IicenseIicenseIicense

    This utility enables Vou to download and install the third party soft1Nare listed above. This list may containopen source software, induding software licensed under the terms of the General PubJiclicense.

    By dicking 1nstaU" on the next screen, vou will be downloadng and instaJling the soft1l1'arelisted above.

    By dicking 'Cancel", you will not download or install the software.

    < Back I I Next > I I CanceJ I I Help

    Click Next button.

  • Support Package Installer

    Confirm installation

    Vou have chosen to install Simulink Support Package for Raspberry Pi Hardware inC:V"'1ATLAB\SupportPackagesljUO 13a.

    < Back

    Click InstaU button.

    It will download Raspberry Pi package and then instal1 it.

    If success, you wl obtain a dialog as beIow.

    Install Cancel

  • Support Package Installer

    IMtal/update complete

    Simulink Support Package for Raspberry Pi Hardware has been successfully installed.

    To ensure compatibility with Simulink, you may need to updatethe firmware for the selected support package hardware.

    Select -Continue- to update firmware now.Select -Close- to exit this utility.

    CI

    I Continue> I ~-==--J HelpClick Continue button.

  • Update firmware

    Choose a hard'Nare to start the firmware update processo

    Hardware: aS):>~~~~Y~i..J

    Click Next buttol1.

    Help

  • Support Package Installer

    Select a board

    The firmware update process for Raspberry Pi hardware consists of copying aRaspbian Wheezy Linux image onto a memory cardo We will guide you throughthis processo Select your board to get started:

    Board: IModel B .1

    D

    II Cancel----_._---- >

  • Support Package Installer

    Get firmware

    Where do you want to get the firmware from?

    @ Dovmload from Internet (recommended)

    O Get from local folder

    Download folder: IC;\MTLAB\S~;;;;~~tp~~~~~~201&;\;j~;;~~I~~d~\m....ml Browse ..WARNING: Download size is approxmately 1GB.Download may take several mnutes.

    D

    Choose Download from Internet (recommended).

    If done, click Download button.

    If download process is done, you will see a dialog as below.

  • Support Package Installer

    Configure board

    The board .\lilI be configured with the foilowing name and IP settings:

    Board name: 'raspberrypi-AKUR ]l ....__.._.__. .. .... .....__.. ...__.... _

    Configure IP settings for wired Ethernet connection More info

    IP Assignment

    Automatica!ly get IP aderess

    ManuaDy enter IP address

    IP Settings

    IP address: 10.10.10.9

    Network mask: 255.255.255.0

    Default gateway: 10.10.10.1

    Cl

    < Back Cancel

  • Support Package lnstaller

    5elect a drive

    Insert a 4 GB or larger SD memory card into a memory card reader on the host compu ter.

    Select the drive letter that corresponds to the memory card reader:

    Drive: ID: ~! I RelTeshIf you do not find the memory card reader in the list of drives, reinsert the memory card fullyand dick "RelTesh',

    ~Slide lock switchup to unlocked

    position

    This dialog cal1 detect your SD cardo If 110t,select the drive of your SD cardo

    Then click Next button.

    < Back I I Next > CancE

  • WARNING: Ali data in the memory card will be erased!

    Support Package Installer

    Write firmware

    Vou chose to write to drive D:. The write operation may take severa Iminutes.I,(-

    Click Write button to start to write Raspberry Pi image to SD cardo

    If done, you will see the dialog as below.

    Cana

  • Support Package Installer

    Connect lhe Raspberry PHardware

    Power cable Ethernet connecton

    Instructions

    1. Remove the 50 memory eard ITom the hcomputer and insert into the Raspberry Pi I2. Connect an Ethernet eable to the boardthe other end of the Ethernet eable to a nldirectly to the host compu ter.

    3. Connect a SVmicro USS power supply teboard. The power supply should be rated fleast 700 mA.

    NOTE: Vou may connect optional peripheraas a monitor, keyboard, etc. at ths time.

    Make sure that the 'PWR' LED is solid red athe 'OK' LED indcating 50 card activtystarts blinking. Then, dick 'Next' to continu

    < Saci< I I Next > I I CancE

    Plug out SD card from compu ter. Then, plug in it into Raspberry Pi

    Now turn on your Raspberry PioRead section 2.3.

  • You may configure your Raspberry Pi for instance SSH. You can read it on section 2.4.

    After Raspberry Pi is running well, cIick Next button. Then you will see a dialog as below.

    Support Package Installer

    Confirm board configuration

    If you want to log in to the board in the future, the host name or IP address, user name, and password aredisplayed below. Voumay also type "raspberrypi" on the MATLAB command window to obtain this information.

    Host name: raspberrypi-AKUR

    User name: p

    Password: raspberry

    NOTE:1. YourRaspberry Pi hardware willspeak its IP address through the analog audo connector whenit boots.

    2. Voucan configure your Raspberry Pi hardware to automatically send an e-mail when IP addresschanges. Click'Help' for detailed instructions.

    OptimizationI> Diagnostics

    Hardware ImplementationModel Referencing

    I> Simulation TargetRun on Target Hardware

    Target hardware seleetion

    Target hardware: ~~p~be_r_ry_p_i_~~~ __ ~ _

    Signal monitoring and parameter tuning

    ~ Enable Externai mode

    TCP/IP port (102.4-65535): 1772.5

    Overrun deteetion

    ~ Enable overrun deteetion

    Board information

    Host name:

    User name:

    PassNord: ~~_~~~~:~_=:-~_____..._~- ..-..-..----- ..._-----.---------.----:-=~=_Build direetory: [2~~_~_~Le-~==:_-:_::~:::::::==~===:.:=::_~-:=====--=_:~:==-.

    Before running, change Normal to Externai.

    J ...

    Code Tools Help

    I ~J T ii:--Diagram Simulation Analysis

    iIT:l ~ .. si @, .0~ ~IG) \

    i

    DisplayFile Edit View

    Model Browser

    videodemo

    Now click menu Tools -> Run on Target Hardware -> Run.

    If success, you will see RGB values on Display.

  • -, -vid-eo-de-m-o----'--.-----.--------~------------------------------. -.---.---------~-----

    S ~videodemo

    '~:-~li

  • Contact

    If you have question related to this book, please contact me at [email protected] . My blog: http://blog.aguskurniawan.net.

    Source code can be downloaded on http://www.aguskurniawan.net/book!simulinkcodes.zip.

    00000001000000020000000300000004000000050000000600000007000000080000000900000010000000110000001200000013000000140000001500000016000000170000001800000019000000200000002100000022000000230000002400000025000000260000002700000028000000290000003000000031000000320000003300000034000000350000003600000037000000380000003900000040000000410000004200000043000000440000004500000046000000470000004800000049000000500000005100000052000000530000005400000055000000560000005700000058000000590000006000000061