@@ -30,22 +30,22 @@ rtos::Thread thread_update_sensors;
3030
3131#ifdef ESP32
3232TaskHandle_t update_base;
33+ TaskHandle_t update_ble;
3334#endif
3435
3536bool ble_is_connected = false ;
3637
3738
3839
3940void setup (){
41+ pinMode (6 ,OUTPUT);
4042 science_kit.begin (NO_AUXILIARY_THREADS); // Doesn't start the BME688 and external temperature threads for the moment
4143
4244 if (!BLE.begin ()){
4345 while (1 );
4446 }
4547
46- #ifdef ESP32
47- BLE.setConnectionInterval (6 , 12 );
48- #endif
48+ // BLE.setConnectionInterval(6, 12);
4949
5050 String address = BLE.address ();
5151
@@ -125,13 +125,16 @@ void setup(){
125125 #endif
126126 #ifdef ESP32
127127 xTaskCreatePinnedToCore (&freeRTOSUpdate, " update_base" , 10000 , NULL , 1 , &update_base, 1 ); // starts the update sensors thread on core 1 (user)
128+ xTaskCreatePinnedToCore (&freeRTOSble, " update_ble" , 10000 , NULL , 1 , &update_ble, 0 ); // starts the ble thread on core 0 (internal)
128129 #endif
129130}
130131
131132
132133void update (void ){
133134 while (1 ){
135+ digitalWrite (6 ,HIGH);
134136 science_kit.update (ROUND_ROBIN_ENABLED);
137+ digitalWrite (6 ,LOW);
135138 delay (25 );
136139 }
137140}
@@ -140,10 +143,16 @@ void update(void){
140143static void freeRTOSUpdate (void * pvParameters){
141144 update ();
142145}
143- #endif
144146
147+ static void freeRTOSble (void * pvParameters){
148+ while (1 ){
149+ updateBle ();
150+ delay (1 );
151+ }
152+ }
153+ #endif
145154
146- void loop (){
155+ void updateBle (){
147156 BLEDevice central = BLE.central ();
148157 if (central) {
149158 ble_is_connected = true ;
@@ -155,6 +164,9 @@ void loop(){
155164 if (millis ()-lastNotify>10 ){
156165 updateSubscribedCharacteristics ();
157166 lastNotify=millis ();
167+ #ifdef ESP32
168+ delay (1 );
169+ #endif
158170 }
159171 }
160172 }
@@ -167,6 +179,13 @@ void loop(){
167179 }
168180}
169181
182+
183+ void loop (){
184+ #ifdef ARDUINO_NANO_RP2040_CONNECT
185+ updateBle ();
186+ #endif
187+ }
188+
170189void updateSubscribedCharacteristics (){
171190 /* ________________________________________________________________CURRENT */
172191 if (currentCharacteristic.subscribed ()){
0 commit comments