Send data via Bluetooth

Hello,

I’ve spent some considerable time trying to get my head around setting up BLE and all that is needed to send data across to a PC via Bluetooth but it seems that I’m either looking at the wrong place or this simple task is indeed complicated.

My goal is to just send accelerometer readings over to a PC, just like you would with a serial connection. I know how to read the accelerometer values, but the sending part is unknown as of now.

I heard that there was an example script that showed how to blink LEDs using BLE but that script is gone now.

Does anybody have an example that does this simple transmission of one-way data? Or at least knows on where to start this journey?

What bluetooth module are you using?

TS-Brandon:
What bluetooth module are you using?

The included onboard module.

I’m assuming I’ll have to program it with ambiq_ble. Currently trying to get my head around that.

Would be really helpful if there was an example script of some sort that uses ambiq_ble to do something really simple.

I would also greatly appreciate an example for BLE.

Have you tried following this example? It may transferable to the EDGE board. I may go this route and if I do, I can report on how it went.

https://www.youtube.com/watch?v=EKmEYa9VxKM

Do you use Sparkfun library 2.0.5 with ArduinoBLE (make sure it is version 1.3.1) ? if so try to use attached that I have created.

example10_BME280.zip (10.9 KB)

Thanks Paul!

Just to understand quickly what your code does:

Is it correct that it provides two .ino files, one for each board and then those two boards will communicate with each other over BLE?

The newest ArduinoBLE lib I can find is 1.2.0. You mention 1.3.1 in your post. There is a 1.1.3 though. You meant this one?

hi

both times you are correct.

the ph file is peripheral to which BME280 is connected as indicated at the top of the sketch (the server is you like to call it that way)

the central file is the receiving part that communicates (the client)

And indeed the version is 1.1.3

Okay, I used 1.1.3. When compiling I get the following error though:

Arduino: 1.8.13 (Windows 10), Board: “SparkFun Edge, 921600 (Default), 115200, Ambiq Secure Bootloader (Default)”

(…)

“C:\Users\jante\AppData\Local\Temp\arduino_build_143908\sketch\example10_central_BME280.ino.cpp” -o “C:\Users\jante\AppData\Local\Temp\arduino_build_143908\sketch\example10_central_BME280.ino.cpp.o”

In file included from C:\Users\jante\Documents\Arduino\libraries\ArduinoBLE\src/ArduinoBLE.h:26,

from C:\Users\jante\AppData\Local\Temp\arduino_build_143908\sketch\bridge.h:11,

from C:\Users\jante\Documents\work\Arduino\arduino BLE\example10_central_BME280\example10_central_BME280.ino:52:

C:\Users\jante\Documents\Arduino\libraries\ArduinoBLE\src/BLETypedCharacteristics.h:60:61: error: ‘word’ was not declared in this scope

class BLEWordCharacteristic : public BLETypedCharacteristic {

^~~~

In file included from C:\Users\jante\Documents\Arduino\libraries\ArduinoBLE\src/ArduinoBLE.h:26,

from C:\Users\jante\AppData\Local\Temp\arduino_build_143908\sketch\bridge.h:11,

from C:\Users\jante\AppData\Local\Temp\arduino_build_143908\sketch\bridge.cpp:8:

C:\Users\jante\Documents\Arduino\libraries\ArduinoBLE\src/BLETypedCharacteristics.h:60:61: error: ‘word’ was not declared in this scope

class BLEWordCharacteristic : public BLETypedCharacteristic {

^~~~

C:\Users\jante\Documents\Arduino\libraries\ArduinoBLE\src/BLETypedCharacteristics.h:60:65: error: template argument 1 is invalid

class BLEWordCharacteristic : public BLETypedCharacteristic {

^

C:\Users\jante\Documents\Arduino\libraries\ArduinoBLE\src/BLETypedCharacteristics.h:60:65: error: template argument 1 is invalid

class BLEWordCharacteristic : public BLETypedCharacteristic {

^

Bibliothek ArduinoBLE in Version 1.1.3 im Ordner: C:\Users\jante\Documents\Arduino\libraries\ArduinoBLE wird verwendet

exit status 1

Fehler beim Kompilieren für das Board SparkFun Edge.


The last sentence is German and basically states that compiling failed

Are you are using library 1.20 instead of 2.0.5…

Dear Paul,

I believe I use the correct libraries. I attached a screenshot from which I think it is easiest to see the used libraries.

I tried both the peripheral as well as central example. For the peripheral example, I get a similar error message but the main error (the one highlighted in an orange box at the top) is "no matching function for call to ‘print(const char [22], uint8_t&)’. M

If I may add a more general question:

You may have seen in another thread that my final goal is to send pictures taken with the HM10B0 camera attached to the edge board to a laptop over BLE (via usb works already). I am not sure which route is the best: i) using arduino (more familiar, maybe limited functionality) or ii) through the SDK (less familiar, more functionality). Without describing the exact route, would you imagine that this task can be solved by using your examples and a lot of tweeking?

Thanks again! Your help is much appreciated!!

Jan

Hi

your picture is just missing what I need. Look in c:\users\jante\appdata\local\arduino15\packages\sparkfun\hardware. There is one folder. What is the name of the folder? 1.2.0 or 2.0.5 or ?

In the end it is sending data at highest speed as possible. Much is depending on the MTU size, which is 23 by default but can be renegotiates between the central and peripheral during and after connect.

I was indeed not using the correct one before. Sparkfun had provided another url for the json file which only allowed other versions of the core to be downloaded. Now, I have 2.0.5 installed and verified it as you described. By the way, I am also reading the odt readme file you provided on Github for the BLE example.

Unfortunately, when I compile the peripheral example I still get the error code:

'no matching function for call to ‘print(const char [22], uint8_t&)’

The central example throws a couple of errors but maybe it makes sense to first check that all libs are correct before proceeding, see attached picture. Can you confirm this?

Thanks Paul!

hi

I have just compiled the same peripheral and compiles without that errors What line of filename is mentioned with the error message. else share a hardcopy of the screen with the error message

I have attached copies of both the peripheral and central compiling reports as .txt. Is this fine or would you prefer another format?

error_peripheral.txt (80 KB)

error_central.txt (80.4 KB)

In the version that I had sent in the zip-file for the peripheral, line 348 reads

SERIAL_PORT.printf("Unknown request, %d\r\n", req);

it seems this is changed in your version to (print instead of printf)

SERIAL_PORT.print("Unknown request, %d\r\n", req);

change this to printf instead of print… and try again

Indeed. I changed it back to the original version and the compiling process advances a bit further but eventually throws an error again.

Shall I choose particular versions of the other libs suchs as BME280, Wire or SPI?

I attached the new report. I had to erase the middle part, otherwise the forum was surprisingly complaining that the file is too large with 100kB. The warnings (orange in IDE) is complete though.

error_peripheral2.txt (24.1 KB)

something happend to your SparkfunBME280 library. By default that includes SPI.h but apparently not in your version. Remove and reinstalled that SparkfunBme280 library.

I have deleted and reinstalled the BME280 lib and also tried different versions of it but the error persists. I also checked the .cpp and .h file of the lib and the .h file does include the SPI.h lib. I am still trying to find the problem but this is the current status.

What made me a bit suspicious (but maybe this is in fact normal) is that in the report it in the first lines it looks like the compiler cannot find the libraries since it displays “ResolveLibrary(SparkFunBME280.h)” for instance. However, at the very end of the report the directories of the libraries are correct.

try compiling example1 of BME280 Sparkfun… see what happens…