BLE write to Arduino Nano 33 BLE is unsuccessful

42 views (last 30 days)
I am trying to communicate with a Arduino Nano 33 board using BLE. I have created BLE service and characetristic with read and write capability on the Arduino board. I can read from the characteristic into MATLAB, but when I try to write to it nothing is received on the Arduino. It works fine when I use a BLE app on my Android phone, and I can read or write without any issue. I have used the BLE toolbox in the past to communicate with Adafruit's Bluefruit LE and it worked fine. So, I am not sure if this an Arduino issue or MATLAB. I am using MATLAB R2020a on Windows 10PC. Any suggestions?
Here is a code snippet I use to write to the BLE -
bleobj = ble("BLEname")
ble_Characteristic = characteristic(bleobj,"19B10000-E8F2-537E-4F6C-D104768A1214","19B10001-E8F2-537E-4F6C-D104768A1214");
write(ble_Characteristic, WirelessMsg, "uint8");
val = read(ble_Characteristic);

Accepted Answer

Nikunj Bhagat
Nikunj Bhagat on 3 Aug 2020
Edited: Nikunj Bhagat on 3 Aug 2020
I finally figured out a solution and I am posting it here in case someone else faces this issue. As I had suspected in my original post, this turned out to be an Arduino issue and to a lesser extent a Windows thing. In Arduino when you create a custom characteristic you can choose the option to read/write/notify/indicate. These are the standard 4 characteristic properties. There is also another property 'BLEWriteWithoutResponse', which hasn't been discussed a lot on forums. And it is this property that needs to used in your Arduino Nano33 BLE sketch.
The difference between BLEWrite and BLEWriteWithoutResponse is that the latter doesn't expect an acknowledgement or approval for MATLAB's request to write to the characteristic. If your Arduino is setup to send acknowledgements in response to Write request, then BLEWrite will work too (I think, but I haven't tried this). Now, the other weird thing is (which is why I said its a Windows thing), it didn't matter on a MAC computer whether the Arduino was configured with BLEWrite or BLEWriteWithoutResponse. It worked perfectly well on a MAC computer running MATLAB. But, on a Windows machine, it did make a difference.
Finally, here is a snippet of my Arduino sketch, just to show clearly how the custom characteristic must be setup -
#include <ArduinoBLE.h>
#include <Arduino_LSM9DS1.h> // 9 axis IMU on Nano 33 BLE Sense board
// BLE Service
BLEService imuService("917649A0-D98E-11E5-9EEC-0002A5D5C51B"); // Custom UUID
// Matlab writes to this characteristic:
BLEByteCharacteristic WriteChar("917649A1-D98E-11E5-9EEC-0002A5D5C51C", BLERead | BLEWriteWithoutResponse);
void setup(){
void loop(){

More Answers (1)

Menghan on 12 Aug 2020
Hi Nikunj,
This is a known issue in MATLAB BLE characteristic interface. See external bug report here.
If you use BLEWrite in Arduino sketch, you can call characteristic write function with the "withresponse" parameter. This is an optional parameter and should default to "withresponse" if not specified. It is however not the case in current code, hence a bug.


Find more on Arduino Hardware in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!