Arduino Part 3 Topics Arduino IO package Simulink


























- Slides: 26

Arduino Part 3 Topics: Arduino. IO package Simulink with arduino. IO

Workshop Overview �Matlab VS IDE �Getting started �Hands-on Project �Hands-on Project 1: 2: 3: 4: 5: 6: 7: 8: LED control LED dimmer Reading digital signal Up counter Reading analog signal LED dimmer v 2 Relay control 7 -segment control

Using MATLAB vs. IDE Environment 1 2 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 For wider-breadth projects (that might include data analysis, signal processing, calculations, simulation, statistics, control design …) MATLAB is better suited

Math. Works Solutions 1 2 Arduino IO Package: Used to perform analog and digital input and output as well as motor control from the MATLAB command line Arduino Target: Used to compile and download Simulink® code directly to the Arduino board

Getting started 1 2 3 Install Matlab 2012 a or later version Get arduino. IO package, unzip and place the folder inside a MATLAB folder : C: Program FilesMATLAB Open pde folder. By using arduino IDE software, load adiosv. pde into your arduino

Getting started(cont. ) 4 5 Go to arduino. IO folder, copy everthing inside examples and simulink folder and paste it in the main arduino. IO folder Open the matlab software, change your current folder to Arduino. IO folder Arduino. IO 6 Double click the arduino_io_lib. mdl file Paste here

Getting started(cont. ) 7 You should be able to see simulink library for the arduino IO package Click to launch your first simulink example Arduino. IO Supported simulink block for arduino example

Getting started(cont. ) 8 Your first arduino-simulink block Select your com port Output to arduino led pin 13 Click to start simulation Your on-board led should blink once the program run.

Hands-on Project 1: LED control 1 Prepare your simulink block: Click new to create new simulink model Click library browser to view other simulink block

Hands-on Project 1: LED control 1 Prepare your simulink block: Drag and drop the required block to create new model Can be obtained from simulink library browser Compulsory when using Arduino. IO package

Hands-on Project 1: LED control 2 Run your simulink model This block will send digital signal 0 or 1 to arduino pin 13. When the simulation runs, double click to change the switching position and observe the LED on your board Click to start simulation Set to ‘inf’

Hands-on Project 2: LED dimmer 1 Prepare your hardware 2 Simulink model When simulating, vary slider gain to adjust the led brightness

Hands-on Project 3: Reading digital signal 1 Hardware 2 Simulink model 10 k. Ohm When you release the switch When you press the switch

Hands-on Project 4: Up counter 1 10 k. Ohm Hardware 2 Simulink model

Hands-on Project 4: Up counter 2 Simulink model(cont. )

Hands-on Project 5: Reading analog signal 1 Hardware 2 Simulink model

Hands-on Project 6: LED dimmer v 2 1 2 Hardware Simulink model Gain : 5/1024 Gain : 255/1024 R 1 k Ohm R 220 Ohm

Hands-on Project 7: relay control 1 hardware setup (use relay module from SIRIM robokit): relay 1 relay 2 relay 3 relay 4 5 v GND

Hands-on Project 7: relay control 2 The simulink model: 12

Hands-on Project 8: 7 -segment control 1 hardware setup (use 7 segment module from SIRIM robokit): Bit 2 Bit 0 Bit 1 display 3 display 4 display 2 Bit 3 5 v GND display 1

Hands-on Project 8: 7 -segment control 2 The setting: • we will use display number 4 only • the number will be displayed based on the following table: Bit 0 Bit 2 Bit 1 Bit 3 5 v GND bit 3 bit 2 bit 1 bit 0 displ ay 0 0 0 0 1 1 0 0 1 0 2 0 0 1 1 3 0 1 0 0 4 0 1 5 0 1 1 0 6 0 1 1 1 7 1 0 0 0 8 1 0 0 1 9

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: uint 8([ 0 0 0 1 ]) uint 8([ 0 0 010 ]) uint 8([ 0 0 1 1 ]) uint 8([ 0 1 0 0 ]) uint 8([ 0 1 1 0 ]) uint 8([ 0 1 1 1 ]) uint 8([ 1 0 0 0 ]) uint 8([ 1 0 0 1 ])

Hands-on Project 8: 7 -segment control 3 The results:

www. arduino. cc www. ladyada. net/learn/arduino www. earthshineelectronics. com https: //learn. sparkfun. com/ http: //www. mathworks. com/har dware-support/arduinomatlab. html References