I’m using a NodeMCU ESP8266 12-E to control a heater. I have the app showing the correct temperature but I want to use the measured temperature to take decisions based on the value. The problem I’m having is the value shown when I try to print it on serial port is always -127 and every time I open the serial screen the value on the app also goes to -127. So I’m not sure what is going on.
Do I need to convert the value I read from the sensor to use it?
Do you have any idea if the value I get from sensors.getTempCByIndex(0) needs to be converted? I’m not sure about it and I can’t use the serial monitor to confirm…
I see. The LCD also change the display when I open the serial monitor. If I close the monitor the LCD will work fine after a few seconds. Maybe is something related to the port I’m using the sensor?
I think you have a timing problem .
You’re using Timer.setInterval ( 1000L , ReadTemp ) ;
You need 750 ms to complete reading in 12 bits.
When you start using the serial port, serial port ISR is your highest priority ISR and so the time Dallas will be compromised . And when 1-Wire sequence is compromised, you get -127 <img
@Surbyte I suspected it might relate to the resolution but yesterday when I reduced the 1000L to 600L for 12bit resolution I still couldn’t get the DS18B20 to fail (with a WeMos) and Serial Monitor.
@AndreSepulveda we generally work with 10 bit resolution with sensors.setResolution(10); // resolution 9 to 12 available after sensors.begin in setup(). You could try changing the resolution and also increasing the 1000L to 2000L to see if that helps.
Failing that it must be something specific to the NodeMCU USB port.
Tried everything suggested. @Costas I tried another port and changed the resolution to 10 bits as you said and I changed the timer.serInterval to 2000L as @Surbyte but it’s still weird if I open the serial monitor.
I can use the project since it’s working fine but I’m intrigued by this weird behaviour
I was first trying without Blynk and all I was getting was the -127 on the serial monitor. When I tried using the Blynk app and it gave me the correct reading I thought the value from sensors.getTempCByIndex(0) needed some kind of conversion and the app did that. But when I opened the serial monitor everything went bad again.
The project is up and running already. I just wanted to know why this happens when I open the serial monitor. Maybe someday when I get more familiar with the hardware I’ll find it out.
Probably worth you asking NodeMCU why their hardware is giving you problems and have it replaced if it is faulty. All you would need to do is send them the most basic sketch and then they can easily confirm if your hardware is faulty.