Skip to content

Commit

Permalink
adding gps code to library
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamenm03 committed Feb 14, 2024
1 parent d05a753 commit fb55e6f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
37 changes: 37 additions & 0 deletions examples/read-gps-single-character/read_gps_single_character.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

#include <SoftwareSerial.h>

SoftwareSerial gps(2, 3); // RX, TX

bool isVerbose = true;

void setup() {

// Start the serial monitor:
if (isVerbose) Serial.begin(9600);

// set the data rate for the SoftwareSerial port
gps.begin(9600);
while (!gps) {
delay(2); // wait
}

// set the gps port to listen:
gps.listen();
if (isVerbose) Serial.println("GPS is initialized!");

}

void loop() {
// put your main code here, to run repeatedly:

char t;
if (gps.available()) {
t = gps.read();
if (isVerbose) {
Serial.print(t);
}
}
delay(1);

}
75 changes: 75 additions & 0 deletions examples/read-gps-string/read_gps_string.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@


#include <SoftwareSerial.h>

SoftwareSerial gps(2, 3); // RX, TX

bool isVerbose = true;

const int nChars = 500;
char gps_string[nChars];

// This function clears the GPS data array:
void clear_gps_string() {
for (int i = 0; i < nChars ; i++) gps_string[i] = '\0';
}

// This function reads the GPS data into an array. It does this
// in 3 steps:
// 1. Wait until the buffer is cleared out (in case we arrive in
// the middle of a message.
// 2. Wait until the buffer is available again.
// 3. Read the buffer.

void read_gps() {

char t;

// If we arrive in the middle of a gps_available
// wait for that to go away:
while (gps.available()) {
t = gps.read(); // do nothing
delay(1);
}

// ok, now wait until the gps is available again:
while (!gps.available()) {
delay(1); // do nothing
}

// now read in the GPS data:
int iChar = 0;
while (gps.available()) {
gps_string[iChar] = gps.read();
iChar++;
delay(1);
}

}

// Set up the gps and the Serial port:
void setup() {

// Start the serial monitor:
if (isVerbose) Serial.begin(9600);

// set the data rate for the SoftwareSerial port
gps.begin(9600);
while (!gps) {
delay(2); // wait
}

// set the gps port to listen:
gps.listen();
if (isVerbose) Serial.println("GPS is initialized!");

}

// Read in the GPS and display it.
void loop() {

clear_gps_string();
read_gps();
if (isVerbose) Serial.println(gps_string);

}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ENGR100-950",
"version": "1.1.2",
"version": "1.1.3",
"keywords": "Arduino,library",
"description": "UMich ENGR 100-950 Library",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ENGR100-950
version=1.1.2
version=1.1.3
author=Benjamen Miller <[email protected]>
maintainer=Benjamen Miller <[email protected]>
sentence=UMich ENGR 100-950 Library
Expand Down

0 comments on commit fb55e6f

Please sign in to comment.