How to add lables when my mega2560 digitalread is HIGH

Before creating the topic

Arduino mega2560 and Nodemcu wifi communication
Samsung galaxy s5
Blynk server

This code is for my arduino mega


#include <HardwareSerial.h>


bool limit;


/////////////////////-------------////////////////////

void setup() {
  // put your setup code here, to run once:
  Serial1.begin(9600);
  Serial.begin(9600);
  pinMode(52, INPUT);
}


////////////  Atmega 2560 hardware////////////////
void loop() {
  // put your main code here, to run repeatedly:
  
    limit = digitalRead(52);
    Serial1.write(limit);
    delay(1000);
  
}

What to do with this code which can change the labels in menu widget to the app. this code is particular for Atmega which is serially connected to node mcu.

currently i’m trying to post nodemcu code but i can not. (New user something)
so what should i do this code which will write the value in nodemcu and will chage the labels in MEnu widget.

Please read the Welcome Topic… I had to fix your post to properly show posted code.

Blynk%20-%20FTFC

And then start reading the documentation for Blynk and proper use of code and structure with Blynk…

http://help.blynk.cc/getting-started-library-auth-token-code-examples/blynk-basics/keep-your-void-loop-clean

done sir!

now what to write in Nodemcu ?? please give me suggestion for changing lables of menu button from atmega 2560 digitalread input.

Really? Then what form of nonsense is in your void loop() ??

And what made up command is Serial1.virtualWrite() ???

Have you even looked at the Documentation for the Menu Widget? Particularly the reference for changing Menu items from the Hardware side?

Have you tried to look into the sketch builder?

https://examples.blynk.cc/?board=Arduino%20Mega%202560&shield=Serial1&example=GettingStarted%2FGetData

I think this one will use when i want the data from Blynk app. so in my case this is not useful.

but i want to send data from arduino to blynk app via nodemcu (a medium which will change the menu property ).

I have edited my hardware side code. please see if any correction needed.

This is my nodeMcu code.


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include<HardwareSerial.h>
// You should get Auth Token in the Blynk App.


int pin1;
int pin2;
int pin3;

// Go to the Project Settings (nut icon).
char auth[] = "";


int f1;

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****";
char pass[] = "****";

void setup() {
  // Debug console
  Serial.begin(9600);
  Serial1.begin(9600);
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

}
 /*BLYNK_WRITE(V5)
{
  pin1 = param.asInt();
  Serial.println(pin1);
  Serial1.print(pin1);
}*/
/*BLYNK_WRITE(V6)
  {
  Serial.println(param.asStr());
  }*/

//////////////-----------------////////////


void loop()
{
  if (Serial1.available()) {
  Blynk.run();
  f1 = Serial1.read();
  Serial.print(f1);
  }
}

void ls() {
  if (f1 == 0) {
    Blynk.setProperty(V1, "labels", "Item1", "Item2", "Item3");
  }
  if (f1 == 1) {
    Blynk.setProperty(V1, "labels", "Name1", "Name2", "Name3");
  }
}

Yes sir @Gunner i read that. But i can’t figure out how can my digitalRead will serially transfer to the nodemcu.

So i need help which can send digital signal to nodemcu and nodemcu will change the menu lables through it.

if signal ==0 then label = something;
if signal ==1 then label = something1;

Why are you mixing the NodeMCU and Arduino Mega? If you need to run Blynk on both, then do so and use the bridge command if for some reason it is necessary.

Or if you want to leave the Mega with non-Blynk code, because of timing needs or something… use EasyTransfer to handle your cross MCU communication needs.

Basically sir my intention to use this Atmega and Nodemcu is i want to control thing over atmega 2560 with Iot (which is connected to NodeMCu). I don’t want to use Nodemcu GPIO if needed i will use because my application need 45 I/O so that’s why i’m using Atmega2560.

I already done On/Off the light from mobile app (through virtual pin --> nodemcu —> serially write to atmega)

but now i want to reverse this (mega --> nodemcu(serially I think) --> App(which will change the property of Menu widget)

I needed a code help sir @Gunner. @Dmitriy. @BlynkAndroidDev

@Gunner

hey sir i tried a lot with bridge and Et transfer but this is not working. please sir guide me i’m working since 30 hours.

@Dmitriy

Please stop “calling” on the developers for your coding help… they are busy developing :wink:

As for learning how to use Easy Transfer… well that is something for his (the authors) site or Github page, not really a Blynk thing… just something I suggested.

I also suggest you learn how to use it between to non-Blynk applications before trying to figure in the Blynk aspect at the same time.

ok sir this is my code from hardware side

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Envelopeirtel";
char pass[] = "te123";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

// Bridge widget on virtual pin 1
WidgetBridge bridge1(V1);

// Timer for blynking
BlynkTimer timer;


void blynkAnotherDevice() // Here we will send HIGH or LOW once per second
{
  // Send value to another device
  if (digitalRead(52 == HIGH)) {
    //bridge1.digitalWrite(9, HIGH);  // Digital Pin 9 on the second board will be set HIGH
    bridge1.virtualWrite(V5, 1); // Sends 1 value to BLYNK_WRITE(V5) handler on receiving side.

    /////////////////////////////////////////////////////////////////////////////////////////
    // Keep in mind that when performing virtualWrite with Bridge,
    // second board will need to process the incoming command.
    // It can be done by using this handler on the second board:
    //
    //    BLYNK_WRITE(V5){
    //    int pinData = param.asInt(); // pinData variable will store value that came via Bridge
    //    }
    //
    /////////////////////////////////////////////////////////////////////////////////////////
  } 
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("9071fa474505ba625a8ebfeecc74"); // Place the AuthToken of the second hardware here   /// nodemcu token
}

void setup()
{
  // Debug console
  Serial.begin(9600);
   pinMode(52,INPUT);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  
 
  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Call blynkAnotherDevice every second
  timer.setInterval(100L, blynkAnotherDevice);
}

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

and this is for Nodemcu

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "E`tel";
char pass[] = "t`23";

// Bridge widget on virtual pin 1
WidgetBridge bridge1(V1);

// Timer for blynking
BlynkTimer timer;

BLYNK_WRITE(V5) {
  bool data = param.asBool();
  if (data ==1){
  Blynk.setProperty(V5, "labels", "MENU1", "MENU2", "MENU3");
  }
  
}

BLYNK_CONNECTED() {
  bridge1.setAuthToken("3`c"); // Place the AuthToken of the second hardware here
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Call blynkAnotherDevice every second
  //timer.setInterval(10L, limits);
}

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

@Gunner
so sir what should i do now?

is there any need to change?

First, your ESP Auths are all messed up.

Second, Unless you want to control something on the Mega from the ESP (and you do not appear to be doing such), then you do not need any Bridge stuff in your ESP sketch.

And third… this bool isn’t really necessary

BLYNK_WRITE(V5) {
  if (param.asInt) { // assumes a 1 or HIGH to continue
  Blynk.setProperty(V5, "labels", "MENU1", "MENU2", "MENU3");
  }
}

sir for privacy purpose i remove some digit from auth in nodemcu and mega.

OK… but since you left the Mega AUTH apparently whole and clear (and showed the whole ESP AUTH in that sketch as well) I just figured you were messed up on the rest and that might be why you are having issues :stuck_out_tongue_winking_eye: