Oscilloscope over bluetooth

PhilipK

Member
Licensed User
Longtime User
Just wondering if I’ve got something fundamentally wrong:

Using 2 Android devices and the example ‘Oscilloscope’ code from your site.
Datastreaming Device ’A’ sends sine wave data to the other device ‘B’ (Oscilloscope) over Bluetooth. Working fine. Can see numbers arriving in ‘B’.

Have a click event to hear data coming in at 1 second intervals. See data for variable ‘CurVal’ changing in log window as expected (a slow sine wave).

Bluetooth code in ‘B’ is in a service module attached/added to Oscilloscope’s main module.

Data for the GetValues routine (Oscilloscope main) is retrieved from a variable in the service module called: GetBTData
Main module
Sub GetValues
Dim i As Int
For i = 0 To CurvesNb
CurveVal(i, ii) = GetBTData.CurVal
Next
End Sub

All simple stuff....

Why does the data transfer stop when I press the oscilloscope's ‘Start’ button? The clicking stops and only the last value in GetBTData.CurVal is plotted? Isn't the service module using a separate thread?

On pressing the oscilloscope's ‘Stop’ button, it appears that the new incoming data has been held in the BlueTooth buffer, as I hear a long blast of clicks, before it returns to the correct 'click per second' interval.

Help!
 

Vader

Well-Known Member
Licensed User
Longtime User
If it's anything like the USB Serial library, anything in the main thread that is in a DoEvents() blocks all processing of events, even if they are generated from a separate thread.

The solution to this particular problem is to use a timer to look for data, rather than solely rely on events.

I don't have example code as the above description is my version of what was described to me, but I haven't been able to get my project to work yet.

Don't know if that helps, but good luck.
 
Upvote 0

PhilipK

Member
Licensed User
Longtime User
Thanks for the advice.

Before this thread, I was using a timer but found that I had data synch problems. So I changed it to the InitializePrefixed AsynchStream NewData routine. Works well.

Aaaah! Have found an error while writing this post: Data sent from device 'A' using InitializePrefix and have selected the non-prefix initialize on the receiving device 'B'!!!

Hopefully, this is the culprit!

Will test later and report back.

Thanks.
 
Last edited:
Upvote 0

PhilipK

Member
Licensed User
Longtime User
Thanks Klaus.

BTW, changed the initialise to initialiseprefix and no change.

The oscilloscope code has been left as is. Except that I have introduced a data variable into the GetValues routine. The data variable is seeded in the Asynch_newdata routine in the service module.

*******************************************************
ISSUE RESOLVED HERE
*******************************************************

Your suggestion of tuning the timer seems to have done the trick. Now have a sine wave trace on the scope! It appears that the timer was running too fast to process the data.

There is a short delay before it starts plotting and I'll need to tinker about with the timer setting(s) to tune.

Will make a comparison between data being sent from device 'A' and what is shown on device 'B'. Certainly getting there, now!

.
A Breakthrough - Many Thanks

PhilK
 
Upvote 0
Top