Arduino Nano 33 BLE Sense compatible with NeoGPS library

Is the Arduino Nano 33 BLE Sense compatible with the NeoGPS library?GitHub - SlashDevin/NeoGPS: NMEA and ublox GPS parser for Arduino, configurable to use as few as 10 bytes of RAM

Actually I am using Adafruit GPS module with Arduino Nano 33 BLE Sense but when I have tried to use the NeoGPS library it shows like this image. Which library can be used for Nano 33 with GPS?

image.png

Hello krupalimistry,

In my limited experience with using "incompatible" libraries (I am not a professional mind), it seems that this can be triggered by older libraries that aren't declaring that they are suitable for the more modern architecture even if they work fine. If you compile an incompatible library it tends to say something like:

WARNING: library NeoGPS claims to run on avr, samd, sam, esp8266, arc32, esp32 architecture(s) and may be incompatible with your current board which runs on mbed architecture(s).

Which doesn't mean it won't work, but at the same time, you have to be careful! In the meantime, you could use the Adafruit GPS library that I have used on a Sense before and it works fine.

Hope that helps,
Matt

Hi matt_lee_smith

Thank you for the reply.I get the same warning message which you have mentioned.Actually I want to use the Bluetooth with the GPS. I have used the Adafruit library initially but when I use it with the bluetooth it doesn't gives me any results. May be due to serial communication problem i.e Adafruit uses inbuiit SoftwareSerial. i have also used TinyGPSPlus library which has the same problem. So I want any suggestions that can use Hardware Serial for GPS along with Bluetooth.

Hello krupalimistry,

The Adafruit library should work with Bluetooth, however, this is no SoftwareSerial on the Nano 33's. You can use the Nano Sense's hardware serial Serial1 (not Serial as that is restricted to the USB port) when initialising the GPS:

#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);

This can be found in the Adafruit examples such as GPS_HardwareSerial_Parsing.

Hope that helps,
Matt

Hello Matt,

I tired to run the Adafruit library Hardware Serial Parsing code which works well individually but when I combine it with the ArduinoBLE library example Peripheral->LED. It just shows the GPS location the LED code doesn’t works. Below is the code which I want i.e combining GPS with the Bluetooth. It’s just the combination of two examples Adafruit GPS library example GPS_HArdwareSerial_Parsing and ArduinoBLE library Peripheral->LED.

#include <Adafruit_GPS.h>
#include <ArduinoBLE.h>

// what's the name of the hardware serial port?
#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 to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false
uint32_t timer = millis();



BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
const int ledPin = LED_BUILTIN; // pin to use for the LED



void setup()
{
  Serial.begin(9600);

 // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  
  pinMode(ledPin, OUTPUT);
  BLE.setLocalName("LED");
  BLE.setAdvertisedService(ledService);
  // add the characteristic to the service
  ledService.addCharacteristic(switchCharacteristic);
  // add service
  BLE.addService(ledService);
  // set the initial value for the characeristic:
  switchCharacteristic.writeValue(0);
  // start advertising
  BLE.advertise();

  delay(1000);
}




void loop() 
{  
  char c = GPS.read();

  BLEDevice central = BLE.central();
 
  if (GPS.newNMEAreceived()) {
   // Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }
 
 if (timer > millis()) timer = millis();


//BLE code to connect to bluetooth

  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, HIGH);         // will turn the LED on
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin, LOW);          // will turn the LED off
        }
      }
    }
    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }


//GPS to print latitude and longitude
  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 5000) {
    timer = millis(); // reset the timer
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
    }
  }
  
}

Hello krupalimistry,

The code you have uploaded is missing the BLE.begin() call so the Bluetooth isn’t on ;D !

Also, I quite like using event handlers when I am using the BLE, you can find out more here

I have tweaked your code with an event handler so you can see what it looks like.

#include <Adafruit_GPS.h>
#include <ArduinoBLE.h>

// what's the name of the hardware serial port?
#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 to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO false
uint32_t timer = millis();



BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
const int ledPin = LED_BUILTIN; // pin to use for the LED



void setup()
{
  Serial.begin(9600);

  // 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate

  pinMode(ledPin, OUTPUT);
  
  BLE.begin();
  BLE.setLocalName("LED");
  BLE.setAdvertisedService(ledService);
  // add the characteristic to the service
  ledService.addCharacteristic(switchCharacteristic);
  // add service
  BLE.addService(ledService);
  // set the initial value for the characeristic:
  switchCharacteristic.writeValue(0);
  // start advertising
  BLE.setEventHandler(BLEConnected, ConnectHandle);
  BLE.advertise();
  
  delay(1000);
}

void ConnectHandle(BLEDevice central){
  //BLE code to connect to bluetooth

  // if a central is connected to peripheral:
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, HIGH);         // will turn the LED on
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin, LOW);          // will turn the LED off
        }
      }
    }
    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
}


void loop() {
  char c = GPS.read();

  BLE.poll();
  
  if (GPS.newNMEAreceived()) {
    // Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }

  if (timer > millis()) timer = millis();

  //GPS to print latitude and longitude
  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 5000) {
    timer = millis(); // reset the timer
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
    }
  }
}

Thanks,
Matt

I think your biggest issue is the while loop. This will stop everything else in your sketch while something is connected. The while loop is nice for a simple sketch but not very good for a responsive sketch especially when it grows.

This will require you to restructure your sketch. Make sure you loop can run as often as possible. Try not to wait anywhere. Waiting somewhere for 1ms means you could have executed 64.000 processor instructions.

Using the eventHandler does not help getting around the while loop issue. You can use the handler to set some software flags which you can use in your loop. But you need to use both the connect and disconnect handler.

Let me know when you like some more hints for the changes needed.

Klaus_K is correct, sorry I should have specified that whilst your code will work (I tested it with a Adafruit GPS and a Nano Sense) it currently won't collect GPS data whilst it is dealing with the Bluetooth!