Intro Arduino Matlab v5
Intro Arduino Matlab v5
net/publication/339003854
CITATIONS READS
0 4,244
2 authors:
Some of the authors of this publication are also working on these related projects:
Smart Multi-Terminal DC micro-grids for autonomous Zero-Net Energy Buildings View project
All content following this page was uploaded by Francisco Gonzalez-Longatt on 03 February 2020.
Introduction
Arduino is an open-source hardware and software company that designs and manufactures
single-board microcontrollers and microcontroller kits for building digital devices. The Arduino
company products (Arduino boards and software) can be produced and distributed by anyone
since these products are licensed under the GNU Lesser General Public License (LGPL) or the
GNU General Public License (GPL).
A program for Arduino hardware may be written in any programming language with compilers
that produce binary machine code for the target processor.
The Arduino integrated development environment (IDE) is a cross-platform application (for
Windows, macOS, Linux) that is written in the programming language Java.
On October 18th, 2019, Arduino Pro IDE (alpha preview) was released. The system still uses
Arduino CLI (Command Line Interface), but improvements include a more professional
development environment, autocompletion support, and Git integration.
However, Arduino programming is supposed to be fun but can become frustrating and time-
consuming for tasks such as plotting sensor data or incorporating advanced math, signal
processing, or controls routines into your projects.
MATLAB® and Simulink® address several challenges with traditional Arduino programming.
MATLAB support package for Arduino allows writing MATLAB programs that read and write
data to Arduino and connected devices, such as Adafruit motor shield, I2C, and SPI devices. The
main benefits of using MATLAB for Arduino programming are:
• Read and write sensor data interactively without waiting for code to compile.
• Analyse the sensor data using thousands of pre-built functions for signal processing, machine
learning, mathematical modelling, and more.
• Quickly visualise the data using the vast array of plot types in MATLAB.
Reader must find useful looking into the official MathWorks videos related to MATLAB-
Simulink interaction with Arduino.
https://uk.mathworks.com/matlabcentral/fileexchange/47522-matlab-support-package-for-
arduino-hardware
FIG. 9. I NSERT A BLOCK FROM THE LIBRARY BROWSER ONTO THE WORKSPACE .
b) Select the block and drag it from the Library Browser to the model workspace
[Fig. 9].
where Vref = 2.2, input = 0 < input < 4095, N = 12 (number of bits on DAC channel), Voffset
= 0.56. Vref is the reference voltage for the DAC pin. Therefore, to obtain the output signal
in the correct values, it is necessary to compute input from (1) as follows:
N
(
input = 2 − 1 Vout − Voffset ) (2)
Vref
Substituting the known values:
Therefore, several adjustments must be made before sending the signal to Arduino
Due:
• An offset must be added to the signal; the value of the offset must have the same
value of the amplitude of the signal to have a completely positive signal.
• A gain of (212-1)/2.2 must be added to deliver the signal whit the magnitudes
corrections.
• The signal must be converted to uint16 because it is the type of accepted values
in the Analog Output block.
Analog Input block: Measure the voltage of an analog pin relative to the analog input
reference voltage on the Arduino hardware. If the measured voltage is equal to the analog
reference voltage, the block output emits 1023. The default value of the analog input reference
voltage for Arduino Due boards is 3.3V. Therefore, for coupling the measured analog signal, it
is necessary to add a gain of 3.3/1023 that modifies this signal to the required ranges. Moreover,
it is required to subtract the offset that was previously attached to have an entirely positive
signal.
Table 1. Parameters of the Model
Block Equation Parameters
Data Type
Conversion Output data type: uint16
--
uint16: converts inputs to 16-
bit signed integer.
5. Click the Monitor & Tune -button. The model will now be deployed to the connected
Arduino hardware and a code generation report will appear [
6.
7. Fig. 14].
Hardware Setup
The sine wave generator created in the previous subsections using the Simulink® Support
Package for Arduino® Hardware. The sine wave generator was designed in Simulink, but it
must be deployed and used inside the Arduino Due, as a consequence, hardware setup is needed.
The top view of Arduino Due is presented in Fig. 16.
FIG. 17. GENERAL VIEW OF THE A RDUINO D UE SHOWING THE PROGRAMMING PORT
Simulink model
USB connection
GND DAC0
Oscilloscope
Oscilloscope
probe
Arduino Due
USB Connection
Measurements
This section is dedicated to present recording of the test process of the sine wave generator
implemented using Arduino Due. The initial setting of the Sine wave block is as shown in Fig.
22.
F IG. 22. SETTINGS OF THE SINE WAVE B LOCK. AMPLITUDE = 1, FREQUENCY ( RAD/ SEC)
= 10 RAD/ SEC ( F = 1.5915 HZ)
The output of the scope in the simulink model is presented in Fig. 23.
F IG. 23. SCOPE OF THE S IMULINK MODEL. AMPLITUDE = 1, FREQUENCY ( RAD/ SEC) = 10
RAD/ SEC (F = 1.5915 HZ ). O UTPUT OF THE SINE WAVE BLOW (BOTTOM ), O UTPUT OF THE
DATA TYPE CONVERSION (U NIT 16).
The 50 MHz oscilloscope, Tektronix TBS 1052B-Edu, is used to record the analog output from
the Arduino Due and the screen capture is presented in Fig. 22.
FIG. 24. CAPTURE OF THE A RDUINO D UE SHOWING THE SINE WAVE GENERATOR . (F =
1.5915 H Z)
Now, the frequency of the sine wave is increased and the setting the parameters of the sine
wave block inside the Simulink model as presented in Fig. 25. The amplitude is adjusted to 1,
and the frequency = 314.1593 rad/sec, as a consequence, f = 50 Hz.