Tutorial 2
How to Use UART1
Some users would like to use UART1 or Serial1 while compiling with GNSS library. This tutorial shows how to do this. It is assumed that user is familiar with the concepts in this “Hello World” tutorial.
To turn off NMEA output sentence, set message interval to 0 as below. GNSS.cpp is under C:\Users\USER\AppData\Roaming\Arduino15\packages\navspark\hardware\navspark\1.0.1\cores\arduino
--------------------------------------------------------
uint8_t led = 13;
void setup() {
GnssConf.init();
// put your setup code here, to run once:
pinMode(led, OUTPUT);
//Serial1.config(STGNSS_UART_8BITS_WORD_LENGTH, STGNSS_UART_1STOP_BITS, STGNSS_UART_NOPARITY);
//Serial1.begin();
}
void loop()
{
// put your main code here, to run repeatedly:
}
void task_called_after_GNSS_update(void)
{
static uint8_t val = HIGH;
char buf[32];
int len;
if (val == HIGH) {
digitalWrite(led, HIGH);
len = sprintf(buf, "Hello world (GPIO%02d output 1)\r\n", led);
gnss_uart_putline(0, (U08*) buf, len);
val = LOW;
}
else if (val == LOW) {
digitalWrite(led, LOW);
len = sprintf(buf, "Hello world (GPIO%02d output 0)\r\n", led);
gnss_uart_putline(0, (U08*) buf, len);
val = HIGH;
}
}
--------------------------------------------------------
Copy the above program to Arduino IDE. What’s different from program in “Hello World” tutorial:
No call to function Serial1.config(), Serial1.begin(), and Serial1.print()
gnss_uart_putline() is called instead.
If compiling and upload to NavSpark, will show as below in the Message window.
Since we compiled with GNSS library, all GNSS and firmware update related functions are still intact, just didn't print out NMEA sentence. So when uploading below code or your code to restore, can simply upload directly while it’s running from Flash mode, no need to switch to ROM mode to upload as in “Hello World” tutorial that used non-GNSS library.
-------------------------------------------------------
void setup() {
// put your setup code here, to run once
GnssConf.init();
}
void loop() {
// put your main code here, to run repeatedly:
}
-------------------------------------------------------
Before compiling above code, remember to restore NMEA output interval in GNSS.cpp, that we changed to 0 before, to values other than 0; otherwise it’ll not output anything and will behave like a hanged program.