Script keeps halting (on MEGA via USB link)

Ok so I will buy one of those and hopefully this will work. Third time lucky.

1 Like

Dmitriy, I have just bought an Ethernet shield for my Arduino as you instructed to use either Ethernet or Wifi as more stable that USB.

Guess what, it keeps disconnecting, connecting, disconnecting, connecting even on the most simple of sketches. Things work when its connected, but why does it keep disconnecting and then reconnecting? I thought this was supposed to be more stable?

Here is a video of what its doing…

@stevelondon post the simple sketch that keeps disconnecting together with the Serial Monitor data.

Sounds like you have a general internet or hardware problem as every connection type you try is unstable and that is not the experience of most Blynkers.

Which Ethernet shield are you using as some are very unreliable i.e. faulty?

1 Like

@stevelondon please post simplest possible sketch that is disconnecting.

It might be me but I will do some more testing tonight. It’s the

It’s a Wiznet W5100

Post a basic sketch if you are still struggling.

    #define BLYNK_PRINT Serial
    #define ONE_WIRE_BUS_PIN 44

    #include <SPI.h>
    #include <Ethernet.h>
    #include <BlynkSimpleEthernet.h>

    #include <Wire.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>

    OneWire oneWire(ONE_WIRE_BUS_PIN);
    DallasTemperature sensors(&oneWire);

    DeviceAddress Probe01 = { 0x28, 0x5E, 0x72, 0xC5, 0x06, 0x00, 0x00, 0xA4 }; 
    DeviceAddress Probe02 = { 0x28, 0x9F, 0x49, 0x2F, 0x06, 0x00, 0x00, 0xAA };
    DeviceAddress Probe03 = { 0x28, 0x7A, 0xFB, 0xC4, 0x06, 0x00, 0x00, 0x79 };

    char auth[] = "65b59ec2bb95487dbfe59f0c4d5f4166";

    #define W5100_CS  10
    #define SDCARD_CS 4

    float tempC01, tempC02, tempC03;
    unsigned int tempMillis = millis();

    void setup()
      pinMode(SDCARD_CS, OUTPUT);
      digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

      sensors.setResolution(Probe01, 10);
      sensors.setResolution(Probe02, 10);
      sensors.setResolution(Probe03, 10);

    void printtemp1()
      if (tempC01 > 28)
        Blynk.setProperty(V21, "color", "#FF3333");
      else if (tempC01 < 25)
        Blynk.setProperty(V21, "color", "#3399FF");
        Blynk.setProperty(V21, "color", "#000000");
      Blynk.virtualWrite(V21, tempC01);

    void printtemp2()
      if (tempC02 > 28)
        Blynk.setProperty(V22, "color", "#FF3333");
      else if (tempC02 < 25)
        Blynk.setProperty(V22, "color", "#3399FF");
        Blynk.setProperty(V22, "color", "#000000");
      Blynk.virtualWrite(V22, tempC02);

    void printtemp3()
      if (tempC03 > 28)
        Blynk.setProperty(V23, "color", "#FF3333");
      else if (tempC03 < 25)
        Blynk.setProperty(V23, "color", "#3399FF");
        Blynk.setProperty(V23, "color", "#000000");
      Blynk.virtualWrite(V23, tempC03);

    void loop()
      if (millis() - tempMillis > 1000)
        tempC01 = sensors.getTempC(Probe01);      // Tank 
        tempC02 = sensors.getTempC(Probe02);      // Sump
        tempC03 = sensors.getTempC(Probe03);      // LEDS
        tempMillis = millis();

@stevelondon looks like a fairly clean sketch.

10 bit resolution takes around 190ms so the 3 probes should take around 570ms and therefore 1000ms intervals should work. Personally I would read the sensors every 10s or longer unless your project really needs to respond quicker.

I would look to switch to BlynkTimer rather than millis() and see if you are still having problems.

You might want to rethink this if you stick with millis() rather than BlynkTimer(aka SimpleTimer)

1 Like

You know what, I have at the same time as you noticed that and changed it to unsigned long. I was just about to post it and see your second reply. Its fixed it (I think) just running a longer test.

The unsigned int was getting to the end of its numbers and then going back to 0, thus confusing everything and sending flood and other error messages and disconnecting it.

Phew. Thank god for that. Its typical, I knew it would be bloody me. I have spent hours and hours going through this code and couldn’t find anything wrong with it, and it was one little ‘int’ instead of a ‘long’.

Also I want to keeps using millis because i want the arduino to run independently from the app in case something goes wrong with the app. I have water pumps and stuff on it so want to make sure it will run on its own if the app was to ever stop working. I should in theory be able to use the app to programme everything, and then disconnect if need be and still have everything run off the arduino itself.

Thanks for your help mate and good spot.

I agree, I planned on doing it every 5 to 10 seconds in the final setup but used 1s for testing so I could see the results quicker. :slight_smile:

The big question now is… have I wasted money on an ethernet board and was it this ‘unsigned int’ that was causing me problems all along with my USB connection.

Will have to test this later.

I thought it was you too :slight_smile:

BlynkTimer is nothing to do with Blynk, it is Arduino’s SimpleTimer renamed and prevents int / long bugs :slight_smile:
Strongly recommend you switch but it’s your call.

@vshymanskyy might be worth renaming BlynkTimer to “ArduinoESPtimer” as there seems to be a lot of people getting the wrong idea of what it is.

Oh right. I’ll have a look at it then. Thank you.

It didn’t help wither that I was troubleshooting in the dark a little bit because I forgot I can use Serial monitor with an ethernet shield, I was used to using USB were you can’t use it unless you have a TTL - USB cable.

nice touch! how could that go unspotted for soo LONG? (literally)


Perhaps because the OP originally posted hundreds of lines of “irrelevant” code.

Very punny :laughing:

No, why? It works on linux , particle, esp and mbed… why renaming?