Hi,
I'm trying to analyse how often (and how much) data a GPS module is generating. I started with this very simple loop.....
for (int i=0 ;i<36000; i++)
{
bytesRead = 0;
while (Serial1.available())
{
// Read (and ignore) a SINGLE byte from the port
Serial1.read();
bytesRead++;
}
Serial.print("Read <");Serial.print(bytesRead);Serial.print("> bytes from GPS port at <");Serial.print(millis());Serial.println("> milli seconds since startup.");
bytesRead = 0;
}
this gives no problems and gives me a result like this.....
Read <0> bytes from GPS port at <1433> milli seconds since startup.
Read <0> bytes from GPS port at <1438> milli seconds since startup.
Read <0> bytes from GPS port at <1444> milli seconds since startup.
Read <35> bytes from GPS port at <1451> milli seconds since startup.
Read <34> bytes from GPS port at <1457> milli seconds since startup.
Read <34> bytes from GPS port at <1463> milli seconds since startup.
Read <33> bytes from GPS port at <1468> milli seconds since startup.
Read <34> bytes from GPS port at <1474> milli seconds since startup.
Read <34> bytes from GPS port at <1480> milli seconds since startup.
Read <33> bytes from GPS port at <1486> milli seconds since startup.
Read <34> bytes from GPS port at <1492> milli seconds since startup.
Read <33> bytes from GPS port at <1498> milli seconds since startup.
Read <34> bytes from GPS port at <1504> milli seconds since startup.
Read <34> bytes from GPS port at <1510> milli seconds since startup.
Read <33> bytes from GPS port at <1516> milli seconds since startup.
Read <11> bytes from GPS port at <1522> milli seconds since startup.
Read <0> bytes from GPS port at <1527> milli seconds since startup.
Read <0> bytes from GPS port at <1533> milli seconds since startup.
Read <0> bytes from GPS port at <1540> milli seconds since startup.
Which is exactly what was expected - it tells me at what moment the GPS sent a burst of data.
I then decided to modify the routine to totalise the amount of data received in each burst. this is what I wrote....
for (int i=0 ;i<36000; i++)
{
while (Serial1.available())
{
// Read (and ignore) a SINGLE byte from the port
Serial1.read();
bytesRead++;
}
// totalise the amount of data received in each 'burst'
if ( bytesRead != 0 )
{
totBytesRead = totBytesRead + bytesRead;
burst++;
}
Serial.print("bytesRead=<");Serial.print(bytesRead);Serial.print(">, totBytesRead=<");Serial.print(totBytesRead);Serial.print(">, burst=<");Serial.print(burst);Serial.print("> prevBytesRead=<");Serial.print(prevBytesRead);Serial.println(">");
if( (bytesRead == 0) && (prevBytesRead!=0) )
{
Serial.print("Read <");Serial.print(totBytesRead);Serial.print(">bytes, in <");Serial.print(burst);Serial.print(">bursts, from port at <");Serial.print(millis());Serial.println("> milli secs since start.");
totBytesRead=0;
burst=0;
}
prevBytesRead = bytesRead;
bytesRead = 0;
}
As before, this produced exactly what I expected.....
bytesRead=<0>, totBytesRead=<0>, burst=<0> prevBytesRead=<0>
bytesRead=<0>, totBytesRead=<0>, burst=<0> prevBytesRead=<0>
bytesRead=<0>, totBytesRead=<0>, burst=<0> prevBytesRead=<0>
bytesRead=<3>, totBytesRead=<3>, burst=<1> prevBytesRead=<0>
bytesRead=<32>, totBytesRead=<35>, burst=<2> prevBytesRead=<3>
bytesRead=<30>, totBytesRead=<65>, burst=<3> prevBytesRead=<32>
bytesRead=<32>, totBytesRead=<97>, burst=<4> prevBytesRead=<30>
bytesRead=<31>, totBytesRead=<128>, burst=<5> prevBytesRead=<32>
bytesRead=<32>, totBytesRead=<160>, burst=<6> prevBytesRead=<31>
bytesRead=<31>, totBytesRead=<191>, burst=<7> prevBytesRead=<32>
bytesRead=<32>, totBytesRead=<223>, burst=<8> prevBytesRead=<31>
bytesRead=<32>, totBytesRead=<255>, burst=<9> prevBytesRead=<32>
bytesRead=<31>, totBytesRead=<286>, burst=<10> prevBytesRead=<32>
bytesRead=<33>, totBytesRead=<319>, burst=<11> prevBytesRead=<31>
bytesRead=<32>, totBytesRead=<351>, burst=<12> prevBytesRead=<33>
bytesRead=<32>, totBytesRead=<383>, burst=<13> prevBytesRead=<32>
bytesRead=<32>, totBytesRead=<415>, burst=<14> prevBytesRead=<32>
bytesRead=<6>, totBytesRead=<421>, burst=<15> prevBytesRead=<32>
bytesRead=<0>, totBytesRead=<421>, burst=<15> prevBytesRead=<6>
Read <421>bytes, in <15>bursts, from port at <3142> milli secs since start.
Ok, now I'm getting to the hub of the matter. The only part of the output I'm actually interested in is the line...
Read <421>bytes, in <15>bursts, from port at <3142> milli secs since start
So, all I need to do is comment out this line...
Serial.print("bytesRead=<");Serial.print(bytesRead);Serial.print(">, totBytesRead=<");Serial.print(totBytesRead);Serial.print(">, burst=<");Serial.print(burst);Serial.print("> prevBytesRead=<");Serial.print(prevBytesRead);Serial.println(">");
However, as soon as I remove this line (which does nothing but display to the screen) the results actually get changed.
This is what I get.....
Read <1>bytes, in <1>bursts, from port at <1868> milli secs since start.
Read <18>bytes, in <2>bursts, from port at <1871> milli secs since start.
Read <24>bytes, in <1>bursts, from port at <1878> milli secs since start.
Read <37>bytes, in <1>bursts, from port at <1884> milli secs since start.
Read <35>bytes, in <1>bursts, from port at <1890> milli secs since start.
Read <37>bytes, in <1>bursts, from port at <1896> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1903> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1909> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1915> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1922> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1929> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1935> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1941> milli secs since start.
Read <36>bytes, in <1>bursts, from port at <1947> milli secs since start.
Read <15>bytes, in <1>bursts, from port at <1953> milli secs since start.
Read <1>bytes, in <1>bursts, from port at <2068> milli secs since start.
Read <18>bytes, in <1>bursts, from port at <2071> milli secs since start.
Compared to what I expected....
Read <470>bytes, in <16>bursts, from port at <211> milli secs since start.
Read <470>bytes, in <15>bursts, from port at <408> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <610> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <812> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <1008> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <1210> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <1413> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <1609> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <1812> milli secs since start.
Read <470>bytes, in <16>bursts, from port at <2009> milli secs since start.
On the plus side, I've actually got the results I was after by hand-editing the screen output, but on the downside there's obviously something going wrong that I've missed. How can the inclusion of a series of print() statements effect the actual results? and how can I cure it.
Thanks