I have started an Arduino robotics project with an HC-05 Bluetooth sensor to send data to my PC for processing. In my design the Arduino is to serve as the slave which gathers data from sensors and sends it to the PC for processing and decision making, which will serve as the master.

My issue currently is that I do not know how to do multiprocessing with the Arduino. That is, I do not want the process that constantly reads data from the HC-05 bit-by-bit to block the data gathering and data transmission process. Ideally, I could have multiple threads for each process that depend on one another time-wise but not code code-execution wise and operate independently in the Arduino code.

Is there some kind of multi threading library that I can use on the Arduino side so that reading data transmitted from the PC won't block other processes/the execution of other processes will not make it so that the Arduino misses data being transmitted by the PC while it does other processing? Are there other solutions?

  • How is the HC-05 connected to your Arduino? SPI? UART (serial TX/RX)? – jose can u c Sep 14 '17 at 19:47
  • Connected via UART, basic serial TX/RX – Jack Frye Sep 14 '17 at 21:09
  • The arduino already uses an interrupt driven software buffer to receive data on active hardware serial ports. Overall though, this question is too broad to be a fit here. – Chris Stratton Feb 19 '18 at 6:29

Obligatory Nick Gammon reference: https://www.gammon.com.au/blink

Your first step is to study and run the BlinkWithoutDelay example. That show the most basic method to execute things at intervals without using delays, letting the CPU free to execute other things.

There are some scheduling libraries to do what you want, but learning to do it yourself will serve you to gain a much better understanding of Arduino.

FreeRTOS seems to be an interesting alternative for multitasking. No personal experience. Google "Arduino FreeRTOS" to find tutorials and examples.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.