USB and Leonardo

Hi guys! Sorry for my English, Google translator :slight_smile:
Returning to the subject of the connection using the Arduino USB PC port. Produced full customization, everything works fine, but not for long. After 0.5-1 hours of lost connection and laptop can not connect to Arduino:
Received EOF
EVENT_CLOSE
InOut () - STOP
Disconnect () - OK
Connect ( “cloud.blynk.cc”, “8442”) - OK
InOut () START
DSR is OFF

It helps only a complete restart Arduino, there is an assumption that there is an accumulation of information in the Arduino and eventually it stops working.

My code:
-#include <SoftwareSerial.h>
SoftwareSerial SwSerial(0, 1); // RX, TX
-#define BLYNK_PRINT SwSerial
-#include <BlynkSimpleSerial.h>
char auth[] = “***********my”;
-#include <SimpleTimer.h> //таймер
SimpleTimer timer;
void sendOnOff() {
int sens = A0;
int senst = A2;
int led = 11;
int led1 = 13;
int kak= analogRead(sens);
int osv= kak/1.45;
Blynk.virtualWrite(V0,osv);
int kakt= analogRead(senst);
int temp= kakt/17.0;
Blynk.virtualWrite(V1, temp);

}
void setup()
{
Blynk.begin( auth, 9600);
Blynk.connect();
while (Blynk.connected() == false)
{
Blynk.connect();
}
timer.setInterval(1000, sendOnOff);
}
void loop()
{
while (Blynk.connected() == false)
{
Blynk.connect();
}
Blynk.run();
timer.run();
}

What information has to provide to get rid of the problem?

@aleksandrn7 few ideas for you:

  1. Switch from SoftSerial to HardSerial
  2. Check that any widgets associated with virtual pins are set to PUSH frequency not for example 250ms.
  3. I wouldn’t have thought it was a memory issue as the sketch looks quite basic. How much storage space and dynamic memory does the sketch use (in bytes and % of total).
  4. Please provide details of the widgets you are using and their pin allocations and I will try to load it up on my Leonardo and report back to you.
  5. For Serial Monitor isn’t the sketch missing the opening of the serial port i.e. serial.begin and remembering that the Leonardo is slightly different to other Arduinos regarding serial use?

Thanks for the answer!

    1. I do not have HardSerial, only SoftSerial.
  1. Yes, I found it was time 200 ms and 1 second on my widget, I will try to PUSH .
  2. Sketch uses 14 424 bytes (50%) of program storage space. Maximum is 28 672 bytes.
    Global variables use 553 bytes (21%) of dynamic memory, leaving 2 007 bytes for local variables. Maximum is 2 560 bytes.
    4.Widgets screen.https://drive.google.com/open?id=0B4NC9k9IWGa-TWVLZFdBYmZVeWc
  3. This little know now I will read about the class Serial.

instead:
-#include SoftwareSerial.h>
SoftwareSerial SwSerial(0, 1); // RX, TX
-#define BLYNK_PRINT SwSerial
-#include BlynkSimpleSerial.h>

I wrote:
-#define BLYNK_PRINT Serial1
-#include BlynkSimpleSerial.h>

I tested :blush:

Have you changed the Serial and if so is it any better?
Pretty sure you do have hard serial even if you think you don’t.

Maybe you don’t have Hard Serial, I forget that I also use ESP’s as well as the USB port.

Your sketch as posted above is missing various bits. I have included the required parts and it now compiles for the Leonardo. The sketch as I currently have it is shown below. Please let me know if you have anything different and meanwhile I will create the app and test it. Whilst I was out one of my USB connected devices notified me it had lost the connection to Blynk but the batch file reconnected and all is fine with the project. I do get disconnects as I think many people do. I have recently transitioned to ESP standalone and it does seem to be the most reliable hardware at the moment.

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(0, 1); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";
#include <SimpleTimer.h>//таймер
SimpleTimer timer;
void sendOnOff() {
int sens = A0;
int senst = A2;
int led = 11;
int led1 = 13;
int kak= analogRead(sens);
int osv= kak/1.45;
Blynk.virtualWrite(V0,osv);
int kakt= analogRead(senst);
int temp= kakt/17.0;
Blynk.virtualWrite(V1, temp);

}
void setup()
{
  Blynk.begin( auth, 9600);
  Blynk.connect();
  while (Blynk.connected() == false) 
  {
    Blynk.connect();
  }
  timer.setInterval(1000, sendOnOff);
}
void loop()
{
  while (Blynk.connected() == false) 
  {
    Blynk.connect();
  }
  Blynk.run();
  timer.run();
}

after replacing:
#include SoftwareSerial.h>
SoftwareSerial SwSerial(0, 1); // RX, TX
#define BLYNK_PRINT SwSerial
#include BlynkSimpleSerial.h>
into:
#define BLYNK_PRINT Serial1
#include BlynkSimpleSerial.h>

And I also installed widgets associated with virtual pins are set to PUSH. For 4 hours it works well. If everything will work well, I try to test what would fix the issue.
I plan to go to the ESP, but still have the desire to set up a solid performance by USB :smiley:

My Leonardo is running with your sketch, been up for 5 minutes (around 4pm local time.) Connected to a Windows 8.1 machine. I will leave it running for a while to see if it stays connected.

May I ask what you have connected to A0 and A2? I’m guessing a temperature sensor etc. If you could provide details I will see if I have a similar device to hook up in case the hardware on A0 or A2 causes the disconnects.

For A0 connected low-power solar cell with a maximum voltage of 5V, so I measure the illuminance. By A2 is connected to the thermistor 9kOm through voltage divider resistors on 11kOm, 5V Arduino connected to the thermistor and resistance 11kOm to the GND…

Already working 6-7 hours and it is good, tomorrow I will seek what was the problem.

I have a 24V solar cell here but I’m not an illuminance or thermistor kind of guy. I added a Value display to an ESP standalone project yesterday and I started to get lots of disconnects on a system that is normally very stable. When I changed the frequency to PUSH the disconnects seem to have stopped but I can’t be sure that was the problem.

Here is a sketch works well. It seems the problem was SoftwareSerial.h…

#define BLYNK_PRINT Serial1
#include <BlynkSimpleSerial.h>
char auth[] = "***********************************";
#include <SimpleTimer.h> //таймер
SimpleTimer timer;
void sendOnOff() {
int sens = A0;
int senst = A2;
int led = 11;
int led1 = 13;
int kak= analogRead(sens);
int  osv= kak/1.45;
Blynk.virtualWrite(V0,osv);
int kakt= analogRead(senst);
int temp= kakt/17.0;
Blynk.virtualWrite(V1, temp);
}
void setup()
{
Blynk.begin( auth, 9600);
Blynk.connect();
while (Blynk.connected() == false) 
{
Blynk.connect();
}
timer.setInterval(1000, sendOnOff);
}
void loop()
{
while (Blynk.connected() == false) 
{
Blynk.connect();
}
Blynk.run();
timer.run();
}