Stream Binary Data from Arduino Nano 33 BLE to PC via BLE

Hello,

It seems that ArduinoBLE.h does not contain functionality which allows for "faster" binary transmission of data to a PC via BLE. Do I need to write my own functionality, or is there a way to take advantage of Arduino's BLE API?

Thanks!

All transmission is in binary bytes so it's not clear what you are asking? What data are you trying to send?

The .writeValue function to send an arrary of bytes is

int writeValue(const uint8_t value[], int length);

And you can use this to send a generic chunk of data cast to bytes. There is a data size limit of 20 bytes based on a BLE core specification of 33 maximum bytes in the payload.

.writeValue((uint8_t *)&myData, sizeof(myData));
2 Likes

Thanks for the reply.

Yes right now, I refactored the BLEStringCharacteristic to a "BLEArrayCharacteristic" class and use the that interface for sending data with the function you listed:

int writeValue(const uint8_t value[], int length);

My overall goal would be to have a function like this:

BLEByteArrayCharacteristic deviceCharacteristic(RANDOM_UUID, BLERead | BLEWrite, 10000);
deviceCharacteristic.writeValue(packetBuffer, 10000);

All transmission is in binary bytes so it's not clear what you are asking?

I would like to send a large binary buffer via BLE for faster, one-shot transmission, rather than packet by packet. I hope this will help save clock-cycles for my normal operations on the board elsewhere, and improve my transmission rate.

What data are you trying to send?

I use a uint8_t array to contain <512 bytes of payload (multiple "packed" packets of 3-byte/5-byte sizes). Also, if there is a way for me to send a chunk of higher than the 512 byte threshold, that would be great. Serially, I have a solution right now that sends a buffer size of 10,000 bytes.

There is a data size limit of 20 bytes based on a BLE core specification of 33 maximum bytes in the payload.

I also reviewed the BLE Specification in the nRF52840 and found the maximum recommended BLE throughput is 1Mbps. Where do you find the 33 maximum payload bytes in the specification?

Why is BLE your choice for converting your project to wireless? Trying to generate large packets and arranging for larger MTU's supported on both client and server is heading down a different path from the short energy saving transmissions BLE was designed around.

I also reviewed the BLE Specification in the nRF52840 and found the maximum recommended BLE throughput is 1Mbps.

I think this is a radio transmission rate.

Here is a good article on the BLE maximum throughput.
https://www.novelbits.io/bluetooth-5-speed-maximum-throughput/

1 Like

Thanks for the resources. I worked out a method using that write capability/custom characteristic and the Python Bleak library.

async with BleakClient(device.address) as client:
                print(f'Connected to {device.address}')
                while(1):
                    packets = await client.read_gatt_char(CHARACTERISTIC_UUID)
                    if (packets):
                        print("Seq:", int.from_bytes(packets[0:2], 'little', signed=False))

Unfortunately, I have run into another hiccup: Bleak only get's ~6% of packets at a packet frequency of ~23kHz. Total transmission rate is ~33kbps over the expected ~552kbps.

Seq: 40
Seq: 58
Seq: 73
Seq: 89
Seq: 104
Seq: 120
Seq: 138
Seq: 151
Seq: 168
Seq: 182
Seq: 198
Seq: 213
Seq: 228
Seq: 243
...

Do you suggest any other non-BLE solutions? Or an alternative way to capture the BLE packets without so much loss?

My understanding is that you have a wired serial solution.

Serially, I have a solution right now that sends a buffer size of 10,000 bytes.

I would think that there might be a simple solution using classic bluetooth with an HC05 on the Arduino and a BT dongle on the PC if it doesn't have built in classic bluetooth.

With your serial wired solution, what baud rate are you using, and what program is running on the PC side?

What range are you looking for? The HC12 is like BT classic and uses a simple SPP protocol and is longer range than an HC05.

If you want to send large amounts of data to a PC then WiFi is a better choice.

BLE was designed for low energy and cheap silicon, not bandwidth. There are choices in the BLE specification like packet size that will allow to make the silicon design cheaper by setting how long the radio circuit can/must be active for a single transmission. Radio circuits require a lot of power when transmitting. That will heat the silicon and therefore change the characteristic. If you design a circuit that is active only for short bursts you may not need to compensate for this versus a design that requires the radio to be active for longer time.

As cattledog stated, this is the radio transmission rate. BLE is designed as burst packet radio. Short bursts allow the silicon to be inactive for most of the time which is good for modern silicon processes.

What distance do you have for the radio link? BLE is designed for short distances (basically inside a room). If you could use BLE for long distance you would waste energy. There are some extension with long range in BLE5.

My understanding is that you have a wired serial solution.

I should explain why I cannot use the serial solution at this time. Having my Nano connected/powered by a PC provides an invasive element to a sensitive power monitoring setup. To avoid any voltage leakage into the circuit, I need to have my Mac disconnected from the Nano.

I would think that there might be a simple solution using classic bluetooth with an HC05 on the Arduino and a BT dongle on the PC if it doesn't have built in classic bluetooth.

My PC should have classic BT. Is there an existing interface/library I can use on the Nano for classic bluetooth?

If you want to send large amounts of data to a PC then WiFi is a better choice.

That would be helpful. From the below graphic taken from here. I see that the BLE nor the BLE Sense have WiFi Capability. I would have to purchase an IoT.

image

What distance do you have for the radio link?

Right now, my distance is half a meter (~1.5ft).

No. The Nano33 is a BLE device only. Did you choose that device because of the BLE, or is there some other reason for the choice.

For a classic bluetooth solution (or perhap wifi as @Klaus_K suggests), another processor might be a better choice.

For a classic bluetooth solution (or perhaps wifi as @Klaus_K suggests), another processor might be a better choice.

I'll look into alternatives. I am beginning to lean on purchasing an Arduino IoT for its WiFi capability.

Make certain to take a look at the ESP32. It is very fast and powerful. It has built in BT/BLE/Wifi. It has a 12 bit ADC. They can be used with an Arduino IDE or the Espressif api.

The ESP32 development boards with USB interface are quite reasonably priced.

That is a bit short. Please check whether your antenna is damaged. Sometimes one of the small components in the green PCB gets ripped off. Happened to one of my boards without me noticing it. Others have reported this in the forum.

The Arduino Nano 33 IoT is a nice WiFi enabled Arduino. The SAMD21 microcontroller is used on other boards e.g., from Adafruit as well. It has good peripherals e.g., I like the analog comparator. Most of the BLE and WiFi code runs on the NINA module. The SAMD21 just runs some high level code of the library. The ArduinoBLE library works the same but does not rely on mbedOS.

1 Like

There is a new enhancement for BLE 5.2 which includes a Low Energy audio codec called LC3, which may deliver what you want:

Not sure which chipset has this available but I'm sure Nordic Semiconductor offers something:

Otherwise investigate the use of the BLE Object Transfer Profile or GATT Service. This is supposed to allow for bulk data transfers via a separate L2CAP connection-oriented channel.