I cannot get my DS18B20 temperature sensor to work

First the basics:
I have 2 DS18B20s that work just fine on an arduino. (Edit: and I’m only trying one at a time.) If I use the EXACT SAME circuit with my FEZ Cobra, I can’t get it to read an accurate temperatue. What am I doing wrong?

I wired one pin to Vcc, one to ground and the middle one to IO9 (with a 4.7k resistor to Vcc-5V).

I am using the exact same sample code from the “Beginners guide to NETMF” ebook. Yes, I changed my pin number to IO9. Do I have to use a specific pin?

When I look at the signal on my Saleae Logic Analyzer, it is able to recognize the reset and presence pulses, but it shows all zeros for the two commands (0xCC and 0x44) to start the temperature conversion.

Here is a snapshot (if this free image hosting works).

I’m totally frustrated by this. Any help would be appreciated!

This is digital sensor so you either can read it accurate or can’t read it at all.

You should be able to use any pin for one wire. Maybe start with one sensor then add the second

I’ve had DS18B20’s working on my Domino. I’ll dig out some code when i get home (5+ hours away).

I edited my first post to clarify. I have 2 sensors, but I’m only trying one at a time. My point is that my sensor is fine (and works great with the Arduino).

If my logic analyzer is right, my code really shouldn’t have anything to do with it. It looks like the timings generated by the Cobra are off?

I’m going to have to double check everything when I find some time, but again, the same circuit works just fine on an Arduino. All I do is just switch the Vcc, Gnd, and Signal lines to the Cobra and I don’t get any meaningful data.

Ah ok, so that might change things.

here’s the simple code I’d try.

int OW_number , i;
int OW_address[8];
OneWire ow = new OneWire((Microsoft.SPOT.Hardware.Cpu.Pin)FEZ_Pin.Digital.Di1); //set your own pin
if (ow.Reset())
    OW_number = 0;
    while (ow.Search_GetNextDevice(OW_address)
       for (i=0;i<8;i++) debug.print(OW_address[i]+":");
    Debug.Print("Found: " + OW_number + " devices");

That should dump out all devices it can see, if any, on the OW network. I’ve had it seeing 8 on a breadboard, but that’s on a Domino not a Cobra. Good luck !

The above is just if it can see any devices on the OW network. If you get past that and the address is displayed, i reckon you have a lack of "RESET"s in your code.

you need to start a conversion, then wait, then read the value.

ow.Reset  // reset the bus
// Match each ROM, and start conversion.
ow.WriteByte(0x55);     // Match ROM
ow.WriteByte(0x44);     // Start temperature conversion
Thread.Sleep(750); //wait for conversion to finish

ow.WriteByte(0x55);     // Match ROM
ow.Write(OW_address, 0, 8);
ow.WriteByte(0xBE);     // Read Scratchpad
ow.Read(OW_readvalue,0,9);  // this variable isn't defined above 

If I remember correctly, the code in the ebook doesn’t use a WAIT it just waits until a read returns non-zero. I seem to remember that there was something in the data sheet that made this not work in the configuration you’re using with the resistor to pull up the data line. Anyway I know the code snippets I’ve included work they’re from an active project (although I have been playing with multiple devices in the code)

Greg5 what firmware version you are using? (printed on LCD)
Try our example in library documentation as is, does it work?
Have you tried a different pin than IO9?

This should be working fine. Just to double check, we tested this again on Cobra and the new SDK which will be online this week. You can try it when it is out.
I attached a picture of my circuit on FEZ Cobra, I connected it to IO6.
I used the same example in our library documentation.

MIke how dare you tease me with the board in your picture and not have it up for sale :>

pshhh, it is a secret :wink:

:o That’s a lot of IO!

Looks like a prototype board?

You were not suppose to guess :stuck_out_tongue:

I tell you guys about a lot things happening at GHI but not everything. I even have a HUGE surprise for next week…I am dieing to tell everyone!!! :wall:

Gus, look the other way…

HEY GUYS! Check out that new green board, cool huh ! Can’t wait to get one in RED!


I’m calling it as a SUPER multiplex board. ;D

This board is not a big deal, just a prototyping board to make using Cobra even more Freakin’ Easy. The board helps you in laying out your boards that will be designed to sit it the FEZ Cobra.

The surprise is actually on a different board…it is … Let’s see…guess what it is and get one for free :smiley:

Just back to the DS18B20 situation for a moment… :wink:

I forgot to mention Greg, you can use my code with multiple devices on the OW, but it’ll only do the conversion on the last one it detects. This is not a bad way to test things out once you get past the initial “it doesn’t work” stage ;D

I kept plugging between the Arduino the Cobra to prove I wasn’t crazy and every once and a while, the Cobra would print out the right temperature.

So, I decided to swap in a couple different resistor values. Instead of 3k and 4.7k like I tried (successfully) with the Arduino, I used a 1k with the FEZ Cobra and it is now merrily spitting out the right temperature values.

I guess this is what I get (professional software dev) for trying to interface with the physical world. :slight_smile: What type of resistor should I be using? Should that really make this much of a difference?

However, my Saleae Logic Analyzer still doesn’t analyze the sequence correctly (although I suppose that could be a problem with the software).

Furthermore, only one of my sensors works with the FEZ Cobra, but both work fine in the Arduino!

Any more insights from the experts? :slight_smile:

Timing could be off so let me try this with a scope and will let you know.
Again, this worked fine here and for other users but not in your case. The good thing is that we are here to make sure all is well

Here is the code I am using. This is tested and working. The Onewire sensor should be pulled up to 5V with a 4.7K resistor. http://files.chrisseto.com/kMF