Comments (3)
Nope, NOT calling serial.available() is faster as you need to query something that's for sure a call to some hardware.
And it might be possible you keep on running longer when checking again for new available bytes, where in the first code example you only check this once and just assume no more bytes have entered the serial buffer.
from tinygpsplus.
I see you define the baud for GPS, but that is never used again.
static const uint32_t GPSBaud = 9600;
That's fine, because you later initialize two serial ports at 9600 baud.
Serial.begin(9600);
Serial2.begin(9600);
It looks like Serial is your debugging port, based on usage in your code.
I assume then that Serial2 is your GPS serial port.
I only see you reading it inside the function display(), which is called in loop()
void display()
{
gps.encode(Serial2.read());
}
This will not work.
The read() function returns the first byte of incoming serial data available (or -1 if no data is available).
This means you're only grabbing a single byte and trying to display the data.
Instead, put this inside loop()
uint16_t GPSbytesAvailable;
GPSbytesAvailable = Serial2.available();
if(GPSbytesAvailable)
{
while(GPSbytesAvailable--)
{
gps.encode(Serial2.read());
}
}
or
while (Serial2.available() > 0)
{
gps.encode(Serial2.read);
}
The first code is a little faster because it doesn't repeatedly call Serial2.available();
from tinygpsplus.
I was wondering why "GPSbytesAvailable--" is faster?
from tinygpsplus.
Related Issues (20)
- Satellites count is always zero but data exists
- problem with include header in a .h module HOT 2
- What a great gps library HOT 3
- no centisecond with Quectel/Mediatek GPS chips HOT 1
- Anything inside void loop if statement does not work...WHYYYY? HOT 2
- Add calculation mechanism for time-since-epoch (in sec and ms)
- Add doc string for `gps.time.age()` that says the return value is in `ms`
- v1.0.3a is invalid semantic versioning syntax
- Leap seconds and inaccurate time report HOT 4
- Is it work for L89 GPS module quectel? HOT 2
- Support for Beidou & GLONASS
- Multi-Constillation Support for custom Sentences
- Pull requests. HOT 3
- Error parsing NMEA sentence with TinyGPSPlus HOT 1
- link for the documentation down HOT 2
- No Data coming from module HOT 4
- GPS TEL0094 HOT 5
- ATGM336H Not Encoding HOT 4
- UBLOX-MAX-M10 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinygpsplus.