Communication problems to an Arduino Board

I am working on MATLAB to communicate with an Arduino. The code is very simple. I am sending an A to the Board, and want to read 100 bytes from the device.

I keep getting this Warning: Warning: Unsuccessful read: The specified amount of data was not returned within the Timeout period..

and only 47 Bytes are read, which is the header, meaning that sending "A" to my board, did not have any effect on it, is there any solution?

arduino=serial('COM8','BaudRate',115200);
fopen(arduino);
fwrite(arduino, 'A');
daten = fread(arduino, 100, 'uint8');
fclose(arduino);

When your PC program opens the serial port the Arduino will reset and that some seconds before it is ready to receive data. You are not allowing for that.

Ideally your PC program should open the serial port, wait for a message from the Arduino - I usually put Serial.println("") in setup() - before sending anything, and then keep the serial port open until it is completely finished with the Arduino.

...R

I have added this line to my Arduino program in setup(): Serial.println("");

instead of reading 47 it reads now 48 bytes , including the header, but still I dont receive out of the board what I need.

You have some issue with the code on the Arduino, or you wouldn't be posting here. So, WHERE IS YOUR CODE?

The arduino code should be fine as I have tested successfully the serial communication using the program Termite 3.2
but anyways here it is :

but anyways here it is :

Well, some of it, anyway.

So, here's the answer (well, some of it, anyway):

You need to chan...

The arduino code works fine, and since it is not only my work, I cannot publish the whole code here. Thanks anyways..

Maybe someone else who faced similar problem with Matlab can help :slight_smile:

monardi:
I have added this line to my Arduino program in setup(): Serial.println("");

instead of reading 47 it reads now 48 bytes , including the header, but still I dont receive out of the board what I need.

But it sounds like you have not modified your Matlab program to make use of the changed Arduino code. The two programs have to be designed as a pair. (And I have never used Matlab so I can't advise you about that side of things).

...R

I have solved it , thank you!

I have included a short delay in my MATLAB program using the pause function and before writing to the board I have read 47 bytes and then the serial communication went successfully, it's possible to skip the header with fseek