UART Communication between the flipper and a GPS Module : Ublox SAM-M8Q
tags: flipper, GPS, Ublox SAM-M8Q, Arduino, UART
This is an example code of UART communication between a GPS Module and the flipper board.
1. Requirements
Version 0.2.0 or higher of the Strataggem nRF52 arduino board package (see updating the bsp ).
2. Schematics and Wiring
On a basic flipper board configuration :
- Xlbee connector has its UART0_TX connected to the MCU UART0_RX
- Xlbee connector has its UART0_RX connected to the MCU UART0_TX
- An Xlbee compatible module is powered when MCU_XLB_EN is high
The GPS module is a Ublox SAM-M8Q .
The sensor is wired on UART0 communication bus so we will use Serial1 instance (if we were using UART1 it would have been Serial2 instance, see flipper arduino bus references ). The basic baudrate of the module is 9600 bps (see datasheet). We start our set up by setting MCU_XLB_EN = XLB_EN in arduino IDE (see gpio arduino name table) .
3. Arduino Code
The module is sending nmea messages on the serial bus, to parse those messages we used the TinyGPSPlus library by mikalhart.
Following code has been modified from this example provided in the library.
- flipper_SAM_M8Q__GPS.ino
#include <TinyGPS++.h> // The TinyGPS++ object TinyGPSPlus gps; void setup() { //enabling XLB_VDD power rail to give power to the module pinMode(XLB_EN, OUTPUT); digitalWrite(XLB_EN, HIGH); delay(1000); Serial.begin(115200); Serial1.begin(9600); } void loop() { // This sketch displays information every time a new sentence is correctly encoded. while (Serial1.available() > 0){ if (gps.encode(Serial1.read())){ displayInfo(); } } if (millis() > 5000 && gps.charsProcessed() < 10) { Serial.println(F("No GPS detected: check wiring.")); while(true); } } void displayInfo() { Serial.print(F("Location: ")); if ( gps.location.isValid() && gps.location.age() < 5000 ) { Serial.print(gps.location.lat(), 6); Serial.print(F(",")); Serial.print(gps.location.lng(), 6); digitalWrite(LED_BLUE,HIGH); delay(200); digitalWrite(LED_BLUE,LOW); } else { Serial.print(F("INVALID")); } Serial.print(F(" Date/Time: ")); if (gps.date.isValid()) { Serial.print(gps.date.month()); Serial.print(F("/")); Serial.print(gps.date.day()); Serial.print(F("/")); Serial.print(gps.date.year()); } else { Serial.print(F("INVALID")); } Serial.print(F(" ")); if (gps.time.isValid()) { if (gps.time.hour() < 10) Serial.print(F("0")); Serial.print(gps.time.hour()); Serial.print(F(":")); if (gps.time.minute() < 10) Serial.print(F("0")); Serial.print(gps.time.minute()); Serial.print(F(":")); if (gps.time.second() < 10) Serial.print(F("0")); Serial.print(gps.time.second()); Serial.print(F(".")); if (gps.time.centisecond() < 10) Serial.print(F("0")); Serial.print(gps.time.centisecond()); } else { Serial.print(F("INVALID")); } Serial.println(); }