accessing arduino variables using matlab

Hi, i have an arduino program reading a rotary encoder. i open arduino on matlab using serial, and id like matlab to read variables value from arduino but not sure how to access them. something like "serial.read" or global variable..

any advice? Thanks!

id like matlab to read variables value from arduino

And pigs would like wings. That isn't going to happen.

Matlab can send messages to the Arduino. The Arduino can read the message, and respond appropriately. That might include sending the contents of a variable to Matlab. But, Matlab is not going to get direct access to anything on the Arduino.

ok.

any suggestions on how to get arduino to send content of a variable to matlab?

any suggestions on how to get arduino to send content of a variable to matlab?

Serial.print(theContentsOfAnyOldVariable);

serial.print() prints on the serial monitor. that works great. the question is how can i pass the information to matlab?

Galya: serial.print() prints on the serial monitor. that works great. the question is how can i pass the information to matlab?

You have to get your Matlab code to take the place of the Serial Monitor by connecting to and reading from the serial port (COM port) on your PC.

There is a large number of Forum Threads about Matlab. Do some Googling.

...R

The first thing i did was writing a code on matlab, and it worked good, but far to slow. so i realized i have to let arduino read the pins, because its much faster. so now the arduino is reading pins and counting the movement of the rotary encoder, and it really works great. the only thing is, im looking for a way to pick up a value from the arduino and output it in Matlab.

-Galya.

Galya: im looking for a way to pick up a value from the arduino and output it in Matlab.

First - have you used Google to find any of the other Arduino Forum Threads about Matlab? I would be very surprised if you do not find an answer that way.

Second, if you still need help you need to post the code you have tried - even if it does not work very well.

...R

I’ve been Googling for days.

this is the code im using on Arduino
https://www.pjrc.com/teensy/td_libs_Encoder.html
works perfect.

and for matlab-

arduino=serial(‘COM6’,‘BaudRate’,9600);
fopen(arduino);

%HERE I’D LIKE TO HAVE SOMETHING LIKE “disp(Serial.println(positionLeft))”

fclose(arduino);

%HERE I'D LIKE TO HAVE SOMETHING LIKE "disp(Serial.println(positionLeft))"

Feel free. It looks pointless.

The Arduino will use Serial.println() to send data to Matlab. Matlab will NOT use Serial.println(). Matlab will use its own method/function to read from the serial port.

Galya: and for matlab-

arduino=serial('COM6','BaudRate',9600); fopen(arduino);

%HERE I'D LIKE TO HAVE SOMETHING LIKE "disp(Serial.println(positionLeft))"

fclose(arduino);

I wonder if the problem is the opening and closing of the Serial port. Usually when the PC program opens the port it causes the Arduino to reset.

Try re-arranging your Matlab code so it opens the serial port and keeps it open until it is finished with the Arduino.

...R

Paul- i know that, that's why im asking around.

Robin-no, opening and closing isnt a problem. the problem is accessing the values of the variables- like "positionLeft" that is on the arduino code.

the problem is accessing the values of the variables- like "positionLeft" that is on the arduino code.

No. It seems to me that the problem is that you don't have a clue how to read serial data in Matlab. Asking how to do that on a Matlab forum is going to be far more effective than to keep asking here. They don't know anything about Arduino. We don't do Matlab.

Not sure what your problem is, if you don't know how to help you can save your cheerfulness to yourself. last i checked the purpose of the forum is to get advice and answer to questions not defeat-full attitude

last i checked the purpose of the forum is to get advice and answer to questions ABOUT THE ARDUINO

Galya: Robin-no, opening and closing isnt a problem.

Have you done any tests to prove that?

the problem is accessing the values of the variables- like "positionLeft" that is on the arduino code.

If I take your statement literally it cannot be done. The Arduino is the only thing that can acces Arduino variables.

Your Arduino program can send the value of a variable using Serial.println(myVariable) - but you have already been told that in an earlier Reply.

This YouTube video seems to be doing what you want

...R

Is the Mathworks package not appropriate for your project? http://uk.mathworks.com/hardware-support/arduino-matlab.html

A place to do some reading.

https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=matlab+serial&btnG=search&domains=http%3A%2F%2Fforum.arduino.cc&sitesearch=http%3A%2F%2Fforum.arduino.cc&gws_rd=ssl