Need help: ESP-01 (Blynk) + UNO (normal sketch)

hello all,

i have project :

ESP-01 = Running Blynk Sketch and as Commands Sender to control Arduino pin through RX TX
UNO = Running normal sketch (without Blynk) proccessing command from SoftwareSerial from ESP-01

everything is goes normal and i can control (send command) my UNO, the problem is :
ESP-01 can send Serial.print () or Serial.write () and,UNO can take it as command and process it but
How can i get data value from Input (sensor or button) from my UNO and send it to ESP-01?

i have tried to send the value from UNO using ā€œESPserial.printā€ or ā€œESPserial.writeā€ but there are no data is coming to Serial Monitor of ESP-01.


Before someone asks why use this scheme, because UNO has FLASH & SRAM limit if I only use UNO (Blynk) and ESP-01 as shield (AT COMMAND), UNO can not accommodate sketch and run out of memory (Blynk library, sensor library etc). UNO has many pins, ESP-01 has a large FLASH memory but has few pins. so I divide the sketch into ESP-01 (Blynk Library and virtual pins commands) & UNO as brain (process sensor input output)

But why do people buy nasty ESP-01ā€™s when you can buy a plug and play ESP for the same money?

The best internet resource for reading Serial data is Robin2ā€™s tutorial at http://forum.arduino.cc/index.php?topic=39645020.

Combine this with the SimpleTimer and SoftwareSerial between ESP and Arduino as per https://www.arduino.cc/en/Tutorial/SoftwareSerialExample24 and you are good to go.

Well, your issue is NOT Blynk relatedā€¦ perhaps look at those other recommended forum & siteā€¦

Closing this topic.

@Fira As requested, I will reopen this so you can post your Blynk code hereā€¦ I still suspect your issue is in your serial code, not due to a Blynk bugā€¦ but lets take a look and see.

Please format it properly after posting itā€¦as required in the Welcome Topic.

Thanks man. sorry if i ask this, iā€™m new with this stuff,

this is my UNOā€™s sketch

// UNO Sketch Part Of ESP-01
#define ledPin 13
#define fanPin 12

#define serialbufferSize 15 
// End of Constants

// Now the real varibles
#define debug 0
char inputBuffer[serialbufferSize]   ; 
int serialIndex = 0; // keep track of where we are in the buffer
// End of real variables

#include <SoftwareSerial.h>
SoftwareSerial ESPserial(7, 4); // RX | TX ESP-01 Connection 
#include <IRremote.h>

IRsend irsend;

const unsigned int AC_irSignalONOFF[] PROGMEM = {9172, 4516, 600, 1684, 596, 1688, 596, 556, 592, 560, 592, 564, 592, 568, 592, 572, 592, 1692, 596, 548, 596, 1688, 596, 1692, 592, 560, 592, 564, 592, 568, 592, 568, 596, 560, 592, 548, 592, 552, 592, 1688, 596, 560, 596, 560, 592, 568, 592, 568, 592, 560, 592, 548, 592, 1688, 596, 556, 592, 560, 592, 1700, 596, 1700, 596, 568, 596, 1692, 596, 548, 596, 552, 592, 556, 592, 560, 596, 564, 592, 564, 596, 568, 592, 560, 592, 548, 596, 552, 592, 556, 596, 556, 596, 560, 596, 564, 596, 568, 592, 544, 592, 8064, 596, 1684, 596, 552, 592, 556, 592, 560, 592, 564, 592, 564, 596, 568, 596, 1692, 596, 1684, 592, 552, 596, 556, 592, 1696, 592, 1704, 592, 564, 596, 568, 592, 560, 592, 552, 592, 552, 592, 556, 596, 556, 596, 560, 596, 564, 592, 572, 592, 560, 596, 548, 592, 552, 592, 556, 592, 560, 592, 564, 592, 568, 592, 568, 596, 556, 596, 548, 592, 552, 592, 556, 596, 556, 596, 560, 596, 564, 596, 568, 596, 560, 592, 548, 596, 552, 592, 556, 592, 560, 592, 564, 592, 568, 592, 572, 596, 556, 596, 548, 596, 548, 596, 556, 592, 560, 592, 564, 592, 564, 596, 568, 592, 560, 592, 552, 592, 1688, 596, 1692, 596, 1692, 596, 564, 592, 1704, 596, 568, 592, 540, 596, 8064, 596, 552, 592, 552, 592, 556, 592, 560, 592, 564, 592, 568, 592, 568, 596, 556, 596, 1684, 596, 552, 592, 556, 592, 560, 592, 564, 592, 568, 592, 568, 596, 560, 596, 544, 596, 552, 592, 556, 592, 556, 596, 560, 592, 568, 592, 568, 596, 556, 596, 548, 592, 552, 592, 556, 592, 560, 592, 564, 592, 564, 596, 568, 592, 560, 592, 548, 596, 552, 592, 556, 592, 1696, 592, 564, 596, 564, 592, 572, 592, 560, 592, 548, 592, 552, 596, 552, 596, 556, 592, 564, 592, 568, 592, 568, 596, 556, 596, 1684, 596, 552, 592, 556, 592, 1696, 596, 564, 592, 568, 592, 568, 592, 544, 624}; //AnalysIR Batch Export (IRremote) - RAW

int khz = 38;

#include "DHT.h"
#define DHTTYPE DHT11
#define DHTPIN 10

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(9600);
  ESPserial.begin(9600);
  pinMode(ledPin,OUTPUT);
  pinMode(fanPin,OUTPUT);
  dht.begin();
}

void loop() {
 // Notice how the main loop is very simple and the functions 
  // seperate the logic into easily manageable parts
  if (CheckSerial()) DoCommand(inputBuffer); 
  readTemp ();
  delay(1000);
 

    // Do other stuff
}

boolean DoCommand(char * commandBuffer)
{
  
  // Standard way to handle commands
  if (strcmp(commandBuffer , "V0 1")==0) // ACPOWER ON OFF
  {
    digitalWrite(ledPin,HIGH);
    sendRAW_Flash(AC_irSignalONOFF, sizeof(AC_irSignalONOFF)/sizeof(int),khz); //send AC signal #1 @ 33kHz
    delay(5000); //a good idea to have gaps between signals
    digitalWrite(ledPin,LOW);
  }

    else if (strcmp(commandBuffer , "V4 1")==0) // FAN Relay
  {
    //fanOn= !fanOn;
    digitalWrite(fanPin,1);
    
  }
  
  else if (strcmp(commandBuffer , "V4 0")==0) // FAN Relay
  {
    //fanOn= !fanOn;
    digitalWrite(fanPin,0);
    
  }

  else { 
    Serial.print("I dont understand you \nYou said: ");
    Serial.println(commandBuffer);
      //    Do some other work here
    //    and here
    //    and here
  }
 
  
  // debug code after here
#if debug
  Serial.print("Free Ram = "); Serial.println(freeRam(), DEC);
#endif  
return true;
}

/*
Checks the serial input for a string, returns true once a '\n' is seen
users can always look at the global variable "serialIndex" to see if characters have been received already
*/
boolean CheckSerial()
{
  boolean lineFound = false;
  // if there's any serial available, read it:
  while (ESPserial.available() > 0) {
    //Read a character as it comes in:
    //currently this will throw away anything after the buffer is full or the \n is detected
    char charBuffer = ESPserial.read(); 
      if (charBuffer == '\n') {
           inputBuffer[serialIndex] = 0; // terminate the string
           lineFound = (serialIndex > 0); // only good if we sent more than an empty line
           serialIndex=0; // reset for next line of data
         }
         else if(charBuffer == '\r') {
           // Just ignore the Carrage return, were only interested in new line
         }
         else if(serialIndex < serialbufferSize && lineFound == false) {
           /*Place the character in the string buffer:*/
           inputBuffer[serialIndex++] = charBuffer; // auto increment index
         }
  }// End of While
  return lineFound;
}// End of CheckSerial()

#if debug
// check free ram
int freeRam () 
{
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}
#endif

void sendRAW_Flash(const unsigned int * signalArray, unsigned int signalLength, unsigned char carrierFreq) {

  irsend.enableIROut(carrierFreq); //initialise the carrier frequency for each signal to be sent
  
  for (unsigned int i=0;i<signalLength;i++){
    //tmp=pgm_read_word_near(&signalArray[i]);
   // tmp=cleanPanasonic(tmp); //not needed
    if (i & 1) irsend.space(pgm_read_word_near(&signalArray[i]));
    else irsend.mark(pgm_read_word_near(&signalArray[i]));
  }
  irsend.space(1);//make sure IR is turned off at end of signal

}

void readTemp (){
  float t = dht.readTemperature();
  if (isnan(t) ) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
  ESPserial.println(t);
}

And this is my ESP-01 Sketch (that run Blynk)

#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[] = "authTOKEN";


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "MYSSID";
char pass[] = "MYSSIDPASSWD";
BlynkTimer timer;

void setup()
{
  // Debug console
  Serial.begin(9600);
  
  Blynk.begin(auth, ssid, pass, "local ip xxx.xxx.xxx.xxx");
}

BLYNK_WRITE(V0){ //AC-POWER//
  int pinValue = param.asInt();
  if (pinValue==1) {
  Serial.print("V0 ");
  Serial.println(pinValue);
  }
}

BLYNK_WRITE(V4){ //FAN//
  int pinValue = param.asInt();
  if (pinValue==1) {
  Serial.print("V4 ");
  Serial.println(pinValue);
  }
  else{
  Serial.print("V4 ");
  Serial.println(pinValue);
   
  }
}


//////////////////////////terminal////////////////
void loop()

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

Blockquote

every thing is fine, i press button V0 on my phone and UNO can process it and turn my AC ON or OFF, if i Press V4 button on my phone UNO turn ON/OFF the Fan relay.

I just neeed grab ā€˜tā€™ (temperatur) value from uno and send it to ESP-01 as data, but Serial Monitor on ESP cannot showing it.( iā€™m stuck here). if i just use normal sketch i mean without Blynk Stuff, yes i can read it on ESPā€™s Serial Monitor, but if i run with Blynk library ESPā€™s Serial Monitor never Print/Showing incoming data from UNO.

sorry if this make you all get confused, English is not my primary languange, i hope you get what i mean to. tks

dear costas, i have bought them long time ago and maybe i have 3 or 4 pairs of them in my BOX TOYS. should I throw it all in the garbage? its not about the same value prices, itā€™s about how can we use them and optimized all of them.

I would certainly stop using them as you waste a lot of time with ESP-01ā€™s.

@Fira In your Blynk sketch, you do not have any function running that would sense, and thus grab, any incoming serial dataā€¦ that is why it is not ā€˜workingā€™ā€¦

However, the problem you will run into if you implement such a scan of the incoming serial buffer, is that getting it to line up with serials timing while still not blocking Blynkā€™s own background processes.

It is not going to be easy at allā€¦ and is NOT something you will get much support for here, as it is well outside of what Blynk is designed to do in the first place.

I will make a recommendation to use another serial/i2C based data transfer library instead of trying to handle the Serial timing yourselfā€¦ But again, it is NOT something you can get support for on this forum.

If I understand correctly, it will work with ESP, but only in one capacity, I think as Master not as Slaveā€¦ so you will need to play around with it to see if it will work for you.

I will mark this topic solved, as an answer has technically been supplied - ā€œPossibly doable, but not officially supportedā€, but I will leave it open.

If you do manage to figure out how to combine the somewhat seperate worlds of Arduino/serial transfer and Blynk, feel free to share your progressā€¦ and even ask questions if you think they are applicable to the Blynk side of the operation.

Ok then, case closed. Iā€™ll find another way. :slight_smile:

Thank you all.

1 Like

thank you for suggesting using I2C instead of Serial connection.

Now I can read one, two even more sensors in arduino uno and display them in Blynk app, and control the uno output through I2C and virtual pin

Now my ESP-01 has many pins with the help of UNO as slave :slight_smile:

1 Like