GPS parsing

I have an issue with parsing the GPS data. It works great with the debug version I have but if I implement it into the main code it doesn’t:

Arduino Mega, with multiple sensors:

Main code:

//Maincode

//Libraries
#include <Wire.h>
#include "Adafruit_MLX90393.h"
#include "SparkFunCCS811.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include "TFMini.h"
#include <Adafruit_GPS.h>
#include "DFRobot_SHT20.h"

//Define
#define CCS811_ADDR 0x5B
#define BNO055_SAMPLERATE_DELAY_MS (100)
#define SLAVE_BROADCAST_ADDR 0x00  // Default address
#define SLAVE_ADDR 0xAF       // Slave address of Ultrasonic Sensor (0xA0-0xAF)
#define TCAADDR 0x70 // Slave address of Multiplexer

//Private Variables
uint8_t distance_H = 0; // High Byte of Lidardistance
uint8_t distance_L = 0; // Low Byte of Lidardistance
uint16_t distance = 0; // Lidardistance
int Co2read; // CO2 value
float magx, magy, magz; // Magneticfield values in vector x,y,z
float yaw; // Yaw value
float pitch;
float roll;
float accx;
float accy;
float accz;
float humd1;
float temp1 ;
float humd2;
float temp2 ;
uint16_t dist;
uint16_t strength;
int hours;
int minutes;
int secondes;
int millisec;
int days;
int months;
int years;
int fix;
float latitude;
float longitude;
int speedms;
int alt;

const int ledPin =  7;      // the number of the LED pin
int buttonState = 0;         // variable for reading the Blynkbutton status

// Sensor preparation
Adafruit_MLX90393 Mag = Adafruit_MLX90393();
Adafruit_BNO055 bno = Adafruit_BNO055(55);
CCS811 Co2(CCS811_ADDR);
TFMini tfmini;
DFRobot_SHT20 sht20;
Adafruit_GPS GPS(&Serial1);


// Initialise Multiplexer for the two temperature sensors
void tcaselect(uint8_t i) {
if (i > 7) return;

Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}

void setup() {
delay(5000);
//Starting up all availeble Serials
Serial.begin(115200); //For debugging
Serial2.begin(115200); //Lidar TFmini
Serial3.begin(9600); //XBee
Serial1.begin(9600); //GPS

// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);

//Set up GPS
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
GPS.sendCommand(PGCMD_ANTENNA);

//Inialise I2C Harwar
Wire.begin();

//Broadcast new slave address to Ultrasonic Sensor
Wire.beginTransmission(SLAVE_BROADCAST_ADDR); // transmit to device SLAVE_BROADCAST_ADDR
Wire.write(SLAVE_ADDR);                       // Change the SLAVE_ADDR
Wire.endTransmission();                       // stop transmitting

// Initialise Co2 sensor
CCS811Core::status returnCode = Co2.begin();
if (returnCode != CCS811Core::SENSOR_SUCCESS)
{
//Serial.println(".begin() returned with an error."); //for debugging
while (1); //Hang if there was a problem.
}

//Initialise magneticfield sensor
if (Mag.begin())
{
//Serial.println("Found a MLX90393 sensor"); //for debugging
}
else
{
//Serial.println("No sensor found ... check your wiring?"); //for debugging
while (1);
}

// Initialise the sensor Acc
if (!bno.begin())
{
//Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); //for debugging
while (1);
}

bno.setExtCrystalUse(true); // Use external crystal for better accuracy

// Initialise TFmini Lidar
tfmini.begin(&Serial2);


// Initialise the 1st temperature sensor
tcaselect(0);
sht20.initSHT20();

// Initialise the 2nd temperature sensor
tcaselect(1);
sht20.initSHT20();

}


uint32_t timer = millis();

//Main Loop

void loop() {

//GPS

char c = GPS.read();

// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {

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 millis() or timer wraps around, we'll just reset it
if (timer > millis())  timer = millis();

// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 1000) {
timer = millis(); // reset the timer
Serial.print("\nTime: ");
Serial.print(GPS.hour, DEC); Serial.print(':');
Serial.print(GPS.minute, DEC); Serial.print(':');
Serial.print(GPS.seconds, DEC); Serial.print('.');
Serial.println(GPS.milliseconds);
Serial.print("Date: ");
Serial.print(GPS.day, DEC); Serial.print('/');
Serial.print(GPS.month, DEC); Serial.print("/20");
Serial.println(GPS.year, DEC);
Serial.print("Fix: "); Serial.print((int)GPS.fix);
Serial.print(" quality: "); Serial.println((int)GPS.fixquality); 


hours = (GPS.hour, DEC);
minutes = (GPS.minute, DEC);
secondes = (GPS.seconds, DEC);
millisec = GPS.milliseconds

days = (GPS.day, DEC);
months = (GPS.month, DEC);
years = (GPS.year, DEC);
fix = (int)GPS.fix;

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);
Serial.print("Location (in degrees, works with Google Maps): ");
Serial.print(GPS.latitudeDegrees, 4);
Serial.print(", "); 
Serial.println(GPS.longitudeDegrees, 4);

Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
}
latitude = GPS.latitudeDegrees;
longitude = GPS.longitudeDegrees;
speedms = 0.51444 * GPS.speed;
alt = GPS.altitude;
}

// Get ButtonStatus 
if (Serial3.available()) {

digitalWrite(ledPin, Serial.read());
}


//CO2 Sensor
if (Co2.dataAvailable())
{

Co2.readAlgorithmResults();
Co2read = Co2.getCO2();

Serial.print("CO2[");
    //Returns calculated CO2 reading
    Serial.print(Co2.getCO2());
    Serial.print("] tVOC[");
    //Returns calculated TVOC reading
    Serial.print(Co2.getTVOC());
    Serial.println("]");

}

//Magneticfield sensor

if (Mag.readData(&magx, &magy, &magz)) {
Serial.print("X: "); Serial.print(magx, 4); Serial.println(" uT");
Serial.print("Y: "); Serial.print(magy, 4); Serial.println(" uT");
Serial.print("Z: "); Serial.print(magz, 4); Serial.println(" uT");

} else {
Serial.println("Unable to read XYZ data from the sensor.");
}

// BNO055 9-Axis sensor
sensors_event_t event;
bno.getEvent(&event);

Serial.print(F("Orientation: "));
Serial.print((float)event.orientation.x);
Serial.print(F(" "));
Serial.print((float)event.orientation.y);
Serial.print(F(" "));
Serial.print((float)event.orientation.z);
Serial.println(F(""));

yaw = event.orientation.x;
pitch = event.orientation.y;
roll = event.orientation.z;
accx = event.acceleration.x;
accy = event.acceleration.y;
accz = event.acceleration.z;


//Ultrasonic Sensor
Wire.beginTransmission(SLAVE_ADDR); // transmit to device #8
Wire.write(1);              // measure command: 0x01
Wire.endTransmission();    // stop transmitting

Wire.requestFrom(SLAVE_ADDR, 2);    // request 6 bytes from slave device #8
while (Wire.available()) { // slave may send less than requested
distance_H = Wire.read(); // receive a byte as character
distance_L = Wire.read();
distance = (uint16_t)distance_H << 8;
distance = distance | distance_L;
Serial.print(distance);         // print the character
Serial.println("mm");
}


//Temperature
tcaselect(0);
humd1 = sht20.readHumidity();                  // Read Humidity
temp1 = sht20.readTemperature();               // Read Temperature

Serial.println("Sensor1");
Serial.print(" Temperature1:");
Serial.print(temp1, 1);
Serial.print("C");
Serial.print(" Humidity1:");
Serial.print(humd1, 1);
Serial.print("%");
Serial.println();
Serial.println();

tcaselect(1);
humd2 = sht20.readHumidity();                  // Read Humidity
temp2 = sht20.readTemperature();               // Read Temperature
//    Serial.print("Time:");
//    Serial.print(millis());
Serial.println("Sensor2");
Serial.print(" Temperature2:");
Serial.print(temp2, 1);
Serial.print("C");
Serial.print(" Humidity2:");
Serial.print(humd2, 1);
Serial.print("%");
Serial.println();
Serial.println();

Wire.beginTransmission(TCAADDR);
Wire.write(0);  // no channel selected
Wire.endTransmission();

}

the results are as follows:

GPSparsing:

Time: 15:15:21.0
Date: 21/6/2019
Fix: 1 quality: 2
Location: good/good (you won’t get my coordinates :wink: )
Location: good/good
Speed (knots): 0.54
Angle: 182.94
Altitude: 732.40
Satellites: 5

Main:
Time: 0:0:0.0
Date: 0/0/200
Fix: 0 quality: 0
X: 250.6770 uT
Y: 305.4170 uT
Z: 707.0700 uT
Orientation: 0.00 0.00 0.00
205mm
Sensor1
Temperature1:26.0C Humidity1:49.3%
Sensor2
Temperature2:26.7C Humidity2:48.2%

I don’t change the setup, everything stays the same so why doesn’t it work?

Have you eliminated the other libraries and devices as being the cause of the issue? Such as, comment out the other libraries and function calls from running. If not gps problem then add in one or two other libraries and functions. I'd even go as far as pulling the power pins of the commented out devices to see if the issue is software or hardware conflicts. One of your devices or software libraries may not play well with others.

And, please, after 15 posts, when posting your code, use code tags.

Please edit your post to add code tags ("</>" button).

jremington:
Please edit your post to add code tags ("</>" button).

Sorry for that, I hope it’s better now.

Idahowalker:
Have you eliminated the other libraries and devices as being the cause of the issue? Such as, comment out the other libraries and function calls from running. If not gps problem then add in one or two other libraries and functions. I’d even go as far as pulling the power pins of the commented out devices to see if the issue is software or hardware conflicts. One of your devices or software libraries may not play well with others.

And, please, after 15 posts, when posting your code, use code tags.

I’ll get right on it, thank you

char c = GPS.read();Debug tip: echo the characters received, so you can see what is happening.

I have the feeling that it's about the timing, cause when I start adding more than two sensors it stops working it doesn't matter what kind of sensor...

 // if millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 1000) {
    timer = millis(); // reset the timer

So can I see your code, how it has been commented out and other such items. I know it is a pain but if you make code changes, it’s better to post those code changes so that others may use the new changes as part of troubleshooting. The above code snippet is not useful.

//Maincode

//Libraries
#include <Wire.h>
#include "Adafruit_MLX90393.h"
#include "SparkFunCCS811.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include "TFMini.h"
#include <Adafruit_GPS.h>
#include "DFRobot_SHT20.h"

//Define
#define CCS811_ADDR 0x5B
#define BNO055_SAMPLERATE_DELAY_MS (100)
#define SLAVE_BROADCAST_ADDR 0x00  // Default address
#define SLAVE_ADDR 0xAF       // Slave address of Ultrasonic Sensor (0xA0-0xAF)
#define TCAADDR 0x70 // Slave address of Multiplexer

//Private Variables
uint8_t distance_H = 0; // High Byte of Lidardistance
uint8_t distance_L = 0; // Low Byte of Lidardistance
uint16_t distance = 0; // Lidardistance
int Co2read; // CO2 value
float magx, magy, magz; // Magneticfield values in vector x,y,z
float yaw; // Yaw value
float pitch;
float roll;
float accx;
float accy;
float accz;
float humd1;
float temp1 ;
float humd2;
float temp2 ;
uint16_t dist;
uint16_t strength;
int hours;
int minutes;
int secondes;
int millisec;
int days;
int months;
int years;
int fix;
float latitude;
float longitude;
int speedms;
int alt;

const int ledPin =  7;      // the number of the LED pin
int buttonState = 0;         // variable for reading the Blynkbutton status

// Sensor preparation
Adafruit_MLX90393 Mag = Adafruit_MLX90393();
Adafruit_BNO055 bno = Adafruit_BNO055(55);
CCS811 Co2(CCS811_ADDR);
TFMini tfmini;
DFRobot_SHT20 sht20;
Adafruit_GPS GPS(&Serial1);



// Initialise Multiplexer for the two temperature sensors
void tcaselect(uint8_t i) {
  if (i > 7) return;

  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
}


void setup() {

  //Starting up all availeble Serials
  Serial.begin(9600); //For debugging
  Serial1.begin(9600); //GPS
  Serial2.begin(115200); //Lidar TFmini
  Serial3.begin(9600); //XBee



  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);



  //Set up GPS
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  GPS.sendCommand(PGCMD_ANTENNA);

  //Inialise I2C Harwar
  Wire.begin();

  //Broadcast new slave address to Ultrasonic Sensor
  Wire.beginTransmission(SLAVE_BROADCAST_ADDR); // transmit to device SLAVE_BROADCAST_ADDR
  Wire.write(SLAVE_ADDR);                       // Change the SLAVE_ADDR
  Wire.endTransmission();                       // stop transmitting

  // Initialise Co2 sensor
  CCS811Core::status returnCode = Co2.begin();
  if (returnCode != CCS811Core::SENSOR_SUCCESS)
  {
    //Serial.println(".begin() returned with an error."); //for debugging
    while (1); //Hang if there was a problem.
  }

  //Initialise magneticfield sensor
  if (Mag.begin())
  {
    //Serial.println("Found a MLX90393 sensor"); //for debugging
  }
  else
  {
    //Serial.println("No sensor found ... check your wiring?"); //for debugging
    while (1);
  }

  // Initialise the sensor Acc
  if (!bno.begin())
  {
    //Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); //for debugging
    while (1);
  }
  
  bno.setExtCrystalUse(true); // Use external crystal for better accuracy

  // Initialise TFmini Lidar
//  tfmini.begin(&Serial2);


  // Initialise the 1st temperature sensor
  tcaselect(0);
  sht20.initSHT20();
//
//  // Initialise the 2nd temperature sensor
  tcaselect(1);
  sht20.initSHT20();

}


uint32_t timer = millis();
//Main Loop

void loop() {

//GPS

  char c = GPS.read();

  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {


    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 millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 1000) {
    timer = millis(); // reset the timer
    Serial.print("\nTime: ");
    Serial.print(GPS.hour+2, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    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);
      Serial.print("Location (in degrees, works with Google Maps): ");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", "); 
      Serial.println(GPS.longitudeDegrees, 4);
      
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
    }

    }
  
// Get ButtonStatus 
  if (Serial3.available()) {

    digitalWrite(ledPin, Serial.read());
  }


  //CO2 Sensor
  if (Co2.dataAvailable())
  {

    Co2.readAlgorithmResults();
    Co2read = Co2.getCO2();

    Serial.print("CO2[");
    //Returns calculated CO2 reading
    Serial.print(Co2.getCO2());
    Serial.print("] tVOC[");
    //Returns calculated TVOC reading
    Serial.print(Co2.getTVOC());
    Serial.println("]");
    //    //Simply the time since program start
    //    Serial.print(millis());
    //    Serial.print("]");
    //    Serial.println();

  }

  //Magneticfield sensor

//  if (Mag.readData(&magx, &magy, &magz)) {
//    Serial.print("X: "); Serial.print(magx, 4); Serial.println(" uT");
//    Serial.print("Y: "); Serial.print(magy, 4); Serial.println(" uT");
//    Serial.print("Z: "); Serial.print(magz, 4); Serial.println(" uT");
//
//  } else {
//    Serial.println("Unable to read XYZ data from the sensor.");
//  }


  // BNO055 9-Axis sensor
//  sensors_event_t event;
//  bno.getEvent(&event);

//  Serial.print(F("Orientation: "));
//  Serial.print((float)event.orientation.x);
//  Serial.print(F(" "));
//  Serial.print((float)event.orientation.y);
//  Serial.print(F(" "));
//  Serial.print((float)event.orientation.z);
//  Serial.println(F(""));
//
//  delay(100);

//  yaw = event.orientation.x;
//  pitch = event.orientation.y;
//  roll = event.orientation.z;
//  accx = event.acceleration.x;
//  accy = event.acceleration.y;
//  accz = event.acceleration.z;


  //Ultrasonic Sensor
//  Wire.beginTransmission(SLAVE_ADDR); // transmit to device #8
//  Wire.write(1);              // measure command: 0x01
//  Wire.endTransmission();    // stop transmitting
//
//  Wire.requestFrom(SLAVE_ADDR, 2);    // request 6 bytes from slave device #8
//  while (Wire.available()) { // slave may send less than requested
//    distance_H = Wire.read(); // receive a byte as character
//    distance_L = Wire.read();
//    distance = (uint16_t)distance_H << 8;
//    distance = distance | distance_L;
//    Serial.print(distance);         // print the character
//    Serial.println("mm");
//  }

  //TF Mini distance measurement
  //  dist = tfmini.getDistance();
  //  strength = tfmini.getRecentSignalStrength();

  // Display the measurement
  //  Serial.print(dist);
  //  Serial.print(" cm      sigstr: ");
  //  Serial.println(strength);


  //Temperature
//  tcaselect(0);
//  humd1 = sht20.readHumidity();                  // Read Humidity
//  temp1 = sht20.readTemperature();               // Read Temperature

//  Serial.println("Sensor1");
//  Serial.print(" Temperature1:");
//  Serial.print(temp1, 1);
//  Serial.print("C");
//  Serial.print(" Humidity1:");
//  Serial.print(humd1, 1);
//  Serial.print("%");
//  Serial.println();
//  Serial.println();
//
//  tcaselect(1);
//  humd2 = sht20.readHumidity();                  // Read Humidity
//  temp2 = sht20.readTemperature();               // Read Temperature

//  Serial.println("Sensor2");
//  Serial.print(" Temperature2:");
//  Serial.print(temp2, 1);
//  Serial.print("C");
//  Serial.print(" Humidity2:");
//  Serial.print(humd2, 1);
//  Serial.print("%");
//  Serial.println();
//  Serial.println();

}

If I add any other sensor it’s not working anymore

it's not working anymore

Completely useless phrase.

If you want help, take the time to read and follow the directions in the "How to use this forum" post.

If I add the Magneticfield Sensor I get this in the Serialmonitor at 9600

Time: 2:0:0.0 Date: 0/0/200 Fix: 0 quality: 0 X: 216.8670 uT Y: 265.8110 uT Z: 709.1280 uT X: 220.0870 uT Y: 272.8950 uT Z: 718.8300 uT ......

I tried to add a delay after the Magneticfield Sensor but it doesn't help the results for the GPS data is the same

In your issue you state that you have issue with more than 2 sensors but your code only has 2 sensors enabled. Could you restate your issue?

I've copied your code into a new sketch and I am looking for

If I add any other sensor it's not working anymore

, I'll probably not find any because I have no idea what that means in relation to your code.

Using 3 sensors. Could you, please, comment out all the code from the other sensors, including the includes for the libraries, repost the commented out code and the results of more then it does not work. Such as write what you expected and what happened.

With that library, from what I remember, you need a ISR to properly process the NEMA data. That you are using a MEGA, you might want to switch to tinygps++ library for NEMA parsing.

Idahowalker:
In your issue you state that you have issue with more than 2 sensors but your code only has 2 sensors enabled. Could you restate your issue?

The problem is not the physically connection or initiating the sensor, it’s when I try to get the readings. In other words when I accsess more than one sensor on the I2C bus. But that what I don’t understand. The GPS us using UART. All the I2C Sensors are working fine, I get all the readings I want. I’ll reposte the code in the next post.

This is what I get when I read all the sensors:

Time: 0:0:0.0
Date: 0/0/200
Fix: 0 quality: 0
X: 250.6770 uT
Y: 305.4170 uT
Z: 707.0700 uT
Orientation: 0.00 0.00 0.00
205mm
Sensor1
Temperature1:26.0C Humidity1:49.3%
Sensor2
Temperature2:26.7C Humidity2:48.2%

This is what I would like, or say expect:

Time: 15:15:21.0
Date: 21/6/2019
Fix: 1 quality: 2
Location: good/good (you won’t get my coordinates :wink: )
Location: good/good
Speed (knots): 0.54
Angle: 182.94
Altitude: 732.40
Satellites: 5
X: 250.6770 uT
Y: 305.4170 uT
Z: 707.0700 uT
Orientation: 0.00 0.00 0.00
205mm
Sensor1
Temperature1:26.0C Humidity1:49.3%
Sensor2
Temperature2:26.7C Humidity2:48.2%

Idahowalker:
With that library, from what I remember, you need a ISR to properly process the NEMA data. That you are using a MEGA, you might want to switch to tinygps++ library for NEMA parsing.

I’ll check on that.

//Maincode

//Libraries
#include <Wire.h>
//#include "Adafruit_MLX90393.h"
#include "SparkFunCCS811.h"
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BNO055.h>
//#include <utility/imumaths.h>
//#include "TFMini.h"
#include <Adafruit_GPS.h>
//#include "DFRobot_SHT20.h"

//Define
#define CCS811_ADDR 0x5B
//#define BNO055_SAMPLERATE_DELAY_MS (100)
//#define SLAVE_BROADCAST_ADDR 0x00  // Default address
//#define SLAVE_ADDR 0xAF       // Slave address of Ultrasonic Sensor (0xA0-0xAF)
//#define TCAADDR 0x70 // Slave address of Multiplexer

//Private Variables
//uint8_t distance_H = 0; // High Byte of Lidardistance
//uint8_t distance_L = 0; // Low Byte of Lidardistance
//uint16_t distance = 0; // Lidardistance
int Co2read; // CO2 value


//const int ledPin =  7;      // the number of the LED pin
//int buttonState = 0;         // variable for reading the Blynkbutton status

// Sensor preparation
//Adafruit_MLX90393 Mag = Adafruit_MLX90393();
//Adafruit_BNO055 bno = Adafruit_BNO055(55);
CCS811 Co2(CCS811_ADDR);
//TFMini tfmini;
//DFRobot_SHT20 sht20;
Adafruit_GPS GPS(&Serial1);


// Initialise Multiplexer for the two temperature sensors
//void tcaselect(uint8_t i) {
//  if (i > 7) return;
//
//  Wire.beginTransmission(TCAADDR);
//  Wire.write(1 << i);
//  Wire.endTransmission();
//}


void setup() {

  //Starting up all availeble Serials
  Serial.begin(9600); //For debugging
  Serial1.begin(9600); //GPS
//  Serial2.begin(115200); //Lidar TFmini
//  Serial3.begin(9600); //XBee


  // initialize the LED pin as an output:
//  pinMode(ledPin, OUTPUT);


  //Set up GPS
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);   // 1 Hz update rate
  GPS.sendCommand(PGCMD_ANTENNA);

  //Inialise I2C Harwar
  Wire.begin();

  //Broadcast new slave address to Ultrasonic Sensor
//  Wire.beginTransmission(SLAVE_BROADCAST_ADDR); // transmit to device SLAVE_BROADCAST_ADDR
//  Wire.write(SLAVE_ADDR);                       // Change the SLAVE_ADDR
//  Wire.endTransmission();                       // stop transmitting

  // Initialise Co2 sensor
  CCS811Core::status returnCode = Co2.begin();
  if (returnCode != CCS811Core::SENSOR_SUCCESS)
  {
    //Serial.println(".begin() returned with an error."); //for debugging
    while (1); //Hang if there was a problem.
  }

  //Initialise magneticfield sensor
//  if (Mag.begin())
//  {
//    //Serial.println("Found a MLX90393 sensor"); //for debugging
//  }
//  else
//  {
//    //Serial.println("No sensor found ... check your wiring?"); //for debugging
//    while (1);
//  }
//
//  // Initialise the sensor Acc
//  if (!bno.begin())
//  {
//    //Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); //for debugging
//    while (1);
//  }
  
//  bno.setExtCrystalUse(true); // Use external crystal for better accuracy

  // Initialise TFmini Lidar
//  tfmini.begin(&Serial2);


  // Initialise the 1st temperature sensor
//  tcaselect(0);
//  sht20.initSHT20();
////
////  // Initialise the 2nd temperature sensor
//  tcaselect(1);
//  sht20.initSHT20();
}

uint32_t timer = millis();

//Main Loop

void loop() {

//GPS

  char c = GPS.read();
  Serial.print("GPS.read():");
  Serial.println(GPS.read());

  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {


    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 millis() or timer wraps around, we'll just reset it
  if (timer > millis())  timer = millis();

  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 3000) {
    timer = millis(); // reset the timer
    Serial.print("\nTime: ");
    Serial.print(GPS.hour+2, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    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);
      Serial.print("Location (in degrees, works with Google Maps): ");
      Serial.print(GPS.latitudeDegrees, 4);
      Serial.print(", "); 
      Serial.println(GPS.longitudeDegrees, 4);
      
      Serial.print("Speed (knots): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude: "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
      }

    }
  
//// Get ButtonStatus 
//  if (Serial3.available()) {
//
//    digitalWrite(ledPin, Serial.read());
//  }


  //CO2 Sensor
  if (Co2.dataAvailable())
  {

    Co2.readAlgorithmResults();
    Co2read = Co2.getCO2();

    Serial.print("CO2[");
    //Returns calculated CO2 reading
    Serial.print(Co2.getCO2());
    Serial.print("] tVOC[");
    //Returns calculated TVOC reading
    Serial.print(Co2.getTVOC());
    Serial.println("]");
    //    //Simply the time since program start
    //    Serial.print(millis());
    //    Serial.print("]");
    //    Serial.println();

  }

  //Magneticfield sensor

//  if (Mag.readData(&magx, &magy, &magz)) {
//    Serial.print("X: "); Serial.print(magx, 4); Serial.println(" uT");
//    Serial.print("Y: "); Serial.print(magy, 4); Serial.println(" uT");
//    Serial.print("Z: "); Serial.print(magz, 4); Serial.println(" uT");
//
//  } else {
//    Serial.println("Unable to read XYZ data from the sensor.");
//  }


  // BNO055 9-Axis sensor
//  sensors_event_t event;
//  bno.getEvent(&event);

//  Serial.print(F("Orientation: "));
//  Serial.print((float)event.orientation.x);
//  Serial.print(F(" "));
//  Serial.print((float)event.orientation.y);
//  Serial.print(F(" "));
//  Serial.print((float)event.orientation.z);
//  Serial.println(F(""));
//
//  delay(100);

//  yaw = event.orientation.x;
//  pitch = event.orientation.y;
//  roll = event.orientation.z;
//  accx = event.acceleration.x;
//  accy = event.acceleration.y;
//  accz = event.acceleration.z;


  //Ultrasonic Sensor
//  Wire.beginTransmission(SLAVE_ADDR); // transmit to device #8
//  Wire.write(1);              // measure command: 0x01
//  Wire.endTransmission();    // stop transmitting
//
//  Wire.requestFrom(SLAVE_ADDR, 2);    // request 6 bytes from slave device #8
//  while (Wire.available()) { // slave may send less than requested
//    distance_H = Wire.read(); // receive a byte as character
//    distance_L = Wire.read();
//    distance = (uint16_t)distance_H << 8;
//    distance = distance | distance_L;
//    Serial.print(distance);         // print the character
//    Serial.println("mm");
//  }

  //TF Mini distance measurement
  //  dist = tfmini.getDistance();
  //  strength = tfmini.getRecentSignalStrength();

  // Display the measurement
  //  Serial.print(dist);
  //  Serial.print(" cm      sigstr: ");
  //  Serial.println(strength);


  //Temperature
//  tcaselect(0);
//  humd1 = sht20.readHumidity();                  // Read Humidity
//  temp1 = sht20.readTemperature();               // Read Temperature
////  //    Serial.print("Time:");
////  //    Serial.print(millis());
//  Serial.println("Sensor1");
//  Serial.print(" Temperature1:");
//  Serial.print(temp1, 1);
//  Serial.print("C");
//  Serial.print(" Humidity1:");
//  Serial.print(humd1, 1);
//  Serial.print("%");
//  Serial.println();
//  Serial.println();
//
//  tcaselect(1);
//  humd2 = sht20.readHumidity();                  // Read Humidity
//  temp2 = sht20.readTemperature();               // Read Temperature
//  //    Serial.print("Time:");
//  //    Serial.print(millis());
//  Serial.println("Sensor2");
//  Serial.print(" Temperature2:");
//  Serial.print(temp2, 1);
//  Serial.print("C");
//  Serial.print(" Humidity2:");
//  Serial.print(humd2, 1);
//  Serial.print("%");
//  Serial.println();
//  Serial.println();


  
//
//  Wire.beginTransmission(TCAADDR);
//  Wire.write(0);  // no channel selected
//  Wire.endTransmission();

}

It’s to long for one post. I just cut the data preparation out for sendig it with XBee.

I solved it. The issue was that the arduino didn't read the Serail for a long enough time. But thank you for your time.