AnalogRead problem
-
@MasMat said in AnalogRead problem:
analogReference(INTERNAL);
Won't that set the analog reference to the 1.1V internal source? If so then the analog read range of 0-1023 will be mapped to 0-1.1V. Anything over 1.1 will be seen as 1.1V - But maybe I'm wrong....???
-
I investigated the bootloader problem, I use 1.8.1 definitions that made those problems disappear. But still, the A2 (THMR_PIN) reads 1023 but the battery sense on A4 works.
EDIT: now I get what you mean: it also changes the reference for the whole ADC...from 3.3 to 1.1V! Any ideas for changing the resistors? I would want to use the same thermistor as I only have two wires going to the sauna. OR is there a way to change the reference for A2 read and go back after it's been read?
-
Yes, you can change between references.
analogReference(DEFAULT);Be aware that after you changed the reference the first 52 reads have to be discarded.
@electrik ..and then just adjust the volts/bit for 3.3 rather than 1.1v, correct? (i.e x3). That fixed it, thank you.
BUT presented a weird problem. The analogRead gives a proper value but the math then is not working and I cant figure it out. I did the calculations myself and get a proper result:int _nominal_resistor2 = 10000; int _nominal_temperature2 = 25; int _b_coefficient2 = 3950; int _series_resistor2 = 10000; int adcTmm = analogRead(THMR_PIN); Serial.println(adcTmm); float readingSau = (1023 / adcTmm) - 1; readingSau = _series_resistor2 / readingSau; float temperatureS = readingSau / _nominal_resistor2; // (R/Ro) temperatureS = log(temperatureS); // ln(R/Ro) temperatureS /= _b_coefficient2; // 1/B * ln(R/Ro) temperatureS += 1.0 / (_nominal_temperature2 + 273.15); // + (1/To) temperatureS = 1.0 / temperatureS; // Invert temperatureS -= 273.15; // convert to C send(msgTempSau.set((int16_t)temperatureS, 2)); Serial.print("Sauna T: "); Serial.print(temperatureS); Serial.println(" C");But still the serial monitor shows:
7409 MCO:SLP:WUP=1 7413 TSF:TRI:TSB Sauna door: 1 7430 TSF:MSG:SEND,21-21-10-0,s=3,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1 7966 TSF:MSG:SEND,21-21-10-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:29.00 Shower T: 29.00 7989 TSF:MSG:SEND,21-21-10-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:87.0 Shower H: 87.00 536 8005 TSF:MSG:SEND,21-21-10-0,s=16,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:-273.00 Sauna T: -273.15 C Sauna off, sleeping 30min Battery Voltage: 4.22 V Battery percent: 97.70 % 8028 TSF:MSG:SEND,21-21-10-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:97 8097 MCO:SLP:MS=1800000,SMS=0,I1=1,M1=1,I2=255,M2=255 8108 TSF:TDI:TSLI changed variable names to account there wouldnt be overlap with DHT library & dht part of sketch.
-
These kind of issues are usually caused by an overflow somewhere, or memory being full
Edit:
Also check if you're using the right log function... There are two log functions, the log base 10 and the log base 2@electrik Thanks I'll check those.
I added a lot of serial.Print's to debug where it goes south and it appears to ruin already at the first division after the analogRead (I started receiving 530's analogRead at room temp). So probably something else completely that's rotten. I'll try another machine with another Arduino IDE. It should work now that the original question is answered.
So I'll consider this solved. Thanks again! -
@electrik Thanks I'll check those.
I added a lot of serial.Print's to debug where it goes south and it appears to ruin already at the first division after the analogRead (I started receiving 530's analogRead at room temp). So probably something else completely that's rotten. I'll try another machine with another Arduino IDE. It should work now that the original question is answered.
So I'll consider this solved. Thanks again! -
@electrik ..and then just adjust the volts/bit for 3.3 rather than 1.1v, correct? (i.e x3). That fixed it, thank you.
BUT presented a weird problem. The analogRead gives a proper value but the math then is not working and I cant figure it out. I did the calculations myself and get a proper result:int _nominal_resistor2 = 10000; int _nominal_temperature2 = 25; int _b_coefficient2 = 3950; int _series_resistor2 = 10000; int adcTmm = analogRead(THMR_PIN); Serial.println(adcTmm); float readingSau = (1023 / adcTmm) - 1; readingSau = _series_resistor2 / readingSau; float temperatureS = readingSau / _nominal_resistor2; // (R/Ro) temperatureS = log(temperatureS); // ln(R/Ro) temperatureS /= _b_coefficient2; // 1/B * ln(R/Ro) temperatureS += 1.0 / (_nominal_temperature2 + 273.15); // + (1/To) temperatureS = 1.0 / temperatureS; // Invert temperatureS -= 273.15; // convert to C send(msgTempSau.set((int16_t)temperatureS, 2)); Serial.print("Sauna T: "); Serial.print(temperatureS); Serial.println(" C");But still the serial monitor shows:
7409 MCO:SLP:WUP=1 7413 TSF:TRI:TSB Sauna door: 1 7430 TSF:MSG:SEND,21-21-10-0,s=3,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:1 7966 TSF:MSG:SEND,21-21-10-0,s=1,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:29.00 Shower T: 29.00 7989 TSF:MSG:SEND,21-21-10-0,s=0,c=1,t=1,pt=7,l=5,sg=0,ft=0,st=OK:87.0 Shower H: 87.00 536 8005 TSF:MSG:SEND,21-21-10-0,s=16,c=1,t=0,pt=7,l=5,sg=0,ft=0,st=OK:-273.00 Sauna T: -273.15 C Sauna off, sleeping 30min Battery Voltage: 4.22 V Battery percent: 97.70 % 8028 TSF:MSG:SEND,21-21-10-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:97 8097 MCO:SLP:MS=1800000,SMS=0,I1=1,M1=1,I2=255,M2=255 8108 TSF:TDI:TSLI changed variable names to account there wouldnt be overlap with DHT library & dht part of sketch.
-
@MasMat Try changing
float readingSau = (1023 / adcTmm) - 1;To
float readingSau = (1023.0 / float(adcTmm) ) - 1;You are mixing integer and floating point math.