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:
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.
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:
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.
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
MKR1010_SensortagTestOPTneedsDW.ino (3.16 KB)
DebugNotWorking.txt (7.27 KB)
DebugWorking.txt (7.39 KB)