Code not working with Blynk

I’m using Blynk Library 0.6.7. I’m connecting via USB and run the bat file that is there in scripts folder. My code execute until the Blynk.begin(); and doesn’t execute anything outside setup thereafter.

That answers this question…

but what about the rest of my questions, and what is the relevance of the PIO screenshot?

You should probably be running library version 0.6.1

Pete.

Is this is what you are asking for?

That answers the CMD window question.

Are you going to drip-feed me the answers to my questions one at a time?

Pete.

I’m not sure about the rest. But I can tell that I can use serial monitor or the blynk script at a time and not simultaneously…

So you don’t know whether you’ve modified the Blynk script (the .bat file) or whether you own a FTDI adapter?

I assume that this isn’t the actual Auth token that you’re using when trying to connect, and that you’ve disguised the real one for security purposes?

Pete.

Yes I have done it to avoid revealing my auth token… I haven’t modified any bat file. And I don’t have FTDI adapter.

Now I have no idea what to do to make it work… I have posted the code here…

The single most useful tool in this situation is the output from the debug serial port.
You need to see these messages, whilst the device is attempting to connect, to understand what is happening. You need an FTDI adapter for this.

The one other thing you could try (once you’ve downgraded to 0.6.1) is to force the use of port 8080, in case your ISP is blocking port 80.
This requites you to edit the script file. If you do a little searching of this forum you’ll find instructions on how to do that.

Pete.

That’s definitely not an issue from ISP because the other code is working totally fibe… This is the code that’s working fine -


// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <Arduino.h>
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX

#include <BlynkSimpleStream.h>

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

const int Green=2;
const int Orange=3;
const int Red=4;

int buttonstate1=0;


void setup() 
{
pinMode(Green, OUTPUT); 
pinMode(Orange, OUTPUT); 
pinMode(Red, OUTPUT); 

  Serial.begin(9600);
  Blynk.begin(Serial, auth);

}

BLYNK_WRITE(V1)
{
  buttonstate1 = param.asInt();
  if(buttonstate1 == 1){
  digitalWrite(Green, HIGH);digitalWrite(Orange, HIGH);digitalWrite(Red, HIGH);
  }
  else{
    digitalWrite(Green, LOW);digitalWrite(Orange, LOW);digitalWrite(Red, LOW);
  }
}

void loop() 
{
  Blynk.run();
  
}

just on and off the LED. But it’s not working in anything complex code than this…

Can someone help?

My advice is to give some thought to how your devices will connect to the Blynk server in the long term.
Clearly, using the USB serial connection via a computer which has to be running and have the command prompt open 24/7 isn’t the solution.

If your ultimate connection method will be hard-wired Ethernet then you don’t have many choices, and you’ll struggle to get a reliable long-term solution.

If your ultimate connection method will be WiFi then you have many more choices. You could go down the route of using an ESP-01 as a WiFi modem for an Arduino Uno/Mega, but I really wouldn’t recommend it.
Instead I’d suggest using an ESP8266 or ESP32 instead of the Arduino Uno/Mega, as they both have built-n WiFi capabilities, far more memory, and the ability to update them via OTA.

That way, instead of spending money on an FTDI adapter to allow you to see what messages your Mega is giving you about why your serial USB connection is failing, you’ll be able to spend that money on the device that you will ultimately use in your long-term project.

Pete.

1 Like

Yes… I’m planning the same. But are you sure this is not because of the code and it’s happening due to some external reasons?

What you describe sounds like an Auth code error, or an ISP issue, but you say it’s neither of these.
Beyond that it’s impossible to say without some serial debugging.

As far as your code is concerned, it’s a mess, but you already know that. We’ve told you several times about keeping your void loop clean by using timers, but you don’t appear to want to head that advice.

Pete.

I have tried everything… Also I’m not using delay anyways so I don’t see a problem. But I’ll try debugging and will let u know

That’s because you’ve not listened to the advice you’ve been given about the need to give the Blynk library the processor time it needs.
But, people will only give you the same information so many times. After that, if you choose not to take that advice then we tend to let you work it out for for yourself the hard way.

Pete.

I have seen many videos and writeups about blynk timer but there’s something that is missing… It isn’t working in my case. I have also raised this issue earlier… And I don’t think millis is an issue here…

Yes, and you’ve received answers then gone quiet.

There isn’t a fundamental issue with using millis comparisons in Blynk sketches per se - I do it from time to time, it’s the way that you’ve chosen to do this in a very clunky fashion and using wile statements. From my point of view, while statements are best avoided when using Blynk, unless you really know what you’re doing.

Anyway, you clearly aren’t interested in my advice, so I’ll leave you to it.

Pete.

Hello Pete,

I have received my esp wifi module today. But I’m unable to connect it to my mega… Is there any tutorial that can guide me setting up wifi for mega? After that I will start debugging…

Assuming that this means an ESP-01 then there are quite a few different tutorials on the forum. It’s actually pretty easy, once you work out the wiring. Just make sure you don’t connect it to the Tx/Rx pins on your Mega, as these are Serial0, which you’ll use for debugging. Use one of the other hardware serial ports.

Pete.