Using matlab support package for arduino with any motor shield

조회 수: 14 (최근 30일)
Derick Ghoda
Derick Ghoda 2017년 7월 29일
댓글: Madhu Govindarajan 2018년 2월 6일
I have an L298N motor shield that I wish to use to drive a DC motor with the help of the MATLAB support package for arduino (NOT the Simulink support package). Browsing on the internet for an example code, all I've found are examples using the ADAFRUIT MOTOR SHIELD which is not the motor shield I would like to use. So my question is, is it possible to drive a DC motor directly in MATLAB without any DC motor shield on the market other than the ADAFRUIT MOTOR SHIELD ? If yes please help me with an example code.

채택된 답변

Menghan
Menghan 2017년 7월 31일
편집: Menghan 2017년 7월 31일
Hi Derick,
From what I find about this L298N motor shield online, it seems to only need digital IO and PWM signal for direction and speed control. To drive it in MATLAB, simply replace digitalWrite to writeDigitalPin and analogWrite to writePWMVoltage or writePWMFrequency to convert any existing Arduino examples. Please refer to the MATLAB Documentation for correct input parameters to writeDigitalPin/writePWMVoltage/writePWMFrequency.
Hope this helps.
Thanks,
Menghan
  댓글 수: 3
melisa samad
melisa samad 2018년 2월 6일
Hi sir. I'm using the OptoCoupler sensor as a speed sensor. In Arduino, I can calculate the rpm, but in Matlab, I cannot figure out. Can you explain about this coding?
Madhu Govindarajan
Madhu Govindarajan 2018년 2월 6일
From the above code the ones that are used to read the speed value in rpm are -
clear; clc; close all; a = arduino('COM5','Uno','Libraries','rotaryEncoder') encoder1 = rotaryEncoder(a,'D2','D3',64)
rpm = readSpeed(encoder1)
You should be able to do that as long as the two channels of the quadrature encoder are on pins D2 and D3. Post a separate question if this does not work for your specific sensor or if you get error messages, once you try this out.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

커뮤니티

더 많은 답변 보기:  Power Electronics Community

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by