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?
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.
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:
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.
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.
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.
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.
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.
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.
Hello Elijah. I am very much a novice to Arduino code and am working on a first BLE program with 2 Arduino nano 33 BLE boards in my possession. I have looked at this post and I tried to make your code work on the boards in the IDE. Would you happen to have, or be able to provide, a complete short working example that I can upload through the IDE?
Excelent!, Sound very well!, Do you have limitation between the distance and bandwidth? What was the distance between two MCUs?Do you have a problem in bluetooth's laptop, right? Do you think that it's posible connection with a smartphone or pc directly?
I tested up to 10 meters (for 1.5Mbps); however, according to the specification in the NRF52840, the range should go much further.
At further distances (>100m), if you experience issues with packet loss, you may want to consider the PHY RADIO MODE. This will require some added configuration with the registers in the RADIO such as PDUSTAT. I recommend this over traditional ACKing if you're really trying to maximize the data output over those distances.
For transmission to a mobile device or PC, I do not believe it is possible for your computer to receive under Nordic's proprietary radio mode; however it definitely is via GATT (with a high throughput cost). Because the NRF52840 allows one to customize protocols to their needs, you may want to investigate various protocols and see what works best with your constraints. I actually asked Nordic awhile back on some recommendations while I was working through the design.
Thank you, I received recently my tiny machine learning kit with ble nano sense, I want to learn to use all capabilities of this mcu and how every component works. I did some examples using every sensor, but I would like to use a sensor and transmit the result of inference to my smartphone or laptop, for this reason your example is interesting.