General Hardware Error and Connection Problems

My set up is a Arduino Nano connected via Serial USB to a Windows laptop, no local server. As well as the main USB connection I also have a USB to TTL adapter wired up to the Nano to read the debug / serial window.

I spent most of yesterday adding lots of widgets. 2 timers (one for AM and one for PM), terminal to send on and off commands, value display, LED’s etc.

I should have tested each widget more thoroughly because now something is crashing the system. Basically I can run the app but after a few button presses Blynk drops the connection and sometimes it reports invalid hardware CMD. With the Windows system the only way to reconnect to Blynk is to run the batch file a second time i.e. I can’t simply reset the Arduino as it fails to reconnect.

I have now gone right back to the basic Arduino Serial USB sketch with a single Blynk button wired up to an LED on digital pin 3. Now when I quickly reset the Arduino the serial windows shows connecting and timeout every 5 seconds BUT the app is still controlling the LED. How can this be if the serial window states the login has timed out?

One other question. I haven’t defined pin 3 as input / output in the sketch but it works. Are there circumstances where the pins must be defined in the sketch for Blynk to work correctly?

About the pin definition, I’d advise to learn yourself to do it automatically (though sometimes I also forget, lol). It’s just best practise and prevents weird input/output errors.

About the Nano, to my knowledge it has only 1 serial port, so I think you have to choose between serial output or connection over USB. You can’t do both at the same time as far as I know.

You need something like a Mega or Due for that because they have more serial ports available.

I do normally define all the pins as my actual project covers the pinouts on my RF transmitters and receivers. I will ensure I define them correctly and set them high or low on bootup as required.

I do have a Mega but it is tied up at the moment.

My understanding is that with the extra USB to TTL adapter (on pins 10 and 11) the SoftwareSerial library provides the ‘second’ serial port for debugging the error messages etc. Main port is COM5 and USB to TTL is COM7. I upload the sketches to COM5, start the connection to the Blynk server (Windows batch file) and then switch Arduino to use COM7 for debugging.

It all looks ok as shown from the serial monitor data below:

[20078] Connecting...
[22104] Login timeout
[25104] Connecting...
[27129] Login timeout
[30129] Connecting...
[1] Blynk v0.3.1
[5002] Connecting...
[5423] Ready (ping: 398ms);

The ping confirms the connection but if I press the reset on the Nano I get:

 [1] Blynk v0.3.1                                                             
[5002] Connecting...                                                   
[7026] Login timeout                                                     
[10027] Connecting...                                                    
[12052] Login timeout                                                   
[15052] Connecting...                                                      
[17078] Login timeout                                                      
[20078] Connecting...                                                     
[22104] Login timeout                                                       
[25104] Connecting...                                                      
[27129] Login timeout

but the blynk App is still controlling the LED.
I guess this is telling me that COM5 is fine for Nano to Blynk server but COM7 (USB to TTL) is giving me some duff info.
Sketch below is a working reset for the Nano with a button in Blynk (set to Push rather than Switch) and an LED (Pin 3 Arduino). Row 4 of the sketch is commentated out so BLYNK_PRINT doesn’t show misleading messages in the USB to TTL serial window.

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(11, 12); // RX, TX was 2 and 3
//#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>

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


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

void setup()
{
  SwSerial.begin(9600);
  SwSerial.println(" Nano has just rebooted");
  Blynk.begin(auth);
  // Default baud rate is 9600. You could specify it like this:
  //Blynk.begin(auth, 57600);
  pinMode(TestLEDPin, OUTPUT);
  digitalWrite(TestLEDPin, LOW); // set LED pin OFF
  delay(150);  // wait 0.15 seconds  
}

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

void loop()
{
  Blynk.run();
  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
  }
}

USB to TTL serial window correctly shows the Nano resetting as you press the Blynk button:

Pin is HIGH resetting Nano .............
Nano has just rebooted
Pin is HIGH resetting Nano .............
Nano has just rebooted
Pin is HIGH resetting Nano .............
Nano has just rebooted

You could also use the Blynk.connect() procedure to see if Blynk is still connected. I think it just returns true or false. Also very handy.

It may prove even more useful than your software reset because it enters a 2s delay in the main loop which should be avoided.

The 2s delay ONLY occurs when the Nano is resetting and is there to simply light the LED before the reset. It could be as low as 100 ms. I think Blynk.connect() is very different to the reset code. I provided the code more to show the effect of commenting out row 4 as the Blynk connection status messages for the USB to TTL are not relevant (wrong).

I have changed the pause in the sketch from 2s to 0.2s in case anyone cares to use it.

Lichtsignaal is there somewhere I can find out more about the Blynk functions like Blynk.Connect()?
Checked Google and the search on this forum but no joy.
From the sketch in the second post at Continuing loop while reconnecting I am guessing it tries to connect devices to Blynk rather than rebooting the devices.

You can try here for starters:

http://docs.blynk.cc

It’s the official documentation. It’s not 100% complete (because the folks have to work on developing new features for us too), but it’s a good starting point.

And of course doing stuff, making errors and asking here works too :slight_smile: