@@ -172,7 +172,7 @@ int ScienceKitCarrier::begin(const uint8_t auxiliary_threads){
172172 */
173173
174174 // let's start bme688 and external ds18b20 probe
175- // WIP startAuxiliaryThreads(auxiliary_threads);
175+ startAuxiliaryThreads (auxiliary_threads);
176176}
177177
178178
@@ -248,14 +248,17 @@ int ScienceKitCarrier::beginAnalogInput(){
248248
249249void ScienceKitCarrier::updateAnalogInput (const uint8_t input_to_update){
250250 if ((input_to_update==UPDATE_INPUT_A)||(input_to_update==UPDATE_ALL)){
251- /* WIP
251+
252252 if (!getExternalTemperatureIsConnected ()){
253253 inputA=analogRead (inputA_pin);
254+ #ifdef ESP32
255+ beginExternalTemperature ();
256+ #endif
254257 }
255258 else {
256259 inputA=ANALOGIN_DISABLED;
257260 }
258- */
261+
259262 }
260263 if ((input_to_update==UPDATE_INPUT_B)||(input_to_update==UPDATE_ALL)){
261264 inputB=analogRead (inputB_pin);
@@ -472,14 +475,23 @@ float ScienceKitCarrier::getAirQuality(){
472475 return airquality;
473476}
474477
475- #ifdef ARDUINO_NANO_RP2040_CONNECT
476478void ScienceKitCarrier::threadBME688 (){
477479 beginBME688 ();
478480 while (1 ){
479481 updateBME688 ();
482+ #ifdef ARDUINO_NANO_RP2040_CONNECT
480483 rtos::ThisThread::sleep_for (1000 );
484+ #endif
485+ #ifdef ESP32
486+ delay (1000 );
487+ #endif
481488 }
482489}
490+
491+ #ifdef ESP32
492+ void ScienceKitCarrier::freeRTOSInternalTemperature (void * pvParameters){
493+ ((ScienceKitCarrier*) pvParameters)->threadBME688 ();
494+ }
483495#endif
484496
485497
@@ -580,12 +592,11 @@ float ScienceKitCarrier::getMagneticFieldZ(){
580592
581593#ifdef ARDUINO_NANO_RP2040_CONNECT
582594void ScienceKitCarrier::delay (unsigned long t){
583- rtos::ThisThread::sleep_for (t);
595+ rtos::ThisThread::sleep_for (t);
584596}
585597#endif
586598
587599
588-
589600/* *******************************************************************/
590601/* LEDs: errors and activity */
591602/* *******************************************************************/
@@ -745,7 +756,6 @@ bool ScienceKitCarrier::getUltrasonicIsConnected(){
745756/* *******************************************************************/
746757// WIP
747758
748- #ifdef ARDUINO_NANO_RP2040_CONNECT
749759int ScienceKitCarrier::beginExternalTemperature (){
750760 new (&ow) OneWireNg_CurrentPlatform (OW_PIN, false );
751761 DSTherm drv (ow);
@@ -754,8 +764,14 @@ int ScienceKitCarrier::beginExternalTemperature(){
754764
755765void ScienceKitCarrier::updateExternalTemperature (){
756766 float temperature;
757- pinMode (OW_PIN,INPUT);
758767
768+ #ifdef ARDUINO_NANO_RP2040_CONNECT
769+ pinMode (OW_PIN,INPUT);
770+ #endif
771+ #ifdef ESP32
772+ pinMode (INPUTA_PIN,INPUT);
773+ #endif
774+
759775 DSTherm drv (ow);
760776 drv.convertTempAll (DSTherm::MAX_CONV_TIME, false );
761777
@@ -795,11 +811,19 @@ void ScienceKitCarrier::threadExternalTemperature(){
795811 while (1 ){
796812 updateExternalTemperature ();
797813 updateAnalogInput (UPDATE_INPUT_A);
798- rtos::ThisThread::sleep_for (1000 );
814+
815+ #ifdef ARDUINO_NANO_RP2040_CONNECT
816+ rtos::ThisThread::sleep_for (1000 );
817+ #endif
818+ #ifdef ESP32
819+ delay (1000 );
820+ #endif
799821 }
800822}
801- #endif
802823
824+ void ScienceKitCarrier::freeRTOSExternalTemperature (void * pvParameters){
825+ ((ScienceKitCarrier*) pvParameters)->threadExternalTemperature ();
826+ }
803827
804828
805829/* *******************************************************************/
@@ -845,30 +869,35 @@ uint ScienceKitCarrier::getMicrophoneRMS(){
845869/* *******************************************************************/
846870/* Threads */
847871/* *******************************************************************/
848- #ifdef ARDUINO_NANO_RP2040_CONNECT
849872
850873void ScienceKitCarrier::startAuxiliaryThreads (const uint8_t auxiliary_threads){
851874 // thread_activity_led->start(mbed::callback(this, &ScienceKitCarrier::threadActivityLed)); //left for legacy on prototypes and maybe future implementations
852-
853875 // start bme688 thread
854876 if ((auxiliary_threads==START_AUXILIARY_THREADS)||(auxiliary_threads==START_INTERNAL_AMBIENT_SENSOR)){
855877 if (!thread_bme_is_running){
856- thread_update_bme->start (mbed::callback (this , &ScienceKitCarrier::threadBME688));
878+ #ifdef ARDUINO_NANO_RP2040_CONNECT
879+ thread_update_bme->start (mbed::callback (this , &ScienceKitCarrier::threadBME688));
880+ #endif
881+ #ifdef ESP32
882+ xTaskCreatePinnedToCore (this ->freeRTOSInternalTemperature , " update_internal_temperature" , 10000 , this , 1 , &thread_internal_temperature, INTERNAL_TEMPERATURE_CORE);
883+ #endif
857884 }
858885 thread_bme_is_running=true ;
859886 }
860-
861887 // start ds18b20 thread
862888 if ((auxiliary_threads==START_AUXILIARY_THREADS)||(auxiliary_threads==START_EXTERNAL_AMBIENT_SENSOR)){
863889 if (!thread_ext_temperature_is_running){
864- thread_external_temperature->start (mbed::callback (this , &ScienceKitCarrier::threadExternalTemperature));
890+ #ifdef ARDUINO_NANO_RP2040_CONNECT
891+ thread_external_temperature->start (mbed::callback (this , &ScienceKitCarrier::threadExternalTemperature));
892+ #endif
893+ #ifdef ESP32
894+ xTaskCreatePinnedToCore (this ->freeRTOSExternalTemperature , " update_external_temperature" , 10000 , this , 1 , &thread_external_temperature, EXTERNAL_TEMPERATURE_CORE);
895+ #endif
865896 }
866897 thread_ext_temperature_is_running=true ;
867898 }
868899}
869900
870- #endif
871-
872901
873902/* **
874903 * _ _
0 commit comments