BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to add lables when my mega2560 digitalread is HIGH

hardware
#1

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);
  
}
0 Likes

#2

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.

0 Likes

#3

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…

0 Likes

#4

done sir!

0 Likes

#5

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

0 Likes

#6

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?

0 Likes

#7

Have you tried to look into the sketch builder?

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

0 Likes

#8

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.

0 Likes

#9

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");
  }
}
0 Likes

#10

Yes sir @GunnerTechTools 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;

0 Likes

#11

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.

0 Likes

#12

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 @GunnerTechTools. @Dmitriy. @BlynkAndroidDev

0 Likes

#13

@GunnerTechTools

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

0 Likes

#14

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.

0 Likes

#15

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();
  
}
0 Likes

#16

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();
}
0 Likes

#17

@GunnerTechTools
so sir what should i do now?

is there any need to change?

0 Likes

#18

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");
  }
}
0 Likes

#19

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

0 Likes

#20

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:

0 Likes