My project require me to receive serial communication from a device.That device has lots of communication to do. I am not sure when it will stop talking. Most of the data is important. Some are not. I will filter that out once I receive the information. This device communicate through TX, RX pin on ESP8266.
While doing that, my ESP8266 must also communicate with a modbus slave, and read several sensors through I2C protocol. Modbus device communicate using software serial, on pin 13, and pin 15.
I already experimented both of them, with a delay. Make them working one after another. That is bad. It is however just to prove that my wiring is OK.
- void loop()
- {
- modbus();
- delay(1000);
- getSerial();
- delay(1000);
- }
Can I somehow multitasking? While receiver buffer from the serial, I want ESP8266 operate with another function. Can I do that? If yes, how? Because my priority is on that hardware serial communication, it makes me difficult to perform other task.
Thank you. Really appreciate if you can suggest anything.
Hi Suhaimi, unfortunately I don’t have any tutorials on multitasking with the ESP8266 or ESP32 at the moment. The ESP8266 is single core, so you can’t run tasks simultaneously.
However, the ESP32 has 2 cores, so you could potentially use a core for each task and have a reliable communication in your project.
Thank you, Rui.
I am however found another way for this task. That is not to wait communication to get return character “\n”. Instead, just proceed with another task while concat the character until found the return character. Simply put, append the character, one another. Until received return character, serial.print the whole result.
With that, i can multitask with other serial. It is not really multitask. But it did the trick.
Thanks again.