Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

DS18B20 problems, please help.

DS18B20 Netduino2Plus

Best Answer CW2 , 31 January 2013 - 05:00 PM

I think you should use Pins.GPIO_PIN_D0 instead of Cpu.Pin.GPIO_Pin0:

OutputPort portZero = new OutputPort(Pins.GPIO_PIN_D0, false);

(Cpu.Pin.GPIO_Pin0 is Pins.GPIO_PIN_D8 on Netduino Plus 2.) Also, consider checking the return values of OneWire methods:

if(sensorOne.TouchReset() > 0){  //...}else{  // No device detected}
Go to the full post


  • Please log in to reply
2 replies to this topic

#1 AndrejsM

AndrejsM

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationAtlanta

Posted 31 January 2013 - 03:53 PM

Hi. Can anyone shed some light on my problem? I ran the below code, and all I get for a reading is -0.0625 over and over (debug out below). I have tried parasite power, regular power, with a resistor, w/o a resistor. If I completely disconnect the DS18B20 I still get the exact same results, which is telling me that I am not even able to commincate with the sensor I guess? I got the Netduino 2 Plus about 3 weeks ago and I'm guessing it should have all the correct firmware loaded. I'm using a radio shack resistor (4.7k-Ohm, 1/2 watt, 5% tolerance) for the pull-up. The sensor I'm using is '365buying DS18B20 Waterproof Temperature Sensor' I bought off of Amazon. It has three wires. I am assuming that Red is power, Black is ground and White is data. Below is also a picture of my wiring setup.
 
Am I just completely missing something or is my sensor just malfunctioning? Can anyone help please? I'm loosing my mind out here. Thanks.
 
 
MY CODE:
using System;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using Microsoft.SPOT.Net.NetworkInformation;namespace TemperatureTest_01{    public class Program    {        public static void Main()        {            OutputPort portZero = new OutputPort(Cpu.Pin.GPIO_Pin0, false);            OneWire sensorOne = new OneWire(portZero);            while (true)            {                sensorOne.TouchReset();   //<--Reset DS18B20                sensorOne.WriteByte(0xCC);   //<--Skip ROM                sensorOne.WriteByte(0x44);   //<--Convert T                while (sensorOne.ReadByte() == 0);  //<--Wait while DS18B20 gets the temperature (about 750ms)                sensorOne.TouchReset();   //<--Reset DS18B20                sensorOne.WriteByte(0xCC);   //<--Skip ROM                sensorOne.WriteByte(0xBE);   //<--Read Scratchpad                // Read just the temperature (2 bytes)                var tempLo = sensorOne.ReadByte();                var tempHi = sensorOne.ReadByte();                var temp = ((short)((tempHi << 8) | tempLo))/16F;                sensorOne.TouchReset();   //<--Reset DS18B20                Debug.Print("Temperature: " + temp);                Thread.Sleep(5000);            }        }    }}

 

 

 

MY DEBUG OUTPUT (parasite power):

PARASITE POWERCreate TS. Loading start at 806a328, end 808443cAssembly: mscorlib (4.2.0.0)Assembly: Microsoft.SPOT.Native (4.2.0.0)Assembly: Microsoft.SPOT.Hardware (4.2.0.0)Assembly: Microsoft.SPOT.Net (4.2.0.0)Assembly: System (4.2.0.0)Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0)Assembly: Microsoft.SPOT.IO (4.2.0.0)Assembly: System.IO (4.2.0.0)Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1)Assembly: Microsoft.SPOT.Hardware.Usb (4.2.0.0)Assembly: SecretLabs.NETMF.Diagnostics (4.2.0.0)Assembly: SecretLabs.NETMF.Hardware.Netduino (4.2.1.0)Assembly: Microsoft.SPOT.Hardware.OneWire (4.2.0.0)Assembly: Microsoft.SPOT.Time (4.2.0.0)Loading Deployment Assemblies.Attaching deployed file.Assembly: SecretLabs.NETMF.Hardware (4.2.0.0)Attaching deployed file.Assembly: TemperatureTest_01 (1.0.0.0)Resolving.The debugging target runtime is loading the application assemblies and starting execution.Ready.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2Assemblieslemscorlib.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Native.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Net.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleSystem.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleSystem.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.PWM.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.Usb.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Secret LabsNetduino SDKAssembliesv4.2leSecretLabs.NETMF.Diagnostics.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Secret LabsNetduino SDKAssembliesv4.2leSecretLabs.NETMF.Hardware.Netduino.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.OneWire.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Time.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Secret LabsNetduino SDKAssembliesv4.2leSecretLabs.NETMF.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'c:UsersAndrejsDocumentsVisual Studio 2010ProjectsTemperatureTest_01TemperatureTest_01binDebugleTemperatureTest_01.exe', Symbols loaded.The thread '<No Name>' (0x2) has exited with code 0 (0x0).Temperature: -0.0625Temperature: -0.0625Temperature: -0.0625Temperature: -0.0625Temperature: -0.0625The program '[15] Micro Framework application: Managed' has exited with code 0 (0x0).

 

 

 

MY DEBUG OUTPUT (regular, non-parasite power)

REGULAR, NO PARISITE POWERCreate TS. Loading start at 806a328, end 808443cAssembly: mscorlib (4.2.0.0)Assembly: Microsoft.SPOT.Native (4.2.0.0)Assembly: Microsoft.SPOT.Hardware (4.2.0.0)Assembly: Microsoft.SPOT.Net (4.2.0.0)Assembly: System (4.2.0.0)Assembly: Microsoft.SPOT.Hardware.SerialPort (4.2.0.0)Assembly: Microsoft.SPOT.IO (4.2.0.0)Assembly: System.IO (4.2.0.0)Assembly: Microsoft.SPOT.Hardware.PWM (4.2.0.1)Assembly: Microsoft.SPOT.Hardware.Usb (4.2.0.0)Assembly: SecretLabs.NETMF.Diagnostics (4.2.0.0)Assembly: SecretLabs.NETMF.Hardware.Netduino (4.2.1.0)Assembly: Microsoft.SPOT.Hardware.OneWire (4.2.0.0)Assembly: Microsoft.SPOT.Time (4.2.0.0)Loading Deployment Assemblies.Attaching deployed file.Assembly: SecretLabs.NETMF.Hardware (4.2.0.0)Attaching deployed file.Assembly: TemperatureTest_01 (1.0.0.0)Resolving.The debugging target runtime is loading the application assemblies and starting execution.Ready.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2Assemblieslemscorlib.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Native.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Net.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleSystem.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleSystem.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.PWM.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.Usb.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Secret LabsNetduino SDKAssembliesv4.2leSecretLabs.NETMF.Diagnostics.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Secret LabsNetduino SDKAssembliesv4.2leSecretLabs.NETMF.Hardware.Netduino.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Hardware.OneWire.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Microsoft .NET Micro Frameworkv4.2AssembliesleMicrosoft.SPOT.Time.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program Files (x86)Secret LabsNetduino SDKAssembliesv4.2leSecretLabs.NETMF.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'c:UsersAndrejsDocumentsVisual Studio 2010ProjectsTemperatureTest_01TemperatureTest_01binDebugleTemperatureTest_01.exe', Symbols loaded.The thread '<No Name>' (0x2) has exited with code 0 (0x0).Temperature: -0.0625Temperature: -0.0625Temperature: -0.0625Temperature: -0.0625Temperature: -0.0625The program '[16] Micro Framework application: Managed' has exited with code 0 (0x0).

 

 

 

THE WIRING MODEL I USED

ds18b20sample.png

 

 

MY ACTUAL WIRING

IMAG0353.jpg
 
 
Thank you so much for any help you can provide!

Attached Files



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 31 January 2013 - 05:00 PM   Best Answer

I think you should use Pins.GPIO_PIN_D0 instead of Cpu.Pin.GPIO_Pin0:

OutputPort portZero = new OutputPort(Pins.GPIO_PIN_D0, false);

(Cpu.Pin.GPIO_Pin0 is Pins.GPIO_PIN_D8 on Netduino Plus 2.) Also, consider checking the return values of OneWire methods:

if(sensorOne.TouchReset() > 0){  //...}else{  // No device detected}


#3 AndrejsM

AndrejsM

    Member

  • Members
  • PipPip
  • 18 posts
  • LocationAtlanta

Posted 01 February 2013 - 02:39 AM

Thank you CW2! Using 'Pins' instead of 'Cpu.Pin' did the trick. It works! Thank you again. Now on to the next steps.







Also tagged with one or more of these keywords: DS18B20, Netduino2Plus

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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