Go Down

Topic: ArduinoBLE - Unexpected/strange behavior of Characteristic.writeValue() (Read 284 times) previous topic - next topic

DrGee

Sep 11, 2019, 03:24 pm Last Edit: Sep 11, 2019, 04:28 pm by DrGee Reason: add files
Working with the SensorTag CC2650 I found that I need to perform two writeValue() statements to turn the sensor on AFTER it has been turned off..

The scheme is to turn a sensor on, delay for a read time, read the sensor, turn the sensor off...repeat for the next epoch. TI suggests this process in the user guide for power savings when sensor reads occur only occasionally (like a data logger recording every 30 minutes). I have used this procedure before (e.g., CurieBLE) without problems.

To illustrate the problem, I have attached a sketch that reads the OPT3001 light sensor.

Here is the critical section:

Code: [Select]

        OPTConCharacteristic.writeValue(onvalue);
        // the second write below is needed after the sensor has been turned off
        delay(1200);                                              //<--
        OPTConCharacteristic.writeValue(onvalue);   //<--
        delay(1200);                                              //<--
        //---------------------------------------------------------------


When run as is, with the double write, it works fine, printing out the correct lux value repeatedly.

Code: [Select]
Connecting to SensorTag ...Connected
Discovering attributes for Luxometer service ...discovered
Subscribing to the Luxometer data service  ...Subscribed to luxometer data service characteristic
172.96
172.32
171.04
170.40



When run without the double read, like this:

Code: [Select]

        OPTConCharacteristic.writeValue(onvalue);
        // the second write below is needed after the sensor has been turned off
        //delay(1200);                                              //<--
        //OPTConCharacteristic.writeValue(onvalue);   //<--
        //delay(1200);                                              //<--
        //---------------------------------------------------------------


It prints out the first lux value and thereafter, only 0 values, like this.

Code: [Select]
Connecting to SensorTag ...Connected
Discovering attributes for Luxometer service ...discovered
Subscribing to the Luxometer data service  ...Subscribed to luxometer data service characteristic
170.40
0.00
0.00
0.00


I interpret this as a failure to turn the sensor on after it was turned off. It is as though the frst writeValue does not work and that makes no sense. I have tested this extensively. It is definitely NOT a question of a delay. Using only one writeValue, I can wait for 5 minutes before and after the writeValue statement and it makes no difference.

The same situation occurs with the BMP280, TMP007, HDC100 sensors, but not the Mpu9250 (which does not use a simple 1=on / 0=off).

I am not saying that this is an ArduinoBLE problem, but I can't figure out why it would be happening and, again, I have not seen this behavior with CurieBle. I know enough to understand that things are often not what they appear to be, especially after they are understood, but I am stumped.

Anybody have any ideas?


Edited to add debug output: DebugWorking.txt and DebugNotWorking.txt

DrGee

This issue was "fixed" by removing the subscribe to the luxometer service (see attached code).

The scheme that I am using does not use notify. Thus, I do not have to subscribe to the service - instead, I turn the sensor on, wait for a read interval, read the sensor, then turn it off.

Why the subscription interacts in such a way that requires a double write to turn the sensor on, I do not know.

Maybe there is a "face palm" moment in here somewhere, but I do not see it.

I certainly welcome any explanation.

Go Up