• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Multitasking Hardware Serial, Software Serial, I2C device

Q&A Forum › Category: ESP8266 › Multitasking Hardware Serial, Software Serial, I2C device
0 Vote Up Vote Down
Suhaimi asked 7 years ago

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.

  1. void loop()
  2. {
  3.   modbus();
  4.   delay(1000);
  5.   getSerial();
  6.   delay(1000);
  7. }

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.

Question Tags: Serial communication
3 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

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.

0 Vote Up Vote Down
Suhaimi answered 7 years ago

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.

0 Vote Up Vote Down
Rui Santos Staff answered 7 years ago

I’m glad you found a work around. That definitely is a nice trick to solve that problem, but if you need real multitasking I would recommend taking a look at the ESP32. 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.