Set Up And Blink - MATLAB And Simulink With Raspberry Pi

3y ago
61 Views
3 Downloads
1.22 MB
18 Pages
Last View : 16d ago
Last Download : 3m ago
Upload by : Maxton Kershaw
Transcription

Set up and Blink - MATLAB and Simulink with Raspberry PiCreated by Anuja ApteLast updated on 2018-08-22 03:46:25 PM UTC

Guide ContentsGuide ContentsOverviewParts and HardwareSet up MATLAB and Simulink support package for Raspberry PiUsing MATLAB Support Package and Raspberry PiCommon Error MessagesUsing Simulink Support Package and Raspberry PiResources Adafruit e 2 of 18

OverviewYou can use MATLAB to communicate with a Raspberry Pi board and its peripheral devices using MATLAB SupportPackage for Raspberry Pi.You can program Raspberry Pi boards to run your algorithms using Simulink Support Package for Raspberry PiHardware. The support package generates code from your Simulink model in a click of a button that then runs on theRaspberry Pi board.This tutorial covers a step-by-step guide to:MATLAB Support Package1. Set up the MATLAB support package for Raspberry Pi2. Send commands from MATLAB to Raspberry Pi to blink the on-board LEDSimulink Support Package1. Set up the Simulink support package for Raspberry Pi2. Build a simple Simulink model for controlling pins on the Raspberry Pi3. Generate, download and run code on the Raspberry Pi to blink an LEDThis is the first tutorial in a series on using MATLAB and Simulink to program a Raspberry Pi. In this tutorial RaspberryPi 2 is used as an example, however the same steps can be used for other boards like Raspberry Pi Model B etc. Adafruit tlab-and-simulink-with-raspberry-piPage 3 of 18

Parts and HardwareSoftwareMATLAB and Simulink Student Suite Release 2015a - now available for 99MathWorks (https://adafru.it/d5E)Amazon US (https://adafru.it/eoc)Amazon UK (https://adafru.it/eod)If you are not a student, you can purchase the MATLAB Home-Use license for personal use:MATLAB home-use (https://adafru.it/eoe)Hardware1. Raspberry Pi 2 (http://adafru.it/2358)2. USB cable (http://adafru.it/2008)3. Ethernet cable (https://adafru.it/eY7) Adafruit tlab-and-simulink-with-raspberry-piPage 4 of 18

Set up MATLAB and Simulink support package for Raspberry PiStart MATLABOpen MATLAB and click the Add-Ons drop down menu on the top rightStart Support Package InstallerClick on Get Hardware Support Packages in the drop down menu to start the installer. Select 'Install from Internet' asthe source for installing the support packageSelect Raspberry Pi from a list of support packagesClick Next to see a list of support packages and select Raspberry Pi from the list to install both the support packages atonce. Adafruit tlab-and-simulink-with-raspberry-piPage 5 of 18

MathWorks AccountClick next and log in to your MathWorks account. If you don't have a MathWorks account, you can create one duringthe install process or by visiting this page on the MathWorks website (https://adafru.it/eoA). (https://adafru.it/d5K)Continue and Complete the InstallationAccept the license agreement on the next screen and click Next through the following screens to finish the installationof both MATLAB and Simulink Support Package for Raspberry Pi. Adafruit tlab-and-simulink-with-raspberry-piPage 6 of 18

Firmware UpdateClick Next and on the Firmware Update page select the appropriate board (for this tutorial, Raspberry Pi 2 Model B ischosen).Configure NetworkClick Next and in the configure network screen, select Direct connection to host computer (to follow along with this Adafruit tlab-and-simulink-with-raspberry-piPage 7 of 18

tutorial).Select the driveIn the next window 'Select a drive', the MicroSD cards that are detected by MATLAB will show up in a list format.If the MicroSD memory card does not get detected by MATLAB, but is detected by the OS - close MATLAB and restartMATLAB as an administrator. To continue with the process, the targetupdater command can be used in MATLAB. Adafruit tlab-and-simulink-with-raspberry-piPage 8 of 18

Write firmwareIn the next window, select write option to erase existing items on the memory card and flash the latest firmware that isneeded by the Support package. Adafruit tlab-and-simulink-with-raspberry-piPage 9 of 18

Continue and Complete the InstallationClick Next through the following screens to finish the installation for both MATLAB and Simulink Support Package forRaspberry Pi. Adafruit tlab-and-simulink-with-raspberry-piPage 10 of 18

Using MATLAB Support Package and Raspberry PiNow that we have the necessary software installed, it's time to blink the on-board LED. In this example, we will use theMATLAB support package.To establish a connection between MATLAB and Pi 2, the following command can be used from MATLAB. mypi raspiThis command connects MATLAB to the most recent successful connection to a Raspberry Pi board, including thesetup process. A MATLAB variable by the name 'mypi' should now appear on the workspace or an error messageindicating what went wrong. This object represents the connection that MATLAB has established with the physicalobject (Raspberry Pi).To switch on the on-board LED connected, execute the following command writeLED(mypi,'led0',1)Here we are sending a request from MATLAB to Raspberry Pi board, to write the value of 1 on the on-board LED. Thisshould switch ON your LED.To blink the LED, we have to switch it ON and OFF periodically.for i pi,'led0',0);pause(0.5);endOther functions that are related to the MATLAB Support Package for Raspberry Pi can also be used along with theRaspberry Pi object 'mypi'.To take a look at the featured examples from MATLAB Support Package for Raspberry Pi, type raspi examples inMATLAB Command Window.Common Error MessagesError usingraspi (line157)connection to the board with device address "169.254.0.2".Cannotestablishan SSHCausedby: raspi (line 153)ErrorError usingexecutingcommand: FATAL ERROR: Network error: Network is unreachableEnsure that the Raspberry Pi board is connected to the computer that you are working with. Usually when the lights on Adafruit tlab-and-simulink-with-raspberry-piPage 11 of 18

the ethernet port and the ACT LED are blinking, there is a connection between the Pi board and the computer.If for some reason the connection between MATLAB and Raspberry Pi board is lost, the following error messageappears.The host and client connection is lost. Make sure the board is plugged in and/or recreate arduino and its related objects.The best practices to follow to resolve this error 1.2.3.4.Disconnect the USB cable and Ethernet cable from both the Pi board and computerClean up MATLAB by typing clear in MATLAB Command WindowPlug in the USB cable to computer and Pi boardTry connecting to the board from MATLAB by using raspi command Adafruit tlab-and-simulink-with-raspberry-piPage 12 of 18

Using Simulink Support Package and Raspberry PiCreate your own Simulink model1. In MATLAB, select New Simulink Model under the HOME Tab2. Click on the Library Browser Icon on the simulink model and go to Sources tab under Simulink in the SimulinkLibrary Browser window3. Drag the Pulse Generator block from the Sources library to your model and change the values as shown here Adafruit tlab-and-simulink-with-raspberry-piPage 13 of 18

4. Use the LED Block from Simulink Support Package for Raspberry Pi Hardware in the Library Browser and changethe parameters as shown here Adafruit tlab-and-simulink-with-raspberry-piPage 14 of 18

5. Drag and drop the Data Type Conversion block from the Signal Attributes tab under the Simulink library6. When you move the mouse pointer close to the arrow on the block, it will change to a plus sign. Left click when youseee the plus sign and drag the mouse to make the intended connection. Once the connection is made you can Adafruit tlab-and-simulink-with-raspberry-piPage 15 of 18

release the left click button.7. Save this model and to configure the model go to Tools Run on Target Hardware Prepare To Run.8. When the Configuration Parameters page opens up, set the Target hardware parameter to Raspberry Pi. Do notchange any other settings. Adafruit tlab-and-simulink-with-raspberry-piPage 16 of 18

9. In your Simulink model, click the Deploy To Hardware button on the toolbar. Code will be generate from the model,which is then deployed to your Pi 2. The on-board LED should blink one time every second. Adafruit tlab-and-simulink-with-raspberry-piPage 17 of 18

ResourcesExamples for getting startedMATLAB examples (https://adafru.it/d5M)Simulink examples (https://adafru.it/eUL)Full tutorialsMATLAB Getting Started Tutorial (https://adafru.it/d5N) (3 hrs 15 mins)Simulink Getting Started Tutorial (https://adafru.it/d5N) (2 hrs 15 mins - 10 mins per module) Adafruit IndustriesLast Updated: 2018-08-22 03:46:21 PM UTCPage 18 of 18

1. Set up the Simulink support package for Raspberry Pi 2. Build a simple Simulink model for controlling pins on the Raspberry Pi 3. Generate, download and run code on the Raspberry Pi to blink an LED This is the first tutorial in a series on using MATLAB and Simulink to program a Raspberry Pi. In this tutorial Raspberry

Related Documents:

If the model # is: TLP 2824 PLUS 1. Press and hold the feed button (the green button on the face of the machine), continue to hold it. The light around the button will begin to blink. 2. Count the blinks. It will blink once, then it will blink twice, then it will blink 3 times and then it will blink 4 times. After it blinks 4 times, release the .

19 MATLAB Excel Add-in Hadoop MATLAB Compiler Standalone Application MATLAB deployment targets MATLAB Compiler enables sharing MATLAB programs without integration programming MATLAB Compiler SDK provides implementation and platform flexibility for software developers MATLAB Production Server provides the most efficient development path for secure and scalable web and enterprise applications

3. MATLAB script files 4. MATLAB arrays 5. MATLAB two‐dimensional and three‐dimensional plots 6. MATLAB used‐defined functions I 7. MATLAB relational operators, conditional statements, and selection structures I 8. MATLAB relational operators, conditional statements, and selection structures II 9. MATLAB loops 10. Summary

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for algebra, plotting, calculus, and solving differential .

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for

I. Introduction to Programming Using MATLAB Chapter 1: Introduction to MATLAB 1.1 Getting into MATLAB 1.2 The MATLAB Desktop Environment 1.3 Variables and Assignment Statements 1.4 Expressions 1.5 Characters and Encoding 1.6 Vectors and Matrices Chapter 2: Introduction to MATLAB Programming 2.1 Algorithms 2.2 MATLAB Scripts 2.3 Input and Output

Lecture 14: MATLAB I “Official” Supported Version in CS4: MATLAB 2018a How to start using MATLAB: CS Dept. Machines - run ‘cs4_matlab’ Total Academic Handout (TAH) Local Install - software.brown.edu MATLAB Online (currently 2019a) - matlab.mathworks.com Navigating the Workspace (command window, variables, etc.) Data types in MATLAB (everything is a 64-bit .

foundation of basic MATLAB applications in engineering problem solving, the book provides opportunities to explore advanced topics in application of MATLAB as a tool. An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLAB commands. MATLAB is considered as the software of choice. MATLAB can be used .