Unresponsive motor

Thread Starter

CircuitsBlown24

Joined Jun 4, 2012
1
Hello, I recently bought an Arduino Uno R3 to control a stepper motor and to control it with Matlab/Arduino IDE. However, it seems not to be syncing up with Matlab correctly. It can connect to the serial port, but it cannot print out numbers I have written to the board.

ARDUINO CODE:
#include "Arduino.h"
#define DIR_PIN 2
#define STEP_PIN 3

void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
Serial.begin(9600);
}

int incomingByte = 0; // for incoming serial data

void loop() {

// send data only when you receive data:
//if (Serial.available() > 0) {
// say what you got:
Serial.print("I received: ");
int a=Serial.read();
Serial.print(a);
// Serial.println(incomingByte, DEC);
}

MATLAB CODE:
s = serial('COM3', 'BaudRate', 9600);
fwrite(s, 50)
??? Error using ==> serial.fwrite at 199
OBJ must be connected to the hardware with FOPEN.

fopen(s);
fwrite(s, 50);
fscan(s);
??? Undefined function or method 'fscan' for input
arguments of type 'serial'.

fscanf(s)
Warning: A timeout occurred before the Terminator was
reached.

ans =

I received: -1I received: -1I received: -1I received: -1I received: 50I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1I received: -1


NOTE: In the Arduino code, I took out the IF statement asking if the data was available because it would not work with it. Do to this reason and also the output of the above code, I realize that the problem with my Arduino is that it is not recieving data, so none is available.

Can someone tell me what this means, for no data to be available? Also, can someone help me fix it? I have already tried adding libraries and updating the arduino driver, but it has not helped. Also, the Arduino IO package from Matlab does not seem to function correctly (i.e. motor will not work).

Thank you for any help that you may provide.
 
Top