Category:PCB Arduino

Group Administrators: 1 | Group Member: 81 | Group Threads: 86

Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects. About Arduino and Arduino Projects sharing are appreciated.

Thread Reply
Arduino Interface with MATLAB Reply 2017-02-07 05:43:35
821 views
1 comments
179 likes

Cash

Leave A Message

Follow

We're going to create simple MATLAB m-files to talk to our Arduino board. The MATLAB Support Packages for Arduino Hardware lets you use MATLAB to communicate with your board through USB cable. The support packages are available for 32-bit and 64-bit Windows, 64-bit Mac OS and 64-bit Linux.
Installing Packages
You can easily install packages through your MATLAB.
First, start MATLAB and click the Add-Ons drop down menu. In the drop-down menu click Get Hardware Support Packages. It will start the package installer window.
Select Install from internet and then Next.
In the next window you will see all the available packages for MATLAB and Simulink. Select the Arduino package, then check all the packages displayed and click Next to continue installation. Note that this picture is showing that I am reinstalling the Arduino packages because I had previously installed them.
Next, the installer will ask you to log in to your MathWorks account. If you don’t have an account, you can create one during installation. Accept the license agreement on the next screen and continue to download the packages. Now you have to wait for MATLAB to download and install all the required packages.
Testing
Once the packages are installed, connect your Arduino board to your PC and type the following command in MATLAB command window,
>> a = arduino()
if you have more than one Arduino connected to your PC, you have to specify the board type you will be communicating with:
>> a = arduino(‘com3’, ‘uno’)
MATLAB will then attempt to communicate with your board. If successful, MATLAB will display the properties of the Arduino board connected to your PC as shown below:
This information displays the port on which your board is connected, the model of your Arduino board, and available pins and libraries available for the board.
In your workspace, you will see a variable a, which is the MATLAB Arduino object. Run the following command to clear this object.
>> clear a
This command will remove the object a from your workspace.
Wiring Diagram
Connect the cricuit as shown below to complete the following two examples:
It will look something like this:
Experiment 1: Digital I/O with MATLAB
In this example we will blink an LED with MATLAB.
Hardware
  • Arduino Uno
  • 1 x 1k Ohm resistor
  • USB cable for arduino
  • LED
Start MATLAB and create an m-file and write the following code:
Make sure there is no previous Arduino object stored in MATLAB, otherwise MATLAB will display an error message. Save your file and run it. This will blink the LED for a period of 1 second.
Steps
  1. Start MATLAB and install Arduino Hardware Support Packages (if not already installed).
  2. Connect your board to the PC and test if it’s working properly with MATLAB.
  3. Make the circuit as shown in the circuit diagram and connect pin 11 to one end of the LED pin through resistor.
  4. Connect other point of the LED to the ground pin on your arduino board.
  5. Write your m-file and save it. Run your file and MATLAB will burn that file to your board.
  6. Your led will start to blink.
Experiment 2: Analog control
In this example we will use a pulse-width modulated signal to change the brightness of the LED. The program calculates a brightness_step by dividing the maximum and minimum voltage supplied by the pin by the number of iterations in which we will reach maximum brightness of led.
Hardware
  • Arduino Uno
  • 1 x 1k Ohm resistor
  • USB cable for arduino
  • LED
Connect the circuit as shown above in the circuit diagram.
Steps
  1. Start MATLAB and install Arduino Hardware Support Packages (if not already installed).
  2. Connect your board with PC and test if it’s working properly with MATLAB.
  3. Make the circuit as shown in the circuit diagram, connect pin 11 to one end of the LED pin through resistor.
  4. Connect other point of LED to ground pin on your arduino board.
  5. Write your m-file and save it. Run your file and MATLAB will burn that file to your board.
  6. Your led will start to brighten and then dim.
179 likes
Statement: This post is only the personal view of the author and does not represent the opinions of ALLPCB.com.

Blair

Leave A Message

Follow

Your post answered my questions. Thanks a lot.
ThreadReply