MathWorks - Mobile View
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 다운로드
MathWorks
  • 제품
  • 솔루션
  • 아카데미아
  • 지원
  • 커뮤니티
  • 이벤트
  • MATLAB 다운로드
  • MathWorks 계정에 로그인합니다.MathWorks 계정에 로그인합니다.
  • Access your MathWorks Account
    • 내 계정
    • 나의 커뮤니티 프로필
    • 라이선스를 계정에 연결
    • 로그아웃

비디오 및 웨비나

  • MathWorks
  • 비디오
  • 비디오 홈
  • 검색
  • 비디오 홈
  • 검색
  • 영업 상담
  • 평가판 신청
  Register to watch video
  • Description
  • Full Transcript
  • Related Resources

Programming Arduino Uno with Simulink

Anuja Apte, MathWorks

Install the Arduino® support package, create a simple model, and download the model to Arduino Uno using a step-by-step workflow with Simulink®.

In this tutorial, I'm going to show you how to set up the Simulink support package for Arduino. Then we are going to build a simple Simulink model and generate code from that model to run on the Arduino Uno hardware board that links in LED.

So let's see what the requirements are. On the software side, we're going to need MATLAB installed. You will also need a MathWorks Account, which you can create on the MathWorks website or during the installation. Just so you know, the student version for MATLAB is available for a little over $100 from the MathWorks website or from amazon.com.

This student version will give you access to 10 additional products in addition to MATLAB and Simulink. So that's the software side. On the hardware side, we are building a very simple circuit, wherein an LED is connected to the pin 9 of the Arduino Uno board via a 220 ohm resistor.

The other end of the LED is connected to the ground on the Arduino Uno board. Now, moving onto the next step, we're going to assume that you've built this simple circuit, connected it to the Uno, and the Uno is connected to the computer that has MATLAB installed on it. So with that, we're ready to jump into the installation.

Let's go to our MATLAB installation. Here, you're going to click on the top, on Add-ons, and then select Hardware Support Packages, and internet as the way of installation. Click Next, and you'll see a list of hardware boards that are supported in MATLAB. And you can select whichever support package you want to install.

Select Arduino and click Next. Now, you're going to log into your MathWorks Account, hit Next through the license agreement, and complete the simple installation with a few clicks. Give it a minute to install, and it's really that simple. You go to your MATLAB desktop, select your option for the support package, log into your account, and that's it. You're done.

So once the package is installed, it's going to open up the documentation and show you how to get started with the support package. These are really simple step-by-step examples that you can follow to get started on your own. In this video, I'm going to show you how to build a simple model.

In case you want to jump to the code generation step directly, simply type ArduinoUno_gettingstarted at the MATLAB command prompt and just hit Enter. This is going to open a pre-built model that's ready for code generation and does exactly the kind of things that we want to do in this tutorial.

For now, I'm going to show you how to do this from scratch, so click on the Simulink library icon to open the library browser. On the left side, you're going to see a list of libraries that are installed in your version. And on the right side shows the blocks in a specific library, like the support package for Arduino.

As you can see, the individual blocks in this library are focused on a particular interface to the Arduino Uno board. So for example, digital output or serial interface and that kind of thing. For this tutorial example, we're going to use the digital output block, and so we will create a blank canvas or a brand-new model in Simulink and to drag and drop the digital output block in that model.

So on the left, we're going to click on the New Model symbol and drag and drop the digital output block into the model. Now, if you double-click on this block, you can see the different parameters you can modify. For now, it's set to pin 9, which is perfect, so we click OK, and we're done.

Now, at this point, you can run the simulation by clicking the Play button, but it's not going to do anything because we don't have any inputs for the block. So to fix that, we're going to grab a pulse generator block from the Simulink's sources library. So we go to the sources library in Simulink and drag and drop a pulse generator block in this model.

And let's configure it now. So we want to generate a pulse every second. Let's see. Let's set the pulse time to sample based and then look at the rest of the parameters. We have the period set as 10 samples, and then the pulse rate at 5. So if we set the sample time to 0.1, 0.1 times 10 should give us a pulse every second.

So we click OK, and then how do we verify that the pulse generator is doing the right thing? So we grab a scope block from the [INAUDIBLE] library to visualize how the pulse is being generated. So drag and drop the scope block and connect the pulse generator to the scope, and then run the simulation.

When we double-click the scope block, we see that indeed, this pulse generator block generates a pulse every second, and that's what we want. Now we are ready to connect the pulse generator to the Arduino block, which is the pin 9 block, or digital output block. So we connect the pulse generator to the digital output, get rid of the scope.

And now we can move on to the code generation section of the tutorial. Let's quickly save the model as tutorial one or something, and then we can go to the co-generation section. All right, so we've built the circuit as per specifications. We have connected the circuit to Uno, and Uno's connected to the board.

And now we're ready to generate code. So we click on the Tools menu and then select Random Target Hardware and Prepare to Run. Here, we're going to select Arduino Uno as the board, and then leave the rest of the parameters as it is, as in the default scheme. So click OK, and that's it.

We're going to next click a button and generate code from this model, download it on the Arduino hardware board. So click on Run Our Target Hardware again and Run. This will start the code generation process. And at the bottom bar of your model, you're going to see different messages that show you the status of code generation process.

And once the [INAUDIBLE] model is successfully downloaded on Arduino Uno, you are done. At that point, the LED should be blinking as expected every second. So let's see if that's really true. Let's go to the hardware and check it out. All right, it's really blinking every second.

So with that, we've shown you how to install the support for Arduino in Simulink, how to build a simple model and verify what it's doing before you automatically generate code from the model and download it on Arduino Uno.

Related Products

  • Simulink

Feedback

Featured Product

Simulink

  • Request Trial
  • Get Pricing

Up Next:

8:49
Arduino Light Meter Project, Part 2: Program the Device...

Related Videos:

10:00
Using an RC Controller with Arduino and Simulink
23:19
Raspberry Pi Programming using Simulink
26:13
LEGO MINDSTORMS EV3 Programming Using Simulink
18:07
Programming TI C2000 LaunchPad with Simulink

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web site

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • 영업 상담
  • 평가판 신청

제품 소개

  • MATLAB
  • Simulink
  • 학생용 소프트웨어
  • 하드웨어 지원
  • File Exchange

다운로드 및 구매

  • 다운로드
  • 평가판 신청
  • 영업 상담
  • 가격 및 라이선스
  • MathWorks 스토어

사용 방법

  • 문서
  • 튜토리얼
  • 예제
  • 비디오 및 웨비나
  • 교육

지원

  • 설치 도움말
  • 사용자 커뮤니티
  • 컨설팅
  • 라이선스 센터
  • 지원 문의

회사 정보

  • 채용
  • 뉴스 룸
  • 사회적 미션
  • 영업 상담
  • 회사 정보

MathWorks

Accelerating the pace of engineering and science

MathWorks는 엔지니어와 과학자들을 위한 테크니컬 컴퓨팅 소프트웨어 분야의 선도적인 개발업체입니다.

활용 분야 …

  • Select a Web Site United States
  • 특허
  • 등록 상표
  • 정보 취급 방침
  • 불법 복제 방지
  • 매스웍스코리아 유한회사
  • 주소: 서울시 강남구 삼성동 테헤란로 521 파르나스타워 14층
  • 전화번호: 02-6006-5100
  • 대표자 : 이종민
  • 사업자 등록번호 : 120-86-60062

© 1994-2021 The MathWorks, Inc.

  • Naver
  • Facebook
  • Twitter
  • YouTube
  • LinkedIn
  • RSS

대화에 참여하기