Max Bluetooth and Bytes Cast testing

mhamilt's icon

Max Arduino Users!

Cross posting again as I'm still not sure which between the Discord, Slack and Forum is the most active.

I've created a couple of helper objects for interacting with BLE and casting data from bytes. It would be great if there was anyone out there wanted to test these and flag any issues / suggestions on the repository.

Source Audio's icon

Thanks for making this work.
I have no BLE unit at hand at the moment, but will definitely be interested
to test and I am sure that many will find this very usefull.

Is communication with midi BLE devices working ?
--
Byte cast - also very handy, would converting oposite way be an option ?
float to bin for example ....

mhamilt's icon

At the moment it is just polling of vanilla BLE devices. I saw Arduino BLE capable devices were becoming more popular, but the bluetooth examples haven't quite caught up. All the bluetooth examples I can find are Bluetooth 2.0 based and rely on a Serial RFCOMM interface, which just isn't how BLE works.

As a result, most students give up and move on to using OSC, which is fine. What I like about BLE though is the ad hoc / spontaneous nature of it. I like the idea that an audience member could come along to an installation and interact with it either via an Arduino BLE device or through some app on their phone. There is then an element of proximity involved which adds a nice restriction, but you can keep things entirely wireless. You also don't need a network infrastructure to send messages wirelessly. What you do need is something that will get the numbers from your, or your audience's, devices to where you want them to go (e.g. Max).

Is communication with midi BLE devices working ?

My understanding is that BLE MIDI is special case subset of the BLE standard.

From a macOS perspective you'd connect via:

Audio MIDI Setup -> Window -> Show MIDI Studio (⌘2) -> click Bluetooth icon (or ">>" menu -> Configure Devices -> Open Bluetooth Configuration)†

Then it should just appear as a normal midi devices.

Maybe a [`CABTMIDICentralViewController`](https://developer.apple.com/documentation/coreaudiokit/cabtmidicentralviewcontroller/) interface for Max may make the experience a little nicer.

For Windows, there doesn't seem to be as easy an interface with BLE MIDI. I'll need to grab a BLE MIDI and have a play around with the framework. My guess is that the connection is permanently kept alive or that it advertises with a 'notifying' property and push notifications are sent out††

What are current BLE MIDI device owner doing to connect with Max?


† so much for the three-click rule

†† completely unverified guess

mhamilt's icon

What are current BLE MIDI device owner doing to connect with Max?


MIDI Berry I assume

https://www.microsoft.com/en-us/p/midiberry/9n39720h2m05?activetab=pivot:overviewtab

mhamilt's icon

Byte cast - also very handy, would converting oposite way be an option ? float to bin for example ....

That's very doable. I assume casting float to it's raw bytes is handy for serial comms, but I believe that is taken care of within the object itself.

What use case were you thinking of?

Source Audio's icon

Mac and Midi BLE is no problem at all-
On windows, where restriction only one app at a time apply to composite midi devices
it might be of an advantage to talk midi BLE, outside of Midi communication.
------
float to binary - simply does not exist in max, I once had to help someone with a weird device
using float values sent as binary using sysex messages, had to roll js converter to achive it.

mhamilt's icon

As requested: https://github.com/mhamilt/max-byte-cast/releases/tag/0.1-alpha.2

Direct Download: https://github.com/mhamilt/max-byte-cast/releases/download/0.1-alpha.2/byte-cast.zip

There is an extra example in the ref page to cover the new functionality.

On windows, where restriction only one app at a time apply to composite midi devices it might be of an advantage to talk midi BLE, outside of Midi communication.


I will need to try out the Arduino BLE MIDI library https://www.arduino.cc/reference/en/libraries/ble-midi/ and see what I can get working.

Source Audio's icon

That's good news, thank you.
but


mhamilt's icon

The numeric types in max (int, float) are always long, 64-bit (8-bytes). The float would be in double (long float) format.

Max Patch
Copy patch and select New From Clipboard in Max.



There would need to be some kind of flag added to the `b` mode to decide how the user wants the data to be interpreted.

Suggestions welcome: https://github.com/mhamilt/max-byte-cast/issues/new

or fire something on here and I'll flag it.

Source Audio's icon

Some devices or at least some gadgets made with Arduino use single precision float
like for example buchla.com
They had external that converted float to 4 bytes array which then got sent as sysex via midi to program the Device.
I helped someone recreate that in Max because max external was outdated and undocumented.
Could not match the output till I realised that they used single precision floats.
sysex string using double float to sysex conversion crashed the synth.
---------
to byte-cast options
I don't know if it would be too much to put that many conversions and options into single object, but if you offer 4 byte float input one should also have it as output option

mhamilt's icon

I think you're right, this needs to be 2 objects to make it symmetrical, toBytes and fromBytes.

I can take the same source and just apply it to inlets instead of outlets. Shouldn't take too long to do.

mhamilt's icon

RE: BLE MIDI

Apologies, it has taken me a bit of time to finally look in to this.

In essence you can read data from a MIDI BLE device directly via the max-be object. This should mean you can bypass any restrictions on the Windows side. The way BLE MIDI works is by advertising a service with UUID: 03B80E5A-EDE8-4B33-A751-6CE34EC4C700 that has a characteristic with a notifying property with UUID: 7772E5DB-3868-4112-A1A9-F2669D106BF3

This means you can just subscribe to the BLE MIDI characteristic directly.

Apologies that it is a bit messy, but this would translate to a patch, using max-ble, to roughly look like:

Max Patch
Copy patch and select New From Clipboard in Max.


I will need to fully implement subscribing to characteristics on the Windows side, it works on macOS though.

I now realise I don't have a method to unsubscribe either, which is a bit of an oversight. I will look to implement that in the next week or so.

JF's icon

Hi! Very nice objects! I'm new to BLE, and I wonder if it's possible to send out data to the Arduino BLE with this object? More specifically, is there a way to do this example, but connecting with Max instead of a phone app? https://docs.arduino.cc/tutorials/nano-33-ble-sense/bluetooth
Thanks!

mhamilt's icon

If I implemented the functionality you could 100% send data out. What I wasn’t sure of was what the “story” of sending data via ble would look like

if you fancy being a guinea pig, could you draw up a patch of what you would like the workflow to be and post it here? even better, include it as part of an issue on the git repository

JF's icon

I've added a comment to issue #14. Initially I'd created a new issue for it, but then realized it was a duplicate... I closed the duplicate and added the comment to #14. Here is a small patch of an example of how it could be implemented in a patch.

Max Patch
Copy patch and select New From Clipboard in Max.

Francesco's icon

Hi!
max-ble is a very powerful and fascinating tool, I appreciate it very much.

In your opinion, will there be a time for a max-ble extension available in RNBO? This would definetely change the rule of the game...

thank you so much for your kind reply.

F

mhamilt's icon

From the RNBO thread and this thread I don't think the functionality to include max externals is quite there yet.

The BLE object is there to try and expose the bluetooth APIs for windows and macOS. Feeding that through a transcompiler like RNBO I can see getting messy quite quickly.

Never say never, it isn't on the cards right now though.

Francesco's icon

Clear.
thank you for your Kind reply
F

Jiawei chong's icon

I successfully searched for my small bluetooth accelerometer sensor and it connected successfully, but I'm not sure how I should properly subscribe to get the data.

Connected to WT901BLE67

Device: 8123FF39-9271-3274-5799-9B4E7997163B Service (0000FFE5-0000-1000-8000-00805F9A34FB) Char: (0000FFE9-0000-1000-8000-00805F9A34FB ) : Value: (null) Properties: Write Without Response, Write

Device: 8123FF39-9271-3274-5799-9B4E7997163B Service (0000FFE5-0000-1000-8000-00805F9A34FB) Char: (0000FFE4-0000-1000-8000-00805F9A34FB ) : Value: (null) Properties: Notify

I get the result that I can subscribe and return data when I connect to this Bluetooth device with LightBlue. I'm looking forward to someone's answer, thanks!

!!!
So far the connection is good and the data is accepted as normal, I would like to record a video explaining it to later newcomers