hello,
I interfaced the arduino uno with esp8266 nodemcu, and triying to read data from esp8266 which received data from arduino uno .
I want to read those data from Esp8266 and process it for next further process ,but unable to trad those data which i receive through Softwareserial.h RX ,TX
my code is like this,
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX | TX
#include <DHT.h>
#define DHTPIN 6 //Pin D1
#define DHTTYPE DHT11
int incomingByte = 0;
DHT dht(DHTPIN, DHTTYPE);
char c = ' ';
void setup()
{
Serial.begin(9600);
mySerial.begin(115200);
dht.begin();
while (!Serial) {
;
}
Serial.println("hi esp");
float h = dht.readHumidity();
Serial.println(h);
float t = dht.readTemperature();
Serial.println(t);
}
void loop()
{
if (mySerial.available())
{
mySerial.write('t');
delay(1000);
mySerial.write('h');
delay(1000);
}
}
I change all data pattern like hex ,binary decimal but it hasn't worked.
Robin2
July 21, 2018, 10:28am
2
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
The technique in the 3rd example will be the most reliable.
You can send data in a compatible format with code like this
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker
...R
thanks for reply ,
but i still not understood it that how to recognise the data receive by the node mcu.
i just want to read the temperature data for arduino uno and receive by nodemcu to process further for task.
In order to do that what can I change in program for receive data from uno .....
pin connection are like these,
arduino uno pin 3 as TX - RX of nodemcu
arduino uno pin 3 as RX -TX of nodemcu
arduino uno pin Gnd - Gnd of nodemcu
arduino uno pin 3.3 - 3.3 of nodemcu
my nodemcu code arel like these......
#include <SoftwareSerial.h>
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
const char* ssid = "Vaahaka@321";
const char* password = "vaahaka@22018";
SoftwareSerial mySerial(13, 15);
IPAddress staticIP (192, 168, 1, 22);
IPAddress gateway (192, 168, 1, 9);
IPAddress subnet (255, 255, 255, 0);
void setup() {
Serial.begin(57600);
Serial.begin(9600);
pinMode(4, OUTPUT);
Serial.println();
Serial.println("Server started");
WiFi.begin(ssid, password);
WiFi.config(staticIP, gateway, subnet);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop()
{
Serial.println(t);
Serial.println(h);
}
so,what can i change in code to receive those data on nodemcu..............
mySerial.begin(115200);
Software serial may not work well for that high of baud rate.
Implement robin's code at the receiver side. Write complementing code for the transmitter
Based on his example 3 / 5, the basics of the transmitter:
1)
Print '<'
2)
Print temperature
3)
Print comma
4)
Print humidity
5)
Print '>'.
Robin2
July 21, 2018, 6:38pm
6
Start with SoftwareSerial working at 9600 baud. When you get everything working try a higher baud rate. I believe it should work at 38400 baud.
...R