MKR1400 doens't reconnect after uploading code

Hello there,
My MKR1400 doesn't reconnect to my computer after I upload my code. It doen't show up at all at the port.
Connected sensors are DHT22, BMP280, DB1280
It only shows up again when I reset it but then my code is away in a logical way..

#include "thingProperties.h" //Cloud
#include "DHT.h" //DHT22
#include "OneWire.h" // Water
#include "DallasTemperature.h" //Water
#include "Wire.h" //Pressure
#include "SPI.h" //Pressure
#include "Adafruit_BMP280.h" //Pressure
/*---------------------------------------definitions----------------------------------------*/
#define DHTPIN 8 //DHT22
#define DHTTYPE DHT22 //DHT22
#define ONE_WIRE_BUS 2 //Water
/*--------------------------------------initializations-------------------------------------*/
DHT dht(DHTPIN, DHTTYPE); //DHT22
OneWire oneWire(ONE_WIRE_BUS); //Water
DallasTemperature sensors(&oneWire); //Water
Adafruit_BMP280 bmp; //Pressure
/*--------------------------------------void setup------------------------------------------*/
void setup() {
  Serial.begin(9600);
  delay(1500);
  dht.begin(); //DHT22
  sensors.begin(); //Water
  bmp.begin(); //Pressure
  initProperties();
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}
/*--------------------------------------void loop--------------------------------------------*/
void loop() {
  ArduinoCloud.update();
  static unsigned long lastMeasurement = millis();
  if ((millis() - lastMeasurement) > 3000) {
    temperature = dht.readTemperature();
    Serial.print("Temperatur: ");
    Serial.print(temperature);
    Serial.println(" C");

    humidity = dht.readHumidity();
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %\t");

    sensors.requestTemperatures();
    temp_water = sensors.getTempCByIndex(0);
    Serial.print("Wassertemmperatur betrÃĪgt: ");
    Serial.print(temp_water);
    Serial.println(" C");

    pressure_air = bmp.readPressure();
    Serial.print("Pressure is: ");
    Serial.print(pressure_air);
    Serial.println(" PA");

    lastMeasurement = millis();
  }
}

thingProperties.h is

// Code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>


const char THING_ID[]      = "5cafbba4-1a77-4401-b78d-7c9380766ce5";

const char GPRS_APN[]      = SECRET_APN;
const char PINNUMBER[]     = SECRET_PIN;
const char GPRS_LOGIN[]    = SECRET_USERNAME;
const char GPRS_PASSWORD[] = SECRET_PASSWORD;


float temperature;
float humidity;
float pressure_air;
float temp_water;

void initProperties(){

  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(temperature, READ, 5 * SECONDS, NULL);
  ArduinoCloud.addProperty(humidity, READ, 5 * SECONDS, NULL);
  ArduinoCloud.addProperty(pressure_air, READ, 5 * SECONDS, NULL);
  ArduinoCloud.addProperty(temp_water, READ, 5 * SECONDS, NULL);

}

GSMConnectionHandler ArduinoIoTPreferredConnection(PINNUMBER, GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD);

What can I change? It does seem to work with other codes..
Thank you for helping me, Lukas

The best thing to do in this type of situation is to narrow down the number of possible causes for the problem as much as possible. Once you have identified the specific cause of the problem, finding a solution for it will be much easier. Right now, you have a fairly complex sketch and so there are many possible causes of the problem.

The goal is to find a working state ("good") and a non-working state ("bad') and then figure out what is the specific difference between the working and non-working code. You have a sketch that produces the "bad" state, which is the one you shared. From your "It does seem to work with other codes." comment, it sounds like you are also able to achieve a working state. For example, I would guess that this is a "good" sketch:

void setup() {}
void loop() {}

Am I right about that?

But there is a large difference between that good and bad sketch. So the idea is to either add code little by little from the bad to the good working, or vice versa. The most efficient way to do this is the "bisect" technique. In this technique, you make something about halfway between the current "good" and "bad" (hence the "bisect" name), then test it. If it works, that is your new "good". If it doesn't work, that is your new "bad". Then you repeat the process. Each time, the difference between the "good" and "bad" becomes smaller until you have narrowed it down to the smallest possible unit of difference between "good" and "bad".

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.