I am sending information between my nodemcu esp8266 and my arduino mega.
The two are connected from pin D5 (ESP)---->RX2(MEGA). tx--->rx because i am only sending the arduino. But the information is sent too slowly with delays on each line. Here is the mega code:
Serial2.begin(9600);
if(Serial2.available() > 0){
character = Serial2.read();
if(character == '#'){
Serial.println(message);
if(message.startsWith("ho")){
message.remove(0,2);
hours = message.toInt();;
}else if(message.startsWith("m")){
message.remove(0,1);
minutes = message.toInt();;
}else if(message.startsWith("s")){
message.remove(0,1);
seconds = message.toInt();
}else if(message.startsWith("t")){
message.remove(0,1);
outTemp = message.toFloat();
}else if(message.startsWith("hu")){
message.remove(0,2);
outHum = message.toFloat();
}
message = "";
Serial.println();
}else{
message.concat(character);
}
}
and the code from the esp:
SoftwareSerial s(D6,D5); //RX,TX
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
s.begin(9600);
void loop() {
ArduinoCloud.update();
// Your code here
if(temperature != 0){
s.print("ho"+time_hours+"#");
s.print("m"+time_minutes+"#");
s.print("s"+time_seconds+"#");
s.print("t"+String(temperature)+"#");
s.print("hu"+String(humidity)+"#");
Serial.println("ho"+time_hours+"#");
Serial.println("m"+time_minutes+"#");
Serial.println("s"+time_seconds+"#");
Serial.println("t"+String(temperature)+"#");
Serial.println("hu"+String(humidity)+"#");
delay(500);
}
}
I know i have delay(500) but that doesnt explain that each lineof infortmtion is beingsend every like 6 seconds.
for exmaple the mega gets:
ho19
six seconds later
m30
six seconds later
s50
.....