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

Netduino Plus 2 OneWire DS18B20 on 4.2


  • Please log in to reply
6 replies to this topic

#1 andro

andro

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationSlovakia

Posted 30 December 2012 - 11:34 AM

Netduino Plus 2 OneWire

on .NET Micro Framework 4.2

DS18B20

Example code:

 

        public static void Main()        {            // DS18B20, NETMF 4.2		    // center pin is connected to digital pin 0, right pin is connected to 5V,		    // left pin GND, 4k7 pull-up  resistor between 5V and the center pin            OneWire oneWire = new OneWire(new OutputPort(Pins.GPIO_PIN_D0, false));            ushort temperature;            while (true)            {                if (oneWire.TouchReset() > 0)                {                    oneWire.WriteByte(0xCC);     // Skip ROM, we only have one device                    oneWire.WriteByte(0x44);     // Start temperature conversion                    while (oneWire.ReadByte() == 0) ;   // wait while busy                    oneWire.TouchReset();                    oneWire.WriteByte(0xCC);     // Skip ROM                    oneWire.WriteByte(0xBE);     // Read Scratchpad                    temperature = (byte)oneWire.ReadByte();           // LSB                     temperature |= (ushort)(oneWire.ReadByte() << 8); // MSB                    //Temperatu in C, If you will in F would be:  ((1.80 * (temperature / 16.0)) + 32);                    Debug.Print("Temperature: " + temperature / 16.0 + "C");                 }                else                {                    Debug.Print("No device detected");                }                Thread.Sleep(1000);            }        }


#2 Lunddahl

Lunddahl

    Advanced Member

  • Members
  • PipPipPip
  • 152 posts
  • LocationEurope, Denmark

Posted 30 December 2012 - 03:44 PM

From: http://wiki.tinyclr....re_-_TempSensor

 

Better hope it's not freezing...:-)

 

- Ulrik Lunddahl



#3 ninoq

ninoq

    Member

  • Members
  • PipPip
  • 15 posts

Posted 07 July 2013 - 02:55 AM

I'm trying to run the code posted by andro on a Netduino Mini which according to MFDeploy has:

.

.

ClrInfo.clrVersion: 4.2.0.0 ClrInfo.clrVendorInfo:   Netduino Mini (v4.2.0.1) by Secret Labs LLC ClrInfo.targetFrameworkVersion: 4.2.0.0 SolutionReleaseInfo.solutionVersion:   4.2.0.0 SolutionReleaseInfo.solutionVendorInfo: Netduino Mini (v4.2.0.1) by Secret Labs LLC SoftwareVersion.BuildDate:   Sep 19 2012 SoftwareVersion.CompilerVersion:   410894

.

.

 

I've made one change so that the OneWire port is allocated to pin 5:

  OneWire oneWire = new OneWire(new OutputPort(Pins.GPIO_PIN_5, false));

 

When I try to to run the code it fails at the line:

if (oneWire.TouchReset() > 0)

and the output is:

"A first chance exception of type 'System.NotSupportedException' occurred in MyApp.exe"

 

which seems to indicate that the TouchReset() method is unavailable. I'm not sure what to do next- hope someone can help.

 

 



#4 ninoq

ninoq

    Member

  • Members
  • PipPip
  • 15 posts

Posted 07 July 2013 - 11:05 AM

OneWire capability is apparently not included in the Mini's firmware which would explain the exception.



#5 zemuss

zemuss

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts

Posted 08 July 2013 - 01:50 PM

Add reference [color=rgb(0,0,0);font-family:'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif;font-size:13px;]Microsoft.SPOT.Hardware.OneWire to your project.[/color]

 

[color=rgb(0,0,0);font-family:'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif;font-size:13px;]Onewire is included in version 4.2 of the framework. You might need to upgrade firmware to 4.2.2.2[/color]



#6 ninoq

ninoq

    Member

  • Members
  • PipPip
  • 15 posts

Posted 09 July 2013 - 05:21 AM

I realised soon after posting my initial reply that it was in the wrong forum as I'm using a Netduino Mini not a Plus 2.  I have posted a topic in the Netduino Mini forum.  Apologies for any confusion I may have caused.



#7 rbagley66

rbagley66

    New Member

  • Members
  • Pip
  • 1 posts

Posted 07 August 2013 - 11:58 PM

I am also getting the same error in the same location. TouchReset??  I do have a  reference to Microsoft.SPOT.Hardware.OneWire in my project. Any help would be great.

 

I am running VS2012 with 4.3.  Below is the code I am using. Just trying to get to work.

 

public static void Main()

{

// DS18B20, NETMF 4.2

// center pin is connected to digital pin 0, right pin is connected to 5V,

// left pin GND, 4k7 pull-up resistor between 5V and the center pin

OneWire oneWire = new OneWire(new OutputPort(Pins.GPIO_PIN_D0, false));

ushort temperature;

while (true)

{

if (oneWire.TouchReset() > 0)

{

oneWire.WriteByte(0xCC); // Skip ROM, we only have one device

oneWire.WriteByte(0x44); // Start temperature conversion

while (oneWire.ReadByte() == 0) ; // wait while busy

oneWire.TouchReset();

oneWire.WriteByte(0xCC); // Skip ROM

oneWire.WriteByte(0xBE); // Read Scratchpad

temperature = (byte)oneWire.ReadByte(); // LSB

temperature |= (ushort)(oneWire.ReadByte() << 8); // MSB

//Temperatu in C, If you will in F would be: ((1.80 * (temperature / 16.0)) + 32);

Debug.Print("Temperature: " + temperature / 16.0 + "C");

}

else

{

Debug.Print("No device detected");

}

Thread.Sleep(1000);

}

?

}






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.