GPS not working when integrated

nithyaajayan

New member
The project I'm working on involves integrating 3 sensors: GPS, BME, MQ135 to teensy 4.1 and running them simultaneously. I've tested each of these sensors seperately and they work just fine. But on integrating, BME and MQ135 works perfectly, while GPS gives all null values. I'm using GNSS L89 for my GPS. The connections shouldn't be a problem, given they've worked well when run individually on the same pins I've used for integration.
What could be the problem and how do I resolve it?

C:
#include <Wire.h>
#include "Adafruit_BME680.h"
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

#define SEALEVELPRESSURE_HPA (1013.25)
#define rxGPS 0
#define txGPS 1

Adafruit_BME680 bme;
const int mq2Pin = A0; // MQ-2 for smoke and flammable gases
const int mq7Pin = A1; // MQ-7 for carbon monoxide
const int mq135Pin = A2; // MQ-135 for air quality (various gases)

long lat, lon;
SoftwareSerial gpsSerial(rxGPS, txGPS);
TinyGPSPlus gps;

void setup() {
  Serial.begin(9600);
  gpsSerial.begin(9600); // connect gps sensor
  while (!Serial);
  Serial.println(F("BME680 test"));

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }

  // Set up oversampling and filter initialization
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
}

void loop() {
  if (!bme.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }

  float temperature = bme.temperature;
  float pressure = bme.pressure / 100.0;
  float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  int mq2Value = analogRead(mq2Pin); // Read MQ-2 sensor value
  int mq7Value = analogRead(mq7Pin); // Read MQ-7 sensor value
  int mq135Value = analogRead(mq135Pin); // Read MQ-135 sensor value

  while (gpsSerial.available())     // check for gps data
  {
    if (gps.encode(gpsSerial.read()))   // encode gps data
    {
      Serial.print("Number of satellites: ");
      Serial.println(gps.satellites.value());

      Serial.print("Latitude: ");
      Serial.println(gps.location.lat(), 6);

      Serial.print("Longitude: ");
      Serial.println(gps.location.lng(), 6);

      Serial.print("Altitude: ");
      Serial.println(gps.altitude.meters());

      Serial.print("Speed: ");
      Serial.println(gps.speed.mps());
 
      Serial.print("Date: ");
      Serial.print(gps.date.day()); Serial.print("/");
      Serial.print(gps.date.month()); Serial.print("/");
      Serial.println(gps.date.year());
 
      Serial.print("Hour: ");
      Serial.print(gps.time.hour()); Serial.print(":");
      Serial.print(gps.time.minute()); Serial.print(":");
      Serial.println(gps.time.second());

      Serial.print("Temperature: ");
      Serial.print(temperature);
      Serial.println(" *C");

      Serial.print("Pressure: ");
      Serial.print(pressure);
      Serial.println(" hPa");

      Serial.print("Altitude: ");
      Serial.print(altitude);
      Serial.println(" m");

      Serial.print("Smoke: ");
      Serial.print(mq2Value);
      Serial.println(" ppm");

      Serial.print("Carbon Monoxide: ");
      Serial.print(mq7Value);
      Serial.println(" ppm");

      Serial.print("Air Quality: ");
      Serial.print(mq135Value);
      Serial.println(" ppm");

      Serial.println();
      delay(2000);
    }
  }
}
 
Had a look at your code but nothing obviously wrong stood out.

What if you integrate only 2 sensors at a time [BME680 & MQ135 or BME680 & GPS or MQ135 & GPS]? Any combination that works?
I guess it is a matter of commenting out parts of your code above until something works.

By the way: do you use a sensor module which has 3 gas sensors integrated? I see in your code MQ-2, MQ-7 and MQ-135.
Another thought: did you power all sensors, including GPS, from the Teensy 3V3 pin? Did you estimate the power consumption of all sensors including GPS?

Paul
 
In the above code, if you comment out everything except for the GPS, GPS works? Or is your GPS working in a separate program? Reason I ask is the delay(2000) may be the issue. The GPS example code uses a SmartDelay function where that function continues to read the GPS. Maybe mimic the example?
 
Had a look at your code but nothing obviously wrong stood out.

What if you integrate only 2 sensors at a time [BME680 & MQ135 or BME680 & GPS or MQ135 & GPS]? Any combination that works?
I guess it is a matter of commenting out parts of your code above until something works.

By the way: do you use a sensor module which has 3 gas sensors integrated? I see in your code MQ-2, MQ-7 and MQ-135.
Another thought: did you power all sensors, including GPS, from the Teensy 3V3 pin? Did you estimate the power consumption of all sensors including GPS?

Paul
I did integrate just BME and GPS, only for it to just give BME values. I modified the code by removing the delay function and adding this code snippet.
C:
while (millis() - startMillis < 1000);
This made it work, as well as all the three sensors integrated. If this was the issue, how did this code fix it?
I say "if" because I am not sure if the initial problem was that GPS was not receiving signals properly (although I did test it outdoors), but I'm leaving room for that error.
Also yes, I'm measuring MQ-2, MQ-7, MQ-135 using only one MQ-135 sensor, it has given the right values too
 
In the above code, if you comment out everything except for the GPS, GPS works? Or is your GPS working in a separate program? Reason I ask is the delay(2000) may be the issue. The GPS example code uses a SmartDelay function where that function continues to read the GPS. Maybe mimic the example?

The issue is resolved now, but yes, the GPS had worked alone. I removed the delay function and added this code, which seemed to make it work.
C:
while (millis() - startMillis < 1000);
 
Back
Top