Go Down

Topic: Setting variables with Matlab (Read 1 time) previous topic - next topic


Mar 26, 2014, 03:07 pm Last Edit: Mar 26, 2014, 03:24 pm by kakaovnik Reason: 1
Hi Arduinos!
I am working on my project and got stuck at sending variables from Matlab to Arduino.

What I want to do is to send this value from Matlab: 255,100,0,100,175,300
to fill 6 variables in Arduino so I can setup my PORTD properties. I want to generate signal like this on output:

I understand I can use Serial.parseint to fill my variables, but it is not really working, and since I'm really new to programming I don't know where I made a mistake. Can you PLEASE help me?

Arduino code looks like this:

Code: [Select]
 int a=0;
 int b=0;  
 int c=0;
 int d=0;  
 int e=0;
 int f=0;
void setup()

void loop()
 if(Serial.available()>0) // if there is data to read
   a=Serial.parseInt(); // read data
   PORTD = a;
   delay = b;
   PORTD = c;
   delay = d;
   PORTD = e;
   delay = f;

Matlab code:

Code: [Select]
global s;


Code: [Select]

Open the serial port, resetting the Arduino.
While it's rebooting, jam some data at it.
Close the serial port, resetting the Arduino again.

What was the point in sending it data if you don't wait for it to be ready to receive it?


Thank you for answer!
And how can I do that? What would be the best solution?


And how can I do that?

We've hired a psychic. His start data is the 12th of never.

If you need help before then, you'll need to ask questions that have answers. No clue was provided as to what the "that" is that you want to do.


I am sorry Paul,

how am I supposed to make matlab wait for arduino to process my data?

Should I put it to a while cycle? And how? I am bit confused here.

Thank you.


how am I supposed to make matlab wait for arduino to process my data?

The best matlab answers would come form a matlab forum.


You may use matlab Simulink, there's an interface called Serial send and Serial receive. I've tested it with Arduino, works fine.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131