ArduinoIO package and Arduino Uno Motor Shield R3 server sketch?

3 visualizzazioni (ultimi 30 giorni)
I'm trying to use R3 shield with matlab script. I installed the ArduinoIO package but there is no server sketch for Arduino software for this particular shield. Only Adafruit motor shields are included. Where do I get the right sketch for driving R3 with this package?

Risposta accettata

Sami Harju
Sami Harju il 31 Mar 2015
I figured this out. No sketch was needed, just the right tools. Arduino can read serial ports and matlab write to them. Here's the codes if anybody ever meets the same "problem":
Arduino:
// using example:
// http://social.nkcelectronics.com/discussion/1/arduino-motor-shield-r3-introduction/p1
// Include the Stepper Library
#include <Stepper.h>
// Map our pins to constants to make things easier to keep track of
const int pwmA = 3;
const int pwmB = 11;
const int dirA = 12;
const int dirB = 13;
// The amount of steps for a full revolution of your motor.
const int stepsPerRevolution = 200;
// Initialize the Stepper class
Stepper myStepper(stepsPerRevolution, 12,13);
// Initialize the incoming command byte
char incomingByte = 0;
void setup() {
// Set the RPM of the motor
myStepper.setSpeed(40);
// Turn on pulse width modulation
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
// Start the log
Serial.begin(9600);
}
void loop() {
// Wait for any input from serial
if (Serial.available() > 0) {
// Read the incoming byte
incomingByte = Serial.read();
// Commands for stepper
if ( incomingByte == 'a' ) {
myStepper.step(200);
}
}
}
Matlab:
% using example:
% http://se.mathworks.com/help/instrument/writing-and-reading-data-2.html
pause on;
% initialise serial object
s = serial('COM6');
s.Baudrate=9600;
s.StopBits=1;
s.Terminator='LF';
s.Parity='none';
s.FlowControl='none';
% open for usage, pause for process delay
fopen(s);
pause(2);
% give the serial port a command for arduino to execute
for n = 1:10
fprintf(s,'%c','a'); % using char a for "drive"
pause(2);
end
delete(s)
  1 Commento
Guilaume lollia
Guilaume lollia il 24 Set 2020
it is probably what i am looking for i have been trying to make a GUI with matlab 3 GUI- pushbutton making my stepper motor 3 differents angle, 60, 45, 75 degrees with Arduino Motorshield Rev3
As i am a complete beginner with this arduino and communication devices.
and then i do not understand your statement using char a for "drive". Could you explain me please ?
what will be line code or will you write to make it move ?
Thanks

Accedi per commentare.

Più risposte (0)

Community

Più risposte nel  Power Electronics Control

Categorie

Scopri di più su MATLAB Support Package for Arduino Hardware in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by