Topics: ArduinoIO package Simulink with arduinoIO Arduino Part 3 Topics: ArduinoIO package Simulink with arduinoIO
Workshop Overview Matlab VS IDE Getting started Hands-on Project 1: LED control Hands-on Project 2: LED dimmer Hands-on Project 3: Reading digital signal Hands-on Project 4: Up counter Hands-on Project 5: Reading analog signal Hands-on Project 6: LED dimmer v2 Hands-on Project 7: Relay control Hands-on Project 8: 7-segment control
Using MATLAB vs. IDE Environment 1 MATLAB is more interactive, results from Digital/Analog I/O instructions can be seen immediately without needing to program – compile – upload – execute each time. It is a good idea even just for algorithm prototyping 2 For wider-breadth projects (that might include data analysis, signal processing, calculations, simulation, statistics, control design …) MATLAB is better suited
1 2 MathWorks Solutions Arduino IO Package: Used to perform analog and digital input and output as well as motor control from the MATLAB command line 2 Arduino Target: Used to compile and download Simulink® code directly to the Arduino board
1 2 3 Getting started Install Matlab 2012a or later version Get arduinoIO package, unzip and place the folder inside a MATLAB folder : C:\Program Files\MATLAB 3 Open pde folder. By using arduino IDE software, load adiosv.pde into your arduino
Getting started(cont.) 4 Go to arduinoIO folder, copy everthing inside examples and simulink folder and paste it in the main arduinoIO folder Paste here 5 Open the matlab software, change your current folder to ArduinoIO folder ArduinoIO 6 Double click the arduino_io_lib.mdl file
Getting started(cont.) 7 You should be able to see simulink library for the arduino IO package Supported simulink block for arduino ArduinoIO Click to launch your first simulink example example
Getting started(cont.) 8 Your first arduino-simulink block Click to start simulation Your on-board led should blink once the program run. Select your com port Output to arduino led pin13
Hands-on Project 1: LED control Prepare your simulink block: Click library browser to view other simulink block Click new to create new simulink model
Hands-on Project 1: LED control Compulsory when using ArduinoIO package Prepare your simulink block: Drag and drop the required block to create new model Can be obtained from simulink library browser
Hands-on Project 1: LED control 2 Click to start simulation Run your simulink model Set to ‘inf’ This block will send digital signal 0 or 1 to arduino pin13. When the simulation runs, double click to change the switching position and observe the LED on your board
Hands-on Project 2: LED dimmer 1 Simulink model Prepare your hardware When simulating, vary slider gain to adjust the led brightness
Hands-on Project 3: Reading digital signal 1 2 Hardware Simulink model 10kOhm When you release the switch When you press the switch
Hands-on Project 4: Up counter 1 2 Hardware Simulink model 10kOhm
Hands-on Project 4: Up counter 2 Simulink model(cont.)
Hands-on Project 5: Reading analog signal 1 2 Hardware Simulink model
Hands-on Project 6: LED dimmer v2 1 2 Hardware Simulink model Gain : 5/1024 Gain : 255/1024 R 1k Ohm R 220 Ohm
Hands-on Project 7: relay control 1 hardware setup (use relay module from SIRIM robokit): relay2 relay1 relay4 relay3 GND 5v
Hands-on Project 7: relay control 2 The simulink model: 12
Hands-on Project 8: 7-segment control 1 hardware setup (use 7segment module from SIRIM robokit): 5v GND Bit 1 Bit 0 Bit 3 Bit 2 display4 display3 display2 display1
Hands-on Project 8: 7-segment control 2 The setting: bit3 bit2 bit1 bit0 display 1 2 3 4 5 6 7 8 9 we will use display number 4 only the number will be displayed based on the following table: 5v GND Bit 1 Bit 0 Bit 3 Bit 2
Hands-on Project 8: 7-segment control 2 Simulink model:
Hands-on Project 8: 7-segment control 2 Simulink model:
Hands-on Project 8: 7-segment control 2 Simulink model: uint8([ 0 0 0 1 ]) uint8([ 0 0 010 ]) uint8([ 0 0 1 1 ]) uint8([ 0 1 0 0 ]) uint8([ 0 1 0 1 ]) uint8([ 0 1 1 0 ]) uint8([ 0 1 1 1 ]) uint8([ 1 0 0 0 ]) uint8([ 1 0 0 1 ])
Hands-on Project 8: 7-segment control 3 The results:
http://www.mathworks.com/har dware-support/arduino- matlab.html www.arduino.cc www.ladyada.net/learn/arduino www.EarthshineElectronics.com https://learn.sparkfun.com/ http://www.mathworks.com/har dware-support/arduino- matlab.html References