Arduino with MATLAB:
One can connect Arduino very easily with MATLAB and Simulink. MATLAB provides platform to design your project in Simulink and upload it in Arduino for working independently from MATLAB and stand alone as well; working in real time with MATLAB. Following few steps will give a bird’s eye view to work with Arduino and Simulink together.
- Arduino (Mega2560 or UNO)
- MATLAB 2013 (or above)
- Installed Arduino package in Simulink
- Arduino USB cable (for communication)
Installing Arduino Package:
MATLAB Simulink don’t come with pre-installed packages for Arduino. You simply have to download it from the official site of Mathworks. For MATLAB 2013 and above versions,
1. Run the MATLAB program,
2. In menu bar go to the HOME menu. (‘1’ in figure 1)
3. There is block for RESOURCES having an option of ad-Ons. (‘2’ in figure 1)
4. Click on get hardware support packages (Figure 2)
5. Support Package Installer window will open (Figure 3)
6. This window will have option of (Figure 3_1)
i. Install from internet: to install the hardware package directly from internet to your computer
ii. Download from internet: to download the package from internet but not installing in MATLAB program
iii. Install from folder: to install the downloaded support package from your computer.
iv. Uninstall: to uninstall some installed support package
7. You can also open support package installer by writing targetinstaller in command window.
(We will chose install from internet. You can also download the package then installing it.)
8. Click Next on that Support Package installer window in bottom right. (Figure 3_2)
9. Next window will open showing all the available hardware support packages.(Figure 4)
10. Click on Arduino and click Next(Figure 4-1 and 4-3)11. You will have to sign in in your Mathworks account. If you don’t have one, create one with any of your working email address. (see Figure 5 to Figure 8)
12. After sign in by your email address and password, click login and click next and next and it will take a little time (depending upon internet connection) to download and install. Then click finish.
When installation is complete, Connect your Arduino board with the computer using its data cable and write a=arduino it will show the COM port with it is connected through computer and board and other details about it. as shown in figure below the board is Mega2560 and it is connected to the COM1 also showing analog and digital pins of it.
Now the MATLAB is ready to work with Arduino Borad. You can directly burn the Arduino through the MATLAB Simulink and make your life very easy.
After Successful installation of Support Package, the Arduino Libraries in MATLAB Simulink will be added.
Open the Simulink Library by clicking on the option in SIMULINK menu in HOME tab (figure 9). Simulink Library will open and in the left side, along with all the available libraries, there will two libraries Arduino IO library and Simulink Support Package for Arduino library. They have further blocks in them to use. (figure 10)
Arduino I/O Library:
Once you have installed Arduino Support Package, in MATLAB Simulink Libraries, one of the libraries will be Arduino IO Library. This library contains 12 further blocks/operations you can do with Simulink and Arduino connected. This library allows to send the information from the MATLAB to the connected Arduino Board as well as receive from the board. These are shown in following figure 11:
When these blocks are executed, they takes the input voltage at the provided pin defined in the parameter box i.e. they takes/senses the voltage at that specific pin at that specific time at print to the MATLAB. This could be used as real time feed to the MATALB. (See Example).
When these blocks are executed in Simulink, they give the output high to the Arduino i.e. gives the signal to the specified pin.
Simulink Support Package for Arduino tool in MATLAB Simulink Library has four section naming: Common, Ethernet Shield, Wifi Shield and Examples. In Common Blocks Analog Read/Write, Digital Read/write, Motor Control, Servo Control, PWM (on output/PWM pin of Arduino) and Serial Transmit/Receive. (Figure 12)
In Case of any Query and problem regarding this, feel free to contact us and follow us on Facebook for updates. 🙂