Go Down

Topic: Serial data not appearing in a BLE characteristic  (Read 532 times) previous topic - next topic

Jason_Townsend

May 22, 2018, 01:47 pm Last Edit: May 22, 2018, 01:47 pm by Jason_Townsend
Hi all,

This is a complicated post so please bear with me.

I am using an Arduino Uno with an SH-HC-08 bluetooth low energy adapter.  I understand that the SH-HC-08 is similar to the HM-10 and is built on a TI chip.  I can get the arduino to transmit serial data through the bluetooth adapter using the code below:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); // RX, TX
void setup(void)
{
 // start serial port
 Serial.begin(9600);
 // Start a serial connection to the BLE module
 mySerial.begin(9600);
}
void loop(void)
{
 float tmp;
 tmp = 26.6
 char c;

 if (mySerial.available() > 0) {
   c = mySerial.read();
   Serial.print(c);
 } else {
   mySerial.print(tmp);
   Serial.println(tmp);
 }
 delay(5000);
}

Using a serial monitor app on my android phone, I can see the the value from tmp being sent out.

From that same serial monitor app, I type in a string and send it to the bluetooth adapter on the arduino.  It appears in the BLE characteristic FFE0 which is what I want.  

However, when I send my data from the arduino to the bluetooth adapter, although it can be read through a serial monitor, it doesn't appear in the BLE characteristic FFE1 like it should.  

Can anyone see what I am doing wrong in my code or what I have missed?  I'm sure that data sent serially to the bluetooth adapter should appear in the characteristic FFE1.

Thanks,
Jason

PaulS

Quote
Can anyone see what I am doing wrong in my code or what I have missed?
That code makes no attempt to alter any BLECharacteristic, so I can't see why you expect the data to be part of some BLECharacteristic. What have I missed?
The art of getting good answers lies in asking good questions.

Jason_Townsend

Hi,

Thanks for your reply.  As far as I know there isn't a library for that bluetooth adapter, so all I am doing is writing as a serial connection.  As far as I understand, with BLE the characteristic FFE1 is where serial output is placed (20 bytes anyway).  The bluetooth adapter has no AT commands with which to set a characteristic so the only exposed characteristic available is FFE1.  I could be wrong and if so would be more than grateful if someone can correct me.

Thanks,
Jason

Robin2

I think you need to educate us as to what a BLE Characteristic is - or post a link to a datasheet that explains it.

Also post a link to the datasheet for the BLE device you are using.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Jason_Townsend

Hi Robin,

It's a bit convoluted and that's probably why I'm stuck.

The bluetooth adapter is a Bluetooth 4.0 (Bluetooth Low Energy) device which is a cheap generic adapter.

I have attached the manual for the HC-08 module but as with most cheap modules, it's mounted on another board with some power modulation hardware to allow you to use up to 5.5v. 

Bluetooth low energy (BLE) characteristics and services are the means by which a device advertises itself.  Some characteristics can be read from and/or written to. 

The link below is to an article on adafruit which may help with explaining BLE characteristics but it is using an adafruit bluetooth adapter for which there is a software library.

https://learn.adafruit.com/reverse-engineering-a-bluetooth-low-energy-light-bulb/overview

Thanks,
Jason

Robin2

I am interested in learning more about BluetoothLE myself, but I can't see anything about Bluetooth Characteristics in the PDF you linked to. It only mentions electrical characteristics.

If the device you are using is not software compatible with the Adafruit device then you need to post a link to the datasheet for your device.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Nick_Pyner

#6
May 23, 2018, 05:23 am Last Edit: May 23, 2018, 05:54 am by Nick_Pyner
As far as I know there isn't a library for that bluetooth adapter, ............... As far as I understand, with BLE the characteristic FFE1 is where serial output is placed (20 bytes anyway).  The bluetooth adapter has no AT commands with which to set a characteristic so the only exposed characteristic available is FFE1. 
I'm betting the above is nonsense, and BLE Characteristic FFE1 particularly is irrelevant technobabble.  In the light of what you have done ,
Quote
I can get the arduino to transmit serial data through the bluetooth adapter using the code below
by successfully using a serial connection, the sort of thing everybody knows, loves, and understands, I think you need to be a lot more forthcoming about what you want to do in addition.

While your code does something, a triumph in itself, the input section is incomprehensible, and I rather feel that your real problem is that you simply don't understand serial input, and all this BLE Characteristic stuff is just claptrap. In short, even BLE bluetooth is simpler than you think. 

If I'm right, you got lucky, the one to tell you all about that wrote reply #3, and he doesn't need to be educated about BLE Characteristics. If I'm wrong, you could be on the wrong tram entirely.

You might get some better insight into BLE on the Martyn Currey website. He might not know it all but, within the realm of Arduino, he is just about the only one who can write sensibly about what he does know.





Robin2

I said I was interested in learning a bit more about BLE and I found this Adafruit link about GATT yesterday that provides some info about BLE Characteristics.

However while I now have a vague notion of what it is I don't know how to access it.

For the sort of project I have in mind an ESP32 seems likely to be the most suitable BLE device - but it is a combination of micro-processor and wireless so it can be programmed directly. However I have not yet convinced myself that it would be sufficiently better than my present nRF24 solution so I may not pursue it further.


And, as @Nick_Pyner said, if all that is required is to send serial data there is no need to understand Characteristics.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Jason_Townsend

I'm betting the above is nonsense, and BLE Characteristic FFE1 particularly is irrelevant technobabble.  In the light of what you have done , by successfully using a serial connection, the sort of thing everybody knows, loves, and understands, I think you need to be a lot more forthcoming about what you want to do in addition.

While your code does something, a triumph in itself, the input section is incomprehensible, and I rather feel that your real problem is that you simply don't understand serial input, and all this BLE Characteristic stuff is just claptrap. In short, even BLE bluetooth is simpler than you think.  

If I'm right, you got lucky, the one to tell you all about that wrote reply #3, and he doesn't need to be educated about BLE Characteristics. If I'm wrong, you could be on the wrong tram entirely.

You might get some better insight into BLE on the Martyn Currey website. He might not know it all but, within the realm of Arduino, he is just about the only one who can write sensibly about what he does know.


Hi,

I'm not sure if you're deliberately trying to be offensive or if it's accidental.  If you don't know anything about how BLE works or the way that the GATT services and characteristics work, please refrain from dismissing my comments.

I will have a look on Martyn's website though, that may offer greater insight.

Thanks,
Jason

ieee488

If you don't know anything about how BLE works or the way that the GATT services and characteristics work, please refrain from dismissing my comments.

The question is do you understand how they work?

It seems that you are assuming that the mere fact of sending/receiving serial data with a Bluetooth module would be enough. That's all your sketch does.
I am guessing the unnamed Serial Monitor app you are using on your Android smartphone is probably doing more than you give it credit for.


https://stackoverflow.com/questions/27914223/corebluetooth-what-is-the-service-uuid-ffe0-shorten-for





Jason_Townsend

The question is do you understand how they work?

It seems that you are assuming that the mere fact of sending/receiving serial data with a Bluetooth module would be enough. That's all your sketch does.
I am guessing the unnamed Serial Monitor app you are using on your Android smartphone is probably doing more than you give it credit for.


https://stackoverflow.com/questions/27914223/corebluetooth-what-is-the-service-uuid-ffe0-shorten-for



Hi,

Thanks for the reply.  I think everyone might be missing something here; the HC-08, like the HM-10 and similar bluetooth modules, don't have an arduino library that I can make use of so I need to work out how to write to the default characteristic from scratch.  In theory anything sent serially (the first 20 bytes anyway) ought to appear in that characteristic (FFE1) but it isn't and that's what I'm stuck on.

Thanks,
Jason

Robin2

I think we need to go back to basics to avoid misunderstandings.

In your Original Post you have this Arduino program
Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8); // RX, TX
void setup(void)
{
 // start serial port
 Serial.begin(9600);
 // Start a serial connection to the BLE module
 mySerial.begin(9600);
}
void loop(void)
{
 float tmp;
 tmp = 26.6
 char c;

 if (mySerial.available() > 0) {
   c = mySerial.read();
   Serial.print(c);
 } else {
   mySerial.print(tmp);
   Serial.println(tmp);
 }
 delay(5000);
}


What is it sending the data to?
Is the data that the Arduino sends being received correctly?

What is the purpose of this piece
Code: [Select]
if (mySerial.available() > 0) {
   c = mySerial.read();
   Serial.print(c);


What is sending the character that is being read?
Is this part of the program working?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Nick_Pyner

id I was interested in learning a bit more about BLE a................ if all that is required is to send serial data there is no need to understand Characteristics.
Pardon me for hijacking an old thread that may be better left dead, but yes, I get the impression the fundamental problem here was probably about trying to use the plain-vanilla data logging code to deal with all the smarty farty stuff pertinent to BLE - something as futile as it is unnecessary.

In the meantime, I have just learned that, while it might not be the greatest idea, it is indeed quite practical to use BLE in a simple datalogger. You might have missed
https://forum.arduino.cc/index.php?topic=549567.msg3747743#msg3747743
where Liz has succeeded in using BLE to do just that. What's more, she does it with (gasp!) an iPhone.... If she can do it one-way, I'm sure she can do it two-way.

And I'm betting she didn't get much help from Apple in this regard. I understand she is using IOS LightBlue.

I have also just learned from Currey's notes that, contrary to BLE protocol, HM-10 is not backward compatible. Clearly not OP's problem, but that goes quite some way to explain mine...

Robin2

Pardon me for hijacking an old thread ...
As you have quoted me I think I should explain that my interest in BLE is to try to figure out how to control several (like 10 or 20) devices with a single master. It can be done but I have not found any general explanation. It think it is done by having the "slaves" broadcast short messages that the master can respond to.

However this is something I get interested in one day and lose interest in the next day. It is a possible alternative to using nRF24 wireless for radio control, but the BLE devices are more expensive and I have not seen one on a really small breakout board. The ESP8266-12 is on a small board and is also a possible alternative for the nRF24.

At the moment I think I have a found a way to simplify the use of the nRF24 coupled to an Attiny1634 so BLE is in the back seat :)

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Nick_Pyner


Go Up