[SOLVED] Arduino resetting when disconnected (via Serial USB-link )

I red many posts about “working with blynk when there is no internet connection)” but I am connecting to the internet via USB Serial (BlynkUsbScript). And whatever I do in my code to avoid reseting arduino, when i lose connection to the Blynk server, this script resets my arduino every 3 seconds (it is trying to reconnect).

Anything I can so it doesn’t do that? My project will be doing fine if its not connected to Blynk.

Thank you.

This is generally more for deployed, mission critical, WiFi devices… not tethered USB devices.

I know, that’s what I use all the time as well :wink: and attempting to use those connection management commands tends to just confuse the poor USB interface and destabilize my connection.

The USB link is more for benchtop testing, and does behave differently (from what I can tell) from standard Ethernet/WiFi and even GSM.

Also, all my Arduinos restart whenever reconnecting the USB script, I think it has to do with the Arduino firmware for the USB programming.

What script?

Not sure what you mean here… In my view, Blynk is a Server based, library & GUI addition to “normal” MCU coding methods, with it’s own specific purpose and required process of coding that enhance IOT type processes. But if your project works fine without it… then why are you trying to use it?

My wifi module is on its way but I think it is also nice if people could normaly us serial usb for communication, as any other transmission medium (wifi, ethernet, etc…).

BlynkUsbScript
Arduino => Tools => Run Usb Script

The project can work without blynk, I just do the monitoring part via Blynk. If it for some reason loses connection, it notifies me and after some time I can look what is the issue and fix it later, it doesn’t mean the project should stop if there is no connection. This is not a problem with other transmission methods (ethernet, wifi) but currently USB Serial script resets arduino if there is no connection (it trys to reconnect) and you can not modify this, as the script is compiled (jar format)

Hope this makes things clear now.

Thank you for the reply.

Regards

Yes, you will need to jump to the WiFi method in order to better utilise Blynk’s connection management routines.

I quite literally, just (1/2 hours ago), had an almost total stranger stop by, gifting me with a Seeed Studio WiFi Serial Transceiver Module (ESP8266EX based) just because he heard me going on and on about Blynk and what it can do… when NOT tethered by USB :wink: He didn’t even know exactly what it was, he just remembered my passion and the numbers 8266 :stuck_out_tongue_winking_eye: and asked at an electronics store, that I wouldn’t have be able to get to myself.

I have a couple of Wemos boards also on the way, in a month or so (Thank you again @Fettkeewl ;)) but this little gem will get me started learning how to use them properly when they arrive.

Got ya… I thought you were referring to an Arduino script.

I understand better now :slight_smile: If you need, once you get the WiFi module, you can post your script here for assistance in getting the “if serverless” functionality nailed down.

1 Like

Well before Blynk I worked with 2 differend LCD modules, one from Adafruit, programming that one is a horror. After I learned about Nextion LCDs which is half the price of Adafruit and much easier to program due to their GUI editor… and then I learned about Blynk, I was so much fascinated about Blynk, as you with the 8266 number, that my girl friend was going crazy… I was all time saysing to her, look what Blynk can do, look how easy you can do it with Blynk, look this, look that, …blynk, …blynk, …blynk :smiley:

Thank you for the reply, wish you good times with your little gem.

Regards

1 Like

Thanks! That gem cost me many hours of my life… mostly frustrated by spotty documentation… but I managed to get my UNO “wirelessly online” with my Local Server… the Mega is next, with a more permanent wiring job. But now I’m off to sleep as the birds wake up… darn noisy chirp, chirp, chirp… :stuck_out_tongue_winking_eye:

@Cejfi An added comment about your connection stability via USB-script… After some trying of many things, I actually got vastly higher stability with full two way communication by simply increasing my baud rate between the Mega and the PC. Now at 57600 for the USB-link for the server and 38400 for my TTL-USB, used by Termite as my monitoring program.

Sound interesting, the usb to serial script is connecting at 9600 how did you change that?

The blynk-ser.bat is typically located in the located in the Documents\Arduino\libraries\Blynk\scripts forlder on a Windows PC.

You can edit that file directly, or what I do is just make individual copies, edit & rename them for each of my arduino boards, and place shortcuts for them on my Desktop.

Of course , you need to match the BAUD in both the .bat file and on your Arduino script’s Serial.begin(57600);… I have forgotten that a few times :stuck_out_tongue_winking_eye:

I get this msg when I try to run the bat file:
OpenC0C(): CreateFile(“\.\COM1”) ERROR No such file or directory (2)

Ahh my COM port is COM11 that was confusing me, didn’t see the second “one”. Lets see what this new baud rate can do!

Thanks for the hint

Blynk.syncVirtual(BLYNK_ILIGHT_DEBUG_BUTTON_PIN, BLYNK_TERMINAL_BUTTON_PIN);

Don’t know why but the above line makes a soft reconnect. With “soft” I mean Blynk doesn’t notify me about the lost connection, you can just realize that you reconnected by monitoring the BLYNK_CONNECTED() method.

Edit: P.S. The 57600 baud rate didn’t solve this.

Edit 2: P.S.2 And removing one of them solves the problem. Example:
Blynk.syncVirtual(BLYNK_ILIGHT_DEBUG_BUTTON_PIN); or Blynk.syncVirtual(BLYNK_TERMINAL_BUTTON_PIN);

Even though Blynk.syncVirtual(vPin) supports multiple vPins, and without seeing everything else that is going on it is just a guess, but you might still be having glitches in the communication, causing lag or flooding.

This is where having a 2nd TTL-USB connection is handy… if there are any momentary errors, such as flood warning, etc, you may not always notice them, but they will show up with the #define BLYNK_PRINT Serial; // <-- this points to your diagnostic port command at the beginning of your sketch.

As mentioned earlier… I don’t trust the Blynk.config() or connection management commands with the USB-link… I suspect it just makes things worse, based on tests.

That is true, I have to send a lot of init values to Blynk. After the hardware regains connection it has to send everything that changed in the time blynk wasn’t monitoring it (no connection). Maybe spliting the init data in several intervals would solve the problem ^^.

But it is still not an issue, after reconnect everything works fine again, it just hurts my eyes that reconnect, you probably know what I mean… :smiley:

My “testbed” sketch sends many many much data back and forth… as I am constantly testing all sorts of program routines, timing routines, widget controls, etc. As I add stuff, I do find I need to tweak “efficiency”… including recently ditching all connection management (which I have been recently testing) and fiddling with the BAUD rate until it worked smoothly again.

When working with the USB-link, there are other things to consider… your type (and perhaps quality of chipset) of your PC’s USB ports, cable quality (usually it is also sending power to the Arduino), processing power, other USB devices and and background tasks on the PC may even have a subtle effect.

Ahh, soon I will cut the umbilical and branch out into the WiFi world… :astonished:

Well I still don’t understand it but putting all the code from the setup() into a one time timer solved the problem. Seems like the timer is doing more then i was thinking.

The timer gets triggered right after the setup, instantly and it still has a big impact. I didn’t even split the code in several “one time” timers, I just used one timer…amazing.

Without seeing what you had, it is hard to say if it was correctly used… each “named” timer object can have up to 16 individual timers:

Something to note, having “corresponding” timer points can end up with the occasional “rush hour” of multiple timed functions being simultaneously called… so I tend to space out all my timers accordingly.


// ===== Timer Setup =====
  timer.setInterval(200L, whiteLED);  // White LED button monitor on CodeShield
  timer.setInterval(350L, PingSensor);  // Up Time Widget
  timer.setInterval(450L, SuperCapVoltage);  // Super Cap charge display
  timer.setInterval(650L, PIR);  // PIR motion routine - switched
  timer.setInterval(995L, clockDisplay);  // Time and Date Widget
  timer.setInterval(1600L, AnalogSensors);  // Misc analog sensors on CodeShield
  timer.setInterval(5000L, HeartBeat);  // Heartbeat LED
  timer.setTimer(10000L, StartUpEmail, 1);  // Send Start Up Email, once.
  //  timer.setInterval(15000, reconnectBlynk); // check every 15 seconds if we are connected to the server
  timer.setInterval(20010L, thermTemp);  // Thermistor  on CodeShield
  timer.setInterval(60000L, sendUptime);  // Up Time Widget
1 Like

Thank you for the great inputs, all this fighting got me much deeper into the “World of Blynk”.