simplify Flora & Featherwing to just have HwSerial test code

This commit is contained in:
ladyada 2016-07-11 23:33:09 -04:00
parent b2f502887a
commit 3fbbc52add
3 changed files with 69 additions and 44 deletions

View File

@ -0,0 +1,43 @@
// Test code for Ultimate GPS Using Hardware Serial
// (e.g. GPS for Leonardo, Flora or FeatherWing)
//
// This code shows how to test a passthru between USB and hardware serial
//
// Tested and works great with the Adafruit GPS FeatherWing
// ------> https://www.adafruit.com/products/3133
// or Flora GPS
// ------> https://www.adafruit.com/products/1059
// but also works with the shield, breakout
// ------> https://www.adafruit.com/products/1272
// ------> https://www.adafruit.com/products/746
//
// Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada
// what's the name of the hardware serial port?
#define GPSSerial Serial1
void setup() {
// wait for hardware serial to appear
while (!Serial);
// make this baud rate fast enough to we aren't waiting on it
Serial.begin(115200);
// 9600 baud is the default rate for the Ultimate GPS
GPSSerial.begin(9600);
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
GPSSerial.write(c);
}
if (GPSSerial.available()) {
char c = GPSSerial.read();
Serial.write(c);
}
}

View File

@ -1,35 +1,38 @@
// Test code for Ultimate GPS Using Hardware Serial ( // Test code for Ultimate GPS Using Hardware Serial (e.g. GPS Flora or FeatherWing)
// e.g. Adafruit Flora GPS modules or GPS FeatherWing
// //
// This code shows how to listen to the GPS module in an interrupt // This code shows how to listen to the GPS module via polling. Best used with
// which allows the program to have more 'freedom' - just parse // Feathers or Flora where you have hardware Serial and no interrupt
// when a new NMEA sentence is available! Then access data when
// desired.
// //
// Tested and works great with the Adafruit Flora GPS module // Tested and works great with the Adafruit GPS FeatherWing
// ------> http://adafruit.com/products/1059 // ------> https://www.adafruit.com/products/3133
// ------> http://adafruit.com/products/3133 // or Flora GPS
// ------> https://www.adafruit.com/products/1059
// but also works with the shield, breakout
// ------> https://www.adafruit.com/products/1272
// ------> https://www.adafruit.com/products/746
//
// Pick one up today at the Adafruit electronics shop // Pick one up today at the Adafruit electronics shop
// and help support open source hardware & software! -ada // and help support open source hardware & software! -ada
#include <Adafruit_GPS.h> #include <Adafruit_GPS.h>
#ifdef __AVR__
#include <SoftwareSerial.h>
#endif
// Connect to the GPS on the Serial1 hardware port // what's the name of the hardware serial port?
Adafruit_GPS GPS(&Serial1); #define GPSSerial Serial1
// Connect to the GPS on the hardware port
Adafruit_GPS GPS(&GPSSerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console // Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences // Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false #define GPSECHO false
// this keeps track of whether we're using the interrupt uint32_t timer = millis();
// off by default!
boolean usingInterrupt = false;
void setup() void setup()
{ {
//while (!Serial); // uncomment to have the sketch wait until Serial is ready
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out // also spit it out
Serial.begin(115200); Serial.begin(115200);
@ -52,13 +55,11 @@ void setup()
GPS.sendCommand(PGCMD_ANTENNA); GPS.sendCommand(PGCMD_ANTENNA);
delay(1000); delay(1000);
// Ask for firmware version // Ask for firmware version
Serial1.println(PMTK_Q_RELEASE); GPSSerial.println(PMTK_Q_RELEASE);
} }
uint32_t timer = millis();
void loop() // run over and over again void loop() // run over and over again
{ {
// read data from the GPS in the 'main loop' // read data from the GPS in the 'main loop'
@ -103,4 +104,4 @@ void loop() // run over and over again
Serial.print("Satellites: "); Serial.println((int)GPS.satellites); Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
} }
} }
} }

View File

@ -1,19 +0,0 @@
// test a passthru between USB and hardware serial
void setup() {
while (!Serial);
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
Serial1.write(c);
}
if (Serial1.available()) {
char c = Serial1.read();
Serial.write(c);
}
}