How to run two tasks at the same time, currently im using nicla sense me i want to sample the values and transmit through Bluetooth at the same time
Now, after sampling it takes time to transmit the data through Bluetooth, and sampling is starting only after the data is transmitted.
how can i run two tasks parallelly like sampling and transmitting need to be done in same time
You can't actually run two tasks at the same time in a single core microcontroller. However, you can run things fast enough for a human to believe it happens at the same time.
This suggests you may be usign delay() in a code that should be non blocking.
here i need to sample the accelerometer values same time and BLE transmission need to be done at the same time
or else samples are pushed into queue and pulls all the values in queue in packets through BLE
is it possible to run different tasks at the same time?
yes, here im sampling accelerometer values of nicla sense me which consist in-built BLE, when sampling is continously done by nicla sense it stops the sampling when the bluetooth packets are transmitted
i am getting random delays between last sample and first sample after transmission, If we do the sampling as one task and BLE transmission as another task they will not overlap eachother and we can overcome this problem.
im using arduino nicla sense me board, im sampling accelerometer values of nicla sense me which consist in-built BLE and in-built acceleromter sensor, when sampling is continously done by nicla sense it stops the sampling when the bluetooth packets are transmitted
i am getting random delays between last sample and first sample after transmission, If we do the sampling as one task and BLE transmission as another task they will not overlap eachother and we can overcome this problem.
maybe possible using a microcontroller with two cores, e.g. ESP32
although I have worked on various industrial and research projects requiring data acquisition and transmission never needed to use such techniques
by using interrupts to sample data into buffer which are then transmitted in the main program (e.g. in loop() using Arduino IDE) it can appear that parallel operations are taking place at the same time
you could also look at using DMA - the sensor hardware writes data directly into a buffer in memory
what are your requirements - describe the projects? e.g. how many sensors, how many data samples/second, what is the data receiver, etc
So far you have not specified any numbers.
Depending on
how many datavalues
aquired at what frequency
how many databytes per vmeasured value
how much delay is accapetable between aquiring measurings
It will be sufficient to go on using your existing hardware
by just writing clever code
or it might be nescessary to change to a much faster microcontroller with DMA-features to realise what you want.
By only telling sending data by bluetooth and aquiring measurings at the same time
you have not specified anyting but saying "same time"
There is no such thing as making a microcontroller executing two different tasks at the EXACT same time down to the same femto-second
1 femto-second 0,000 000 000 000 001 Seconds
Not even the highest advanced supercomputer can do that,
because it would require a clock of 1000 GHz
And this is the reason why you have to specify numbers.
What do you mean by "real Time", e.g. every microsecond, every millisecond, every second, every minute, every hour???
the definition of "real Time" depends on the project requirements
for a start answer the questions asked by @StefanL38 in post 12
i need real-time values and for different frequencies upto 200hz, the accelerometer sensor in-built in nicla sense me give 4byte float value per axis, and delay will be our sampling rate.
in millisecond, and that interval or delay will be our sampling rate if we are reading the samples for every 5ms then our sampling rate will be 200hz for 1second