Go Down

Topic: send array of integers via xBee s1 (Read 3 times) previous topic - next topic

propilot01

The code was the one you send me, but i fixed the problem, it was simply an error with #define (I've written #Define x=2 as I added you part to my code, then I've seen my huge mistake).
Now, you said me I do not understand Serial communication, it's right, as I wrote Serial.flush() I was trying to clear the buffer, so that the data will be the newest possible. How does I clear the buffer?
Thank you for your help!

PaulS

Clearing the buffer is generally not a good idea. The old flush() method did that by throwing away random amounts of unread data. I can't see how that is a good idea, unless you are resting code that re-syncs with a sender.

If that is not the goal, then every character sent was sent with the expectation that it would be important, and, therefore, read.

Why would you not want to read that data, if you sent it?

If you don't want the Arduino to have to read the data, don't send it.

propilot01

I need to have always the more recent data sent, so that the car has the latest command i gave her, If the buffer fills quicker than arduino reading it's data I would have always an encreasing delay from my commands and what the robot does, isn't it?

Now as I'm writing about this I've thought:I could add a part of code that sends an "ok" when it's ready to recive, so the ground station sends it's data and the car recive only those one, leaving the buffer clear when I don't need data and ready to recive as I have to use them. would that work?

My first idea was: ground station continues sending data, car reads the latest sent. I clear the buffer so that the data aren't too old
Now: car needs data, send a byte to the G.station, which sends back the array of data needed. No useless communication, no buffer filling up with data i don't need ,as you said, REALLY the latest data availale.
Right?

PaulS

Quote
If the buffer fills quicker than arduino reading it's data I would have always an encreasing delay from my commands and what the robot does, isn't it?

Yes. So, don't let that happen. Get rid of any delay()s, so that you spent most of your time checking to see if there is anything to do, rather than doing nothing.


propilot01

I have a little question: as I use the serial.read() function, does it need some time to delete the readen data or is it immediate? I've had some trouble because as I send something like 1,2,3 with the code you gave me I receive 1111,,,,2222,,,,3333 and I'm wondering if it's a problem with some delay() I should use. I simply read the data and put them in one array, should I use some delay to give my board the time do read and then clear the data?

Go Up