Spark Core and DS18B20 Digital Temperature Sensor

I come from some basic Arduino coding and I tried the spark-dallas-temperature.h and OneWire.h (thanks @krvarma for the great work!)
I was able to read eight ds18b20 (and send the data to Gdrive, thanks @binaryfrost), but I did it without a direct reference to the sensor serial number as I was able to do with the Arduino’s library (DallasTemperature.h).

Below is the piece of code for Spark (100* is to bypass the limitation on the float). Everything works, but I would like to be sure that each variable “temperature …” always refers to the same sensor, while if one sensor stops working, I see -12700 as “temperature8” , but I do not know which sensor is not working anymore.

sensor.requestTemperatures();
temperature1= 100sensor.getTempCByIndex(0);

temperature8= 100
sensor.getTempCByIndex(7);

In Arduino I was referring to the serial number of each sensor, see below.
I tried a bit with the Spark, but I couldn’t figure out how to do it.

DeviceAddress insideThermometer = { 0x28, 0xB8, 0x15, 0xCE, 0x04, 0x00, 0x00, 0xA4 };

sensors.requestTemperatures();
float tempCin = sensors.getTempC(insideThermometer);

P.S. I also had a look at the other discussione OneWire Temperature Publish Example with Multiple Sensors, but most probably the issue I’m facing can be easily addressed with the spark-dallas-temperature.h

The sample code seems to be configured for parasite mode:
ds.write(0x44); // start conversion, with parasite power on at the end

Is there a specific change needed for non-parasite mode?

Figured it out
ds.write(0x44, 1); // is for parasite mode
ds.write(0x44); // is for non-parasite mode

The problem I was having was answered a little higher up
present = ds.reset();
ds.select(addr);
ds.write(0xBE, 0); // Read Scratchpad 0
ds.write(0x00,0); // Recall Memory 0 <--------ERASE THIS LINE

1 Like

Did you ever finalize the OneWire library? I’d like to hook up some DS18B20’s.

Have you looked in the web IDE (the “Launch” button on Spark.io) for libraries? I think there is more than one available now.

1 Like

Thank you very much - just what I was looking for.

I setup a network to do temperature monitoring using 5 DS18B20s connected to the 2 unused lines on my POTS land line. Your phoneline is probably 4 wire and each landline only uses 2 of them. So - you have jacks already in your house and you won’t have to run new wiring to each room.
It worked well with a run approx 200 feet long.

Make sure (of course) to disconnect the lines at the TelCo box.

1 Like

That’s a pretty sweet idea.

I have considered using them for a CANbus so small modules could communicate around the house. But now with how cheap the photon is, it’s hardly worth the trouble.

Hi, Your code works for me. But: how about negative celsius?

Re my previous reply: I was asking “bko June '14”, above.

Hi @rch

Are you having trouble with negative values or are you just asking? The code uses int16_t, a 16-bit signed type to hold the results from the 18b20, which sign-extends its result to 16-bits. So I think negative values are handled properly.

What are you seeing?