Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with Arduino Uno R3 for stepper motor and controlling it with Matlab

Status
Not open for further replies.

PlumPuddingBoard

Newbie level 1
Joined
Jun 4, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,301
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.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top