Very slow serial communication between Arduino Duemilanove and Matlab R2011a

Hello everybody !

My search wasn't that successful, so I put a new topic for this issue.

A couple of weeks ago, I managed to connect my Arduino Duemilanove (atmega168) with Matlab R2011a (on Windows). For doing so, I installed ArduinoIO and uploaded the adiosrv.pde code on my Arduino.

I then decided to test the serial communication between Arduino and Matlab and put a sinus voltage 0-2V on a pin to read its output.
On Matlab, I made a new model in Simulink and put a Scope at the output of a AnalogRead block (and somewhere else, I put the Arduino Setup box correctly configured).

The result : I record a quite stairs looking signal with about 60 steps a second. But I read that the communication can be a lot faster. Do you know where is the issue ?

My aim : recording signal whith a frequency up to 100 Hz.

I hope this is easy to solve for you !

Rob.

P.S. : the serial baud rate is 115200.

Can you post the Arduino code you have?
The ADC takes less than a millisecond,
if you send the RAW measurements as 2 bytes that will take @115200 about 2 milliseconds (let the PC do the conversion to volts)
So a freq. of about 500Hz should be possible.

Furthermore the Arduino can send at higher speeds (but not to the Serial Monitor of the IDE)
I have used with succesfully 230400 345600 and 500000 baud which makes about 2Khz samples possible.
Don't know which speeds are supported by MatLab.

If you want really fast IO you might consider using a teensy2.0 or so; IIRC it can go upto 1MByte /second.

Thank you for your reply.

Here's the code in the file adiosrv.pde used to communicate with Matlab.

https://code.google.com/p/arduinolab/source/browse/ArduinoIO/ArduinoIO/adiosrv/adiosrv.pde?r=b25efc9ea77bbfde5af8774ec57432f23b24a0f2

I think it has to be possible to send at a high frequency but I don't really understand why it takes so long with this code.
By the way, if I am not clear, don't hesitate to ask me what I mean because I am French and can make some mistakes…

Thank you in advance !

Sorry,

I found that the code has the same name but has been modified. Here is the code I use, attached.

adiosrv.pde (25.7 KB)

The code waits for serial input (from matlab) before it sends something.
That may be the cause.

Ok. I will try and see if it is possible to modify the cadence of request from Matlab, or make a code which don't wait for a request. By the way, do you know how I could do multiplexing with Arduino to send datas from several pins through serial port ? And how to separate the signals when they arrive on the computer ?

Thanks for your help !

you can merge the pin signals into one byte by bitmanipulation

... readpins..

byte b = (pin1 << 7) & (pin2 << 6) & (pin3 << 5) & .... & (pin8 << 0);
Serial.write(b);

the byte has now the value of the 8 pins in a bit position

on the matlab site you need to extract the individual bit values , unfortunately I do not know the details of matlab language.

Thank you very much for your answers !

I am going to try it next Tuesday, when I get back my Arduino (lent to a colleague). If I find how to demux signals on Matlab, I will share the solution.

Hello again !

I tried with the code in this thread (second page):

But it seems that my sample rate is not that good : I have about 800 samples per second in Matlab with a single input.

With two inputs, the number of samples rises to about 1200 per second, and I don't know why.

My aim is to have a sample rate of about 10-12 kHz.

Could you help me ?

robtillaart:
The code waits for serial input (from matlab) before it sends something.
That may be the cause.

How would I fix that.