Go Down

Topic: Using Bluetooth serial on Arduino Nano BLE 33 (Read 2463 times) previous topic - next topic

luke_shields

Hi there,
I am very new to Arduino so it's a rather basic question. I have purchased an Arduino Nano Nano BLE 33 and have gotten bluetooth working with the ArduinoBLE library, however I wish to send data over serial using bluetooth like you would if you were using a module connected to the Rx and Tx pins. Could someone give me a brief description as to how to do that. Thanks very much

nuhash

Short answer:
That's not possible

Long answer:
You can emulate a Serial port by creating characteristics that mimic the serial pins on an arduino.
You need to make an RX and TX characteristics. RX is for receiving data/commands, TX is for sending data/commands.

Normally you would send data as raw bytes, you would have a format like:
<Byte 1-command><N bytes - parameters>

However, I think you want to use BLEStringCharacteristic. I can't remember the exact name, you will need to look that up.

Klaus_K

Could you please describe what your application level requirement is?

BLE allows you to provide the data to someone in a well formatted and described way. Using it as serial is like giving someone a book without table of content and page numbers.
There are many requests on this forum on how to send a bunch of data over serial basically asking for a nice protocol. Now, BLE has that and you do not want to use it.


If you have a good reason to do so. You can use a ByteCharacteristic and send one byte after another.

Arduino Reference BLECharacteristic

Beware, BLE is a wireless protocol and therefore can and will lose data in between. It is up to your application layer to make sure that is not an issue.

Tartaruga

Hello all

Thanks for the posts.

I tried to implement the code on my Nano BLE but I wanted to send double or float instead of charakters. The library supports the BLEFloatCharacteristic() function and if I want to send just one value, I can receive it with my smartphone. But I didn't get the right values. i.e. I send the float 54 and receive the value z. The Hex value is the right one. But I would like to send a array with 10 float values.

Does someone know how this can work?

Thank you very much for the support !

Klaus_K

How do these 10 float values differ from each other? Is it the same measurement done at 10 different times or are they physically different things e.g. temperature, pressure, humidity, ...?

Tartaruga

#5
Feb 14, 2020, 05:36 am Last Edit: Feb 14, 2020, 06:07 am by Tartaruga
The values are different. The idea is to send a data packages with different information to the smart phone (i.e. Acc data, Device Number, pressure value,...)

Why do you ask? Are the kind of data imporatant? Do you have an other solution?

It seems that  BLEFloatCharacteristic only have 2 arguments. So it would not possible to create a float array.
BLEFloatCharacteristic(uuid, properties)

I think I have to convert the float to char in the array, but I not sure if this is a proper solution.
Would it a better idea to create for each data an own characteristic ?

Thank you for the fast answer

Klaus_K

Would it a better idea to create for each data an own characteristic ?
Yes, that is what BLE is designed to be like. Every data gets its own characteristic. This way apps/central devices can decide what data they are interested in. Lets say you have two displays one cheap just shows the temperature and one "premium" shows you temperature and humidity. They can both connect to the same sensor read the data they can display and then disconnect again until they want to update the display.

If the characteristic is already specified by Bluetooth org you can look it up and use its UUID (gives you the chance that some tools can recognize the value). For other things just create as many new random 128 bit UUID as you need.

https://www.bluetooth.com/specifications/gatt/characteristics/

luke_shields

Thanks for the responses and apologies for the long delay, I thought I'd receive an email update if there was a response. Essentially I have telemetry data being generated by a small car going around a track, this includes 9 float values and 3 integers. This data is collected every 5ms so I didn't think BLE would be able to handle this kind of throughput, but as I say I have very little experience in this area so any advice is welcomed

Klaus_K

Have a look at the post #11 in the following thread. Its a test sketch I wrote.

https://forum.arduino.cc/index.php?topic=659562.0

This has basically all you need to get started. You just need to extend it with some more UUID for your values. Currently it updates the acceleration every 20ms. You can just change it to 5ms.

Let me know if you need some help understanding and modifying the code.

Tartaruga

Hey @Klaus

I create a characteristic for an integer and send the number 54 from the Arduino to the Smartphone. I use BLE Scanner for Android and I see a Value of 6 and a HEX of 0x36
I don't understand why the value is not similar t the Hex?

Thanks
Tartaruga

Klaus_K

#10
Feb 16, 2020, 11:08 pm Last Edit: Feb 16, 2020, 11:09 pm by Klaus_K
Decimal 54 is hexadecimal 0x36. Both are the same number and in ASCII code it is the character for 6.

Lookup ASCII code in Google. Its how characters are encoded. e.g. in "Hello world" This text is stored as numbers in your memory.

Just FYI, Unicode is similar but a modern version that allows all characters in the world including emoji.  :)

Go Up