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 support for the confused (noob)


Best Answer Tobias Vandenbempt, 24 March 2014 - 09:52 AM

You can just copy my Controller code to a class and then use that class as follows:

 

private static OneWireTemperatureSensorController _tempertureController;
public static void Main()
{
_tempertureController = new OneWireTemperatureSensorController(Pins.GPIO_PIN_D0);
     while (true)
     {
                Tick(null);
                //Thread.Sleep(10 * 1000 ); //sleep 10 seconds
                Thread.Sleep(1000 * 60 * 30); //sleep 30 minutes
     }
}


private static void Tick(object state)
{
    var temp = _tempertureController.ReadTemperatureToConsole(TemperatureEnum.Celcius, false);
} 
The temperature then gets logged to your Console window, so there you will see the temperature readings. 
 
Hope this is easy to read, if not ask away!
Go to the full post


  • Please log in to reply
5 replies to this topic

#1 fredk

fredk

    New Member

  • Members
  • Pip
  • 3 posts

Posted 23 March 2014 - 03:07 AM

I've just received my Netduino plus 2 with bits 'n bobs, one of them being a onewire temperature sensor.  I'm now trying to figure out what all I need software wise to get it going.

 

I'm locked in to 4.2 firmware because the laptop my son and I are using is Vista and only supports Visula C# 2010.

 

From looking at the MS reference for its 4.2 Micro Framework I understand that onewire support is "provided through a community development effort.".  I'm guessing that I need additional code/libraries/classes but am not clear on exactly what it is I need. I've downloaded two bits of code, DS18B20.cs and OneWireBus.cs, that were used by someone else in their project.  Should I be using these? Are their any other code bits I need? 

 

Also, do I need flash memory installed to load said code?

 

Thanks in advance



#2 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 23 March 2014 - 12:00 PM

I've done this very thing, and have a blog post about it. Maybe it will help you? 

 

http://netduinoblog.Wordpress.com

https://netduinoblog...sensor-ds18b20/



#3 fredk

fredk

    New Member

  • Members
  • Pip
  • 3 posts

Posted 24 March 2014 - 01:53 AM

Thanks for the reply Tobias.  That is a very well laid out blog and one of the links I found when searching on the subject.

 

Maybe a little more background will be helpful.  I am a non-programmer with a technical marketing background (know just enough to be dangerous :) ) and the guy doing the coding, my son, has only used Python (highschool level programming).  This is an opportunity for him to tackle a real world project using a mainstream language.  So, both of us are stumbling around a bit here.

 

For the classes you have used (linked to in your blog) is there some documentation laying out the methods and properties available for them?  Neither my son or I are going to be very good at figuring this stuff out on our own just stepping through the code.



#4 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 24 March 2014 - 09:52 AM   Best Answer

You can just copy my Controller code to a class and then use that class as follows:

 

private static OneWireTemperatureSensorController _tempertureController;
public static void Main()
{
_tempertureController = new OneWireTemperatureSensorController(Pins.GPIO_PIN_D0);
     while (true)
     {
                Tick(null);
                //Thread.Sleep(10 * 1000 ); //sleep 10 seconds
                Thread.Sleep(1000 * 60 * 30); //sleep 30 minutes
     }
}


private static void Tick(object state)
{
    var temp = _tempertureController.ReadTemperatureToConsole(TemperatureEnum.Celcius, false);
} 
The temperature then gets logged to your Console window, so there you will see the temperature readings. 
 
Hope this is easy to read, if not ask away!


#5 fredk

fredk

    New Member

  • Members
  • Pip
  • 3 posts

Posted 24 March 2014 - 05:47 PM

Well, that would work to get the sensor going.  The code bit you posted makes sense to me.  Hmm.  This will work as a temporary solution until we get a better handle on c# and netmf.

 

I guess the other option is to upgrade my son's laptop to windows 7/8 and work with netmf 4.3  Looking at the Microsoft site for it there appears to be a onewire class.

 

Thanks for your help.



#6 Tobias Vandenbempt

Tobias Vandenbempt

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts
  • LocationGenth, Belgium

Posted 25 March 2014 - 07:49 AM

Of course the wiring is important as well(don't forget the resistor!) but I think it's clear on the image.

 

If it doesn't work, or it does. Let us know :) 

Good luck






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.