Arduino 1.0 with serial.flush();

Hi all,

Wondering if anyone has come across this, i am doing a time based project which requires me to dump the incoming serial buffer on occasion so that i don't have any lag, anyway, I originally made the prog in Arduino 0022 and its been working great, but now I have upgraded to 1.0 the Serial.flush(); function doesn't work for incoming data, thus giving me my original problem.

Anyone know how to wipe the incoming buffer in 1.0?

Cheers

the flush function code is

while (_tx_buffer->head != _tx_buffer->tail);

So it doesn't actually clear anything ( only uses transmit buffer in code as well ). Maybe you can do dummy reads to empty the buffer.

try this to flush the input

while( serial_object.read() != -1 );

loops until no more input ( replace serial_object with whatever name you are using for the serial object. )

cheers

i am doing a time based project which requires me to dump the incoming serial buffer on occasion so that i don't have any lag

How does dumping random amounts of unread data remove lag? How do you know when to start reading again?

Well, I don't really care about the data that I dumb because I'm only sampling for a certain number and then acting on if I receive that number or not, I have an overlap time there its is safe not to sample, so it seems to all work out in the end, though have had a few teething problems but that's just to do with stuff like thresholds, maybe I'm doing something not right but its been working great! I think!!

That last post didn't quite come out right, haha, anyway you get the jist of it, though how would I actually wipe the buffer, is it EEPROM memory or something?

how would I actually wipe the buffer, is it EEPROM memory or something?

No, it is in SRAM. You must actually read everything. Whether you choose to use it or not is up to you.

The main reason for the change was because flush() was often misused in the past, the way you were using it.

PaulS to answer your question correctly, and maybe clarify what I'm actually trying to do, The reason i said that it reduces lag is that I have two xbee modules, one is on a continuous transmit loop, (every 0.5 seconds) and when i receive that signal i'm activating a relay, anyhow, when i go out of range the relay stays on for the same amount of time that i was in range, because it has stored up a huge amount of received data in the incoming buffer, therefor i must remove it before i sample again, this way when i go out of range it cuts off straight away.

anyhow, when i go out of range the relay stays on for the same amount of time that i was in range, because it has stored up a huge amount of received data in the incoming buffer

Not more than 32 bytes, since that is the incoming serial buffer size with 1.0. How long can it take to read and ignore, or not, 32 bytes?

Not more than 32 bytes, since that is the incoming serial buffer size with 1.0.

Cough 64 cough

Actually 32 (well 64) seconds, because its a delayed process, though good thought ill have a look at that. Could I use Serial.find to mod this? instead of trying to do it manually

Cough 64 cough

I'd read 32 in other posts, and assumed that the information was accurate. You are correct; it was not.

In any case 32, 64, or 128, the previous buffer size, hardly qualifies as "a huge amount of received data in the incoming buffer". The Arduino can read and decide what to do with 128 bytes of data very quickly. The slow part might be actually using the data.

Actually on that subject, i assumed that "ATmega 328" meant 32 kb and 8 bit,when I compile it says of a 32256 maximum, is that flash then and not SRAM?

is that flash then and not SRAM?

Yes. There is 2K of SRAM.