DS18B20 + Photon Odd Temp Spikes

I have a DS18B20 connected to a photon. I am using a three-wire configuration with power to 3v3, ground to ground and data to D4. I have a 4.7K resistor between 3v3 and D4. This photon is powered 24x7 so I am not using any sleep or power saving modes in my code.

I am using the code (with some modification) from the Particle.io site for doing temperature:

https://go.particle.io/shared_apps/5bbe8d31277554b6880012eb

So I am seeing consistent readings for a while and then a spike to 188 degrees F (or similar very high temperature) for (what seems like) no reason. I have tried three different DS18B20 sensors and get the same results each time. Everything is going great, then a big spike.

The Photon is running 0.8.0-rc.11 and is powered off a 2.1A USB adaptor.

I shared the code above. Any ideas as where to look would be great.

42%20PM

I usually get spikes when using DS18B20 too, although they are usually negative and consistent. I just have the photon ignore any spike values and use the previous reading.

1 Like

Thanks!

This is in the code, but it does not seem to be doing any good:

// remove random errors
  if((((celsius <= 0 && celsius > -1) && lastTemp > 5)) || celsius > 125) {
      celsius = lastTemp;

How are you dealing with the spikes in your code?

Here it is taken out of context:

dallas.requestTemperatures();
readingData.temperature = dallas.getTempFByIndex(0);

if (readingData.temperature < -190) {
    readingData.temperature = lastTemp;
}
else {
    lastTemp = readingData.temperature;
}

For me the spike was always -196.6 so I made it reject any readings less than -190. For your code you could have it reject readings greater than 180 for example.

Thanks! I’ll work on that. So these spikes are just the DS18B20 when paired to the Photon? I don’t see these spikes using an Arduino with the same sensor.

I don’t know exactly. How frequently are you taking readings?

Also, I use this library if that helps:

I am taking readings about once every 15 seconds right now. Did you see a difference in the Dallas library from the OneWire?

I haven’t really tested the differences between different DS18B20 libraries.

Got it. I’ll play around with the “spike mitigation” code and see if I can just know them out of the reading like you doing!

Thanks Again!

1 Like

You want to make sure whichever Library you are using validates the CRC of the data. Sometimes you get a bad reading with a bad CRC.

2 Likes

I am looking at my Arduino code and I am using the Dallas library. Unfortunately that does not seem to be available as a working version within the WebIDE for Particle. I guess I will try a different IDE.

If you don’t mind me asking, waht IDE do you use for your Particle boards?

Yes it is.
https://build.particle.io/libs/spark-dallas-temperature/0.0.5/tab/spark-dallas-temperature.cpp

There is some bug according to the forum here. When you try to compile it calls …/OneWire/OneWire as opposed to just OneWire.

So you cannot do it on the WebIDE since you cannot modify the library.

That is why I was asking what you were using as your IDE. I use the Arduino IDE for everything related to the the boards and PyCharm for all of my Python stuff.

I guess I have to download their desktop IDE to be able to manage my own libraries…

lib/spark-dallas-temperature/spark-dallas-temperature.h:27:36: ../OneWire/OneWire.h: No such file or directory

I use po-util within Atom for my IDE.

My fork of the dallas library works well in po-util.

You could get it to work in the official Particle desktop IDE.

Ah…got it…

YEah, I am trying the Particle workbench plugin for Visual Studio Code right now, never used VSC before so not sure how much (if at all) I will like it.

I thought the WebIDE was pretty cool until I hit that Library snag. :slight_smile:

The “old” desktop IDE is Atom based and still works pretty well. (Cloud compilation only though.)

I might give that a try as well and see how well it works. According to the Particle.io website they are going to stop using that and go with Visual Studio Code so I downloaded it and I am playing around with it. Seems to run pretty good under Linux for a M$ product…

Since you’re on Linux I would recommend po-util because of how smooth the installation is and because it does all compiling locally.

Po-util can be used from within terminal, Atom, or even Visual Studio Code.

I use this library
https://build.particle.io/libs/DS18B20/0.1.8/tab/example/ds18b20_SingleDrop.ino

The example also shows how to use the CRC check.

4 Likes

Thanks. The code that I am using already does a full CRC check:

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 91 1 4B 46 7F FF C 10 70  CRC=70
  Temperature = 25.06 Celsius, 77.11 Fahrenheit

But even with the CRC enabled and returning good, I still get spikes for no reason:

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 91 1 4B 46 7F FF C 10 70  CRC=70
  Temperature = 25.06 Celsius, 77.11 Fahrenheit
No more addresses.

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 D1 1 4B 46 7F FF C 12 70  CRC=85
  Temperature = 29.06 Celsius, 84.31 Fahrenheit
No more addresses.

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 91 1 4B 46 7F FF C 10 70  CRC=70
  Temperature = 25.06 Celsius, 77.11 Fahrenheit
No more addresses.

And more drastic:

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 91 1 4B 46 7F FF C 10 70  CRC=70
  Temperature = 25.06 Celsius, 77.11 Fahrenheit
No more addresses.

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 95 81 4B 46 7F FF C 10 70  CRC=F2
  Temperature = -2022.69 Celsius, -3608.84 Fahrenheit
No more addresses.

No more addresses.

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 91 3 4B 46 7F FF C 10 70  CRC=A
  Temperature = 57.06 Celsius, 134.71 Fahrenheit
No more addresses.

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 91 3 4B 46 7F FF C 10 70  CRC=A
  Temperature = 57.06 Celsius, 134.71 Fahrenheit
No more addresses.

ROM = 28 8F DF 6A 1F 13 1 98
  Chip = DS18B20
  Data = 1 90 1 4B 46 7F FF C 10 33  CRC=33
  Temperature = 25.00 Celsius, 77.00 Fahrenheit
No more addresses.

All of which passed a CRC check so I don’t think it is a CRC issue.