@@ -111,11 +111,20 @@ ScienceKitCarrier::ScienceKitCarrier(){
111
111
112
112
int ScienceKitCarrier::begin (const uint8_t auxiliary_threads){
113
113
pinMode (LEDR,OUTPUT);
114
- digitalWrite (LEDR,LOW);
115
114
pinMode (LEDG,OUTPUT);
116
- digitalWrite (LEDG,LOW);
117
115
pinMode (LEDB,OUTPUT);
116
+
117
+ #ifdef ARDUINO_NANO_RP2040_CONNECT
118
+ digitalWrite (LEDR,LOW);
119
+ digitalWrite (LEDG,LOW);
118
120
digitalWrite (LEDB,LOW);
121
+ #endif
122
+
123
+ #ifdef ESP32
124
+ digitalWrite (LEDR,HIGH);
125
+ digitalWrite (LEDG,HIGH);
126
+ digitalWrite (LEDB,HIGH);
127
+ #endif
119
128
120
129
121
130
Wire.begin ();
@@ -131,6 +140,7 @@ int ScienceKitCarrier::begin(const uint8_t auxiliary_threads){
131
140
if (beginINA ()!=0 ){
132
141
return ERR_BEGIN_INA;
133
142
}
143
+
134
144
135
145
// let's start resistance measurement
136
146
if (beginResistance ()!=0 ){
@@ -154,10 +164,12 @@ int ScienceKitCarrier::begin(const uint8_t auxiliary_threads){
154
164
}
155
165
#endif
156
166
157
- // let's start ultrasonic and check if it is connected
167
+ // let's start ultrasonic and check if it is connected
168
+ /* WIP
158
169
if (beginUltrasonic()!=0){
159
170
return ERR_BEGIN_ULTRASONIC;
160
171
}
172
+ */
161
173
162
174
// let's start bme688 and external ds18b20 probe
163
175
// WIP startAuxiliaryThreads(auxiliary_threads);
@@ -184,9 +196,10 @@ void ScienceKitCarrier::update(const bool roundrobin){
184
196
updateFrequencyGeneratorData ();
185
197
186
198
// update external
187
- updateUltrasonic ();
199
+ // WIP updateUltrasonic();
188
200
}
189
201
else {
202
+ // WIP
190
203
switch (round_robin_index){
191
204
case 0 :
192
205
if (thread_ext_temperature_is_running){
@@ -205,7 +218,7 @@ void ScienceKitCarrier::update(const bool roundrobin){
205
218
break ;
206
219
case 3 :
207
220
updateResistance (); // about 1ms
208
- updateUltrasonic (); // requires about 5ms when not connected
221
+ // WIP updateUltrasonic(); // requires about 5ms when not connected
209
222
break ;
210
223
case 4 :
211
224
updateIMU (); // heavy task, 13ms
@@ -347,10 +360,10 @@ int ScienceKitCarrier::beginResistance(){
347
360
pinMode (resistance_pin,INPUT);
348
361
// search for minimum open circuit resistance
349
362
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;
352
365
if (opencircuit_resistance>resistance){
353
- opencircuit_resistance= resistance;
366
+ opencircuit_resistance = resistance;
354
367
}
355
368
delay (5 );
356
369
}
@@ -360,23 +373,36 @@ int ScienceKitCarrier::beginResistance(){
360
373
}
361
374
362
375
void 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 ;
366
379
}
367
380
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 ;
371
384
}
372
385
else {
373
386
if (resistance>=opencircuit_resistance){
374
- resistance= -1.0 ;
387
+ resistance = -1.0 ;
375
388
}
376
389
}
377
390
}
378
391
}
379
392
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
+
380
406
float ScienceKitCarrier::getResistance (){
381
407
return resistance;
382
408
}
0 commit comments