@@ -111,11 +111,20 @@ ScienceKitCarrier::ScienceKitCarrier(){
111111
112112int ScienceKitCarrier::begin (const uint8_t auxiliary_threads){
113113 pinMode (LEDR,OUTPUT);
114- digitalWrite (LEDR,LOW);
115114 pinMode (LEDG,OUTPUT);
116- digitalWrite (LEDG,LOW);
117115 pinMode (LEDB,OUTPUT);
116+
117+ #ifdef ARDUINO_NANO_RP2040_CONNECT
118+ digitalWrite (LEDR,LOW);
119+ digitalWrite (LEDG,LOW);
118120 digitalWrite (LEDB,LOW);
121+ #endif
122+
123+ #ifdef ESP32
124+ digitalWrite (LEDR,HIGH);
125+ digitalWrite (LEDG,HIGH);
126+ digitalWrite (LEDB,HIGH);
127+ #endif
119128
120129
121130 Wire.begin ();
@@ -131,6 +140,7 @@ int ScienceKitCarrier::begin(const uint8_t auxiliary_threads){
131140 if (beginINA ()!=0 ){
132141 return ERR_BEGIN_INA;
133142 }
143+
134144
135145 // let's start resistance measurement
136146 if (beginResistance ()!=0 ){
@@ -154,10 +164,12 @@ int ScienceKitCarrier::begin(const uint8_t auxiliary_threads){
154164 }
155165 #endif
156166
157- // let's start ultrasonic and check if it is connected
167+ // let's start ultrasonic and check if it is connected
168+ /* WIP
158169 if (beginUltrasonic()!=0){
159170 return ERR_BEGIN_ULTRASONIC;
160171 }
172+ */
161173
162174 // let's start bme688 and external ds18b20 probe
163175 // WIP startAuxiliaryThreads(auxiliary_threads);
@@ -184,9 +196,10 @@ void ScienceKitCarrier::update(const bool roundrobin){
184196 updateFrequencyGeneratorData ();
185197
186198 // update external
187- updateUltrasonic ();
199+ // WIP updateUltrasonic();
188200 }
189201 else {
202+ // WIP
190203 switch (round_robin_index){
191204 case 0 :
192205 if (thread_ext_temperature_is_running){
@@ -205,7 +218,7 @@ void ScienceKitCarrier::update(const bool roundrobin){
205218 break ;
206219 case 3 :
207220 updateResistance (); // about 1ms
208- updateUltrasonic (); // requires about 5ms when not connected
221+ // WIP updateUltrasonic(); // requires about 5ms when not connected
209222 break ;
210223 case 4 :
211224 updateIMU (); // heavy task, 13ms
@@ -347,10 +360,10 @@ int ScienceKitCarrier::beginResistance(){
347360 pinMode (resistance_pin,INPUT);
348361 // search for minimum open circuit resistance
349362 for (int i=0 ; i<20 ; i++){
350- resistance=REF_VOLTAGE* analogRead (resistance_pin)/ 1024.0 ;
351- resistance= (RESISTOR_AUX*REF_VOLTAGE/resistance)-RESISTOR_AUX;
363+ resistance = getResistanceMeasureVolts () ;
364+ resistance = (RESISTOR_AUX*REF_VOLTAGE/resistance)-RESISTOR_AUX;
352365 if (opencircuit_resistance>resistance){
353- opencircuit_resistance= resistance;
366+ opencircuit_resistance = resistance;
354367 }
355368 delay (5 );
356369 }
@@ -360,23 +373,36 @@ int ScienceKitCarrier::beginResistance(){
360373}
361374
362375void ScienceKitCarrier::updateResistance (){
363- resistance=REF_VOLTAGE* analogRead (resistance_pin)/ 1024.0 ;
364- if (resistance<= 0 ){
365- resistance= -2.0 ;
376+ resistance = getResistanceMeasureVolts () ;
377+ if (resistance <= 0 ){
378+ resistance = -2.0 ;
366379 }
367380 else {
368- resistance= (RESISTOR_AUX*REF_VOLTAGE/resistance)-RESISTOR_AUX;
369- if (resistance<= RESISTANCE_CALIBRATION_LOW){
370- resistance= 0.0 ;
381+ resistance = (RESISTOR_AUX*REF_VOLTAGE/resistance)-RESISTOR_AUX;
382+ if (resistance <= RESISTANCE_CALIBRATION_LOW){
383+ resistance = 0.0 ;
371384 }
372385 else {
373386 if (resistance>=opencircuit_resistance){
374- resistance= -1.0 ;
387+ resistance = -1.0 ;
375388 }
376389 }
377390 }
378391}
379392
393+ float ScienceKitCarrier::getResistanceMeasureVolts (){
394+ float value = 0.0 ;
395+ #ifdef ARDUINO_NANO_RP2040_CONNECT
396+ value = REF_VOLTAGE*analogRead (resistance_pin)/ADC_RESOLUTION;
397+ #endif
398+ #ifdef ESP32
399+ value = analogReadMilliVolts (resistance_pin)/1000.0 ;
400+ #endif
401+ return value;
402+ }
403+
404+
405+
380406float ScienceKitCarrier::getResistance (){
381407 return resistance;
382408}
0 commit comments