Arduino ESP8266 send data and receive from Arduino Micro

Hello!
I'm using an NODE MCU board running Arduino IDE and another Arduino board; lets say a pro micro.

Esp 8266 runs as a MQTT client and it send data to my mqtt server.Temperature,Humidity and control relays.

I see that normal libraries are not compatible with my esp8266 running on arduino, so i'm looking to connect some sensors to my arduino micro. My micro should send data from sensors via serial and receive simple commands to trigger some functions or pins, etc.

Can you help me with a simple example for sending/receiving simple numeric data betwen Arduino esp8266 and Arduino micro and do tasks?

Thank you!

Hi rotarucosminleonard,

I think, I am currently working on, what you are looking for.
I use an ESP8266-01 as "MQTT adapter" on an Arduino UNO. Later I will use an ATtiny85 instead of the UNO, because the device should by battery powered.
The idea is to use the tiny for my weather station to “collect” pulses from temperature and wind sensors. From time to time the tiny will wakeup the ESP8266 to send the collected data to my Raspi broker.

I connected both devices via TX/RX lines and implemented a simple ASCII protocol to send commands to the ESP8266, like:
"p|my/topic|my-data"
to publish data.
I use the first character to distinguish different commands, the '|' character to separate parameters and a trailing zero as end tag.
The ESP8266 will respond with:
"R|ok"
or
"E|error description"
Currently, I am able to send messages to the broker, the other direction is not planned so far and makes no sense for a weather station.

But I can't provide you a simple example. A communication protocol between two devices is always a little bit tricky. If you are interested in a read-to-use solution, give me some time to bring it into a form so that it can be useful for someone else…

Regards
Joe

i tried this, but i cant create a link bethen them:

On arduino Micro:
/*
Some Sample code of how to use your IR remote

  • Lets get started:

The IR sensor's pins are attached to Arduino as so:
Pin 1 to Vout (pin 11 on Arduino)
Pin 2 to GND
Pin 3 to Vcc (+5v from Arduino)

*/

#include <IRremote.h>

int IRpin = 3; // pin for the IR sensor
int LED = 5; // LED pin
IRrecv irrecv(IRpin);
decode_results results;

boolean LEDon = true; // initializing LEDon as true

void setup()
{
// Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(LED, OUTPUT);
}

void loop()
{
IRclone();

}

int IRclone()
{

if (irrecv.decode(&results))
{
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}

if (results.value == 3772782313) // this is where you put in your IR remote button #
{
Serial.begin(9600);
if (LEDon == false) {
digitalWrite(LED, HIGH);
LEDon = true;
}
else {
digitalWrite(LED, LOW);
LEDon = false;
}

}
results.value = 0;

}

On arduino Esp8266:

#include <SoftwareSerial.h>

SoftwareSerial swSer(14, 12, false, 128);

void setup() {
Serial.begin(9600);
swSer.begin(9600);

Serial.println("\nSoftware serial test started");

for (char ch = ' '; ch <= 'z'; ch++) {
swSer.write(ch);
}
swSer.println("");

}

void loop() {
while (swSer.available() > 0) {
Serial.write(swSer.read());
yield();
}
while (Serial.available() > 0) {
swSer.write(Serial.read());
}

}