I am trying to communicate serially between Matlab and Arduino Uno, and implement some flow control mechanisms that I study in college. Here the Arduino needs to take a number serially, and if it expected that number (there's a logic for figuring out which number it expects), write the same number to Serial after a certain delay, otherwise do nothing. the code I'm uploading to the board is -
I'm printing "inside the if" just for debugging purposes. Trouble is it never prints it to the serial monitor, meaning it never goes into the If condition (it should ATLEAST satisfy the If in the first iteration, when I give it a 0 serially).
Any idea why this is happening? The problem has been eating my brain since two days!
Serial.write sends out binary, may be getting non-printing characters sent instead.
see asciitable.com for cross reference of the characters/ascii value/hex value
Alternatively, if you are only sending characters that represent decimal digits:
iframe=Serial.read() - '0';
The Serial Monitor deals with strings. The number 0 is the character 0 as far as the Serial Monitor is concerned, so that character is what it sends to the Arduino, not the number 0.
thanks for the replies everybody! turns out the problem was something else altogether.
I wasnt pausing for enough time after writing the fopen(serial obj) in Matlab. Arduino resets everytime fopen() is executed, and so the poor thing was getting confused - data coming in serially while its still booting!
Thanks PaulS, one of your earlier posts came in handy!