[SOLVED] Slider seems to crash arduino

If I have a serial monitor open to debug my program, and I slide the slider widget to change a value in the program, Arduino crashes. Is this an issue, or something I’m overlooking?

I have tried with multiple widgets, holding the button down while in Push mode doesn’t have the same effect as continuously sliding the slider.

Any suggestions?

my code:

BLYNK_WRITE(10){
int test = param.asInt();
Serial.print("this is test param: ");
Serial.println(test);
}

What do you mean by " Arduino crash" ?
Please post more details, set up and full code.

Thanks

When I say “crash” i mean when I move the slider for more than ~5 seconds Blynk loses connection and reconnects.

I’m using Mega 2560 and CC3000 wifi board.

Code is here: https://github.com/justinwagg/New_Greenhouse_v2

I have the same problem with my Arduino Nano and the slider. My slider is polled every second and then the reading sent back to a Value Display in the App. If I slide the slider then I get errors in the serial window and the connection to the Blynk server needs to be restarted. If I prod or dab the slider all works fine. Perhaps this is a ‘flood’ issue?

I see the bug / feature is also reported at Reconnect to Blynk server after use Slider Widget

For me the slider range is very small, just 10 to 30 but I think dragging the slider is just too much ‘stress’ for the Nano / Blynk server. Anybody found a fix for delaying the slider readings until you stop sliding?

You could do something with millis() to apply a pause between readings.

unsigned long previousMillis;
unsigned long waitTime = 250;

BLYNK_WRITE(V10)
{
  previousMillis = millis();
  if( ( millis() - previousMillis ) >= waitTime )  
  {
    doStuffHere();
  }
}

I’m not sure the logic here is spot on, but you can do something like this to compare current time with a previous time and if current time - previous time is bigger than the interval, do something, but I’m not sure it’ll work correct this way.

-edit-

Or use the debounce library, I think someone already made something for de-bouncing buttons, I’m sure that’ll work here too.

@Costas in your link it was esp wiring problem. Nano should work fine. Could you please post your code?

Lichtsignaal I have 2 (well 3 timers) one that calls read slider and one that writes slider value to a value display.They are both set at 1 second intervals (the third for something else is 6 second intervals).
So I have:

void sendMinutes()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, minutes_requested);   // StartTimer (manual) duration in minutes write to V6 every second
}

void sendSlider()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, minutes_requested);   // StartTimer (manual) duration in minutes write to V6 every second
}


BLYNK_WRITE(V7) //Button Widget is writing to pin V7
{
  int pinData2 = param.asInt();
  minutes_requested = pinData2; 
}

And in setup I have:

  timer.setInterval(1000L, sendMinutes);  // send every 1 second
  timer.setInterval(1000L, sendSlider);  // send every 1 second

Wouldn’t the timer library overwrite the millis debounce?
I do need to do some debounce as some of my pins appear to be floating. Fixed one with an LED but don’t want to put LED’s on all the bouncing pins.

Dimitriy not sure if code snippets are any good for you. Is it ok to write 2 lots of details to a single value display?

Serial monitor shows the following when I drag the slider:

Invalid header type:50 and some garbled characters.

Dimitriy do you know what the frequency is for reading the Slider? I have set up some basic code and I can now slide the Slider and report the changes on a Value Display widget.

But if I move the slider back and forwards too quickly the system crashes. I will incorporate millis() into my sketch as suggested by Lichtsignaal but I’m not convinced this will fix the problem if your slider value calls are too frequent.

Hm… Usually it should not happen with Arduino. Are you in debug mode on Arduino side?

Yes I have debug running to my additional USB to TTL Com Port.

I show the full sketch below. Initial previousMillis = millis(); is in setup() and resetting if the action is carried out in V7. Even with the wait time set as high as 1500 ms it will not prevent the crash. As far as I can tell it is not the writing to the Value Display widget that is the problem (following Lichtsignaal’s fix) it is the constant reading of the Slider. I guess the Slider frequency is set at your end. With my cleaner code the normal operation of the slider is now fine but you are always going to get some user who wants to fly backwards and forwards at unacceptable speeds.

/**************************************************************
  Simple NANO reboot sketch 26/12/2015
 **************************************************************/

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(11, 12); // RX, TX was 2 and 3
#define BLYNK_PRINT SwSerial
#define BLYNK_DEBUG // Optional, this enables lots of prints
#include <BlynkSimpleSerial.h>
#include <SimpleTimer.h>
SimpleTimer timer;

int testval = 0;  // variable to hold D3 pin status
int Changed = 0;  // variable to see if D3 pin status has changed
int TestLEDPin = 3; // new ON / OFF LED PIN
int minutes_requested = 0;
int pinData2 = 0;  // read Slider vlaue
int SliderChanged = 0; // check if slider value has changed

unsigned long previousMillis;
unsigned long waitTime = 1500;

char auth[] = "2120f1064e494868aa6f624c48a0ebcd";

void setup()
{
  SwSerial.begin(9600);
  SwSerial.println(" Nano has just rebooted");
  Blynk.begin(auth);
  timer.setInterval(1000L, sendSlider);  // send every 1 second
  pinMode(TestLEDPin, OUTPUT);
  digitalWrite(TestLEDPin, LOW); // set LED pin OFF
  delay(50);  // wait 0.15 seconds
  previousMillis = millis();  // set initial values as equal  
}

//****************************************

BLYNK_WRITE(V7) //Button Widget is writing to pin V7
{

  if( ( millis() - previousMillis ) >= waitTime )  
  {
      pinData2 = param.asInt();
      if (pinData2 != SliderChanged){  // Slider has changed
         minutes_requested = pinData2;
         previousMillis = millis();
      } 
  }
}

void sendSlider()
{
  if (pinData2 == SliderChanged){  // Slider hasn't changed
    minutes_requested = millis()/ 1000; // 1 second intervals
  }
  pinData2 = SliderChanged;  // set variables the same 
  Blynk.virtualWrite(V6, minutes_requested);   // StartTimer (manual) duration in minutes write to V6 every second
}

//void(* resetFunc) (void) = 0; //declare reset function @ address 0 THIS IS VERY USEFUL

void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
  testval = digitalRead(TestLEDPin);    // pin
  delay(100);
  if (testval != Changed){   // prevent looping until status of D3 pin changes
    if (testval == 1){
      SwSerial.println(" Pin is HIGH resetting Nano .............");
      delay(200);  // pause to see LED ON prior to reset
      //resetFunc(); //  reset Nano
    }
    else{
      SwSerial.println(" OK Pin is LOW");
    }
    Changed = testval; // prevent looping until status of D3 pin changes
  }
}

Turning debug off should help. Debug could slowdown your system up to 10x times.

Ok I will see how I go without DEBUG.

It is not recommended to use delays in main loop.

So I should user timer library for any delays and use virtual buttons to stop any pin bounce etc?

Probably yes. Depends on your goals.

Thanks guys, with debug off and no delays I can’t crash the system however fast I move the Slider back and forth.

1 Like