Netduino home hardware projects downloads community

Jump to content


Photo

Reading temperature from DS18B20 using OneWire


  • Please log in to reply
7 replies to this topic

#1 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 10 December 2010 - 03:14 AM

Using Peter H. Anderson's awesome RS232 - OneWire Controller I have managed to successfully read temperature using the Dallas DS18B20 one wire temperature sensor.

The DS18B20 is really awesome, seems very accurate and very responsive. Considering my struggles getting reliable readings from a thermistor, I am finally :) .

Here is my temperature reading code, and attached is a class I wrote to interface with the OneWire controller, in case someone finds it useful.
using System;
using System.IO.Ports;
using System.Text;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using PHAOneWire;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace SerialTest1
{
    public class Program
    {
        public static void Main()
        {
      
            int Tc, Tf;

            using (OneWire ow = new OneWire())
            {
                while (true)
                {

                    ow.Write("P0W0ccS044");
                    Thread.Sleep(1000);  // need to wait for conversion
                    ow.Write("P0W0ccW0be");
                    
                    byte low = ow.ReadByte();
                    byte high = ow.ReadByte();

                    // it's dealing with temps as integers, for instance, 23.5F comes back 235000
                    // since it's 12bits of precision, the smallest difference in temp is .0625
                    
                    Tc = ((high * 256 + low) * 10000) / 16;
                    Tf = ((Tc * 18) / 10) + 320000;

                    Debug.Print(Tf.ToString() + " - " + Tc.ToString());
                    
                    Thread.Sleep(10);
                }
            }
        }
    }
}

Attached Files



#2 MattEric

MattEric

    New Member

  • Members
  • Pip
  • 7 posts

Posted 14 December 2010 - 02:31 AM

Very newbie here. Not sure which post is appropriate so i'll post to both... I've got some DS18B20's that i plan to hook up to a Netduino as soon as i can get a Netduino. I've got them working successfully on an Arduino board using the Dallas Temp Control library (for Arduino) (http://milesburton.c...Control_Library) and Jim Studts's one-wire library (for Arduino) (http://homepage.mac....leSharing7.html). Wouldn't the most straightforward way to go be to port these two libraries of C++ open-source to C#? Or was that already suggested?

#3 Carsten Dressler

Carsten Dressler

    Member

  • Members
  • PipPip
  • 20 posts

Posted 09 January 2011 - 01:37 AM

How did you hook up your DS18B20? Pin 1 (GND) -> GND Pin 2 (DQ) -> Netduino IO 0 Pin 3 (NC) -> Netduino IO 1 Then the 4.7k resister between Pin 2/3? Also your passing "P0W0ccS044". I think this is the unique ID per DS18B20? How do you get this ID? Thanks for the help.

#4 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 09 January 2011 - 02:35 AM

Are you aware I'm using the PHAnderson OneWire controller? The DS18B20 gets hooked to the controller (as per the instructions included with the controller); the controller gets hooked to the Netduino's uart. This thread has my sous vide circuit: http://forums.netdui...rst-shield-pcb/

#5 Carsten Dressler

Carsten Dressler

    Member

  • Members
  • PipPip
  • 20 posts

Posted 09 January 2011 - 07:38 PM

Oh I didnt realize that. Thanks

#6 Jan Olof

Jan Olof

    Advanced Member

  • Members
  • PipPipPip
  • 41 posts
  • LocationSweden

Posted 09 January 2011 - 09:49 PM

Carsten, Forum member CW2 is developing a OneWire driver that does not need an external processor. It will probably be integrated in the official firmware release when finished. But there are a special release of the firmware available in the forums with OneWire support(can´t remember the thread). /Jan Olof

#7 MattEric

MattEric

    New Member

  • Members
  • Pip
  • 7 posts

Posted 10 February 2011 - 05:10 PM

I purchased a PHA controller and implemented code based on Bill's example here, some differences, but nothing major. Everything works fine (after referencing the Microsoft.SPOT.Hardware.SerialPort.dll assembly as described in the Plus forum) except I don't get any readings from controller channels 2 and 3, i.e., pins 3 and 2, respectively. I can move my wire that is hooked up to a DS18B20 data pin and resistor to each controller pin that represents a channel and get readings through channels 0,1,4,5 and 6 but the program hangs when attempting to read from channels 2 or 3. I reset the controller after each move. Anyone experience similar? I suspect a bad controller. Related to this is the ability of the program to detect the presence of a thermometer on a channel. The Dallas documentation describes how this can be done but I haven't seen any documentation from P. Anderson about this capability with the controller. Anyone know how to do that?

#8 jonnyforever

jonnyforever

    New Member

  • Members
  • Pip
  • 1 posts

Posted 27 February 2012 - 04:35 PM

Good Afternoon, i just bought most of the components but i did not buy the PHA Controller ... is it still possible to wire the "One Wire Digital Temperature Sensor - DS18B20" to the Netduino and read its data on the PC? this is my first time that i am working with netduino and this is also my first post :) thanks for your help joN




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2010-2014 Secret Labs LLC  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.