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

Dallas 1-wire support library


  • Please log in to reply
6 replies to this topic

#1 Xtrophic

Xtrophic

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationSweden

Posted 01 February 2013 - 08:27 PM

Hi,

 

I just wanted to share the little support library I created for my temperature sensor application that deals with 1-wire operations. 

 

The library is currently only supporting DS18S20 and DS18B20 temp sensors, but I created the library to be extendable in the future. 

 

I had fun creating it and it seems to work pretty good. Been logging temperature for the past 2 weeks every 5 mins from 3 probes on the same line. (Although now I rewired the NP2 to attempt to get an LCD display working so it's currently offline hehe).

 

Also here is the code I am using to probe the temp:

 

OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
OutputPort oneWirePort = new OutputPort(Pins.GPIO_PIN_D7, false);


try {               
    Microsoft.SPOT.Hardware.OneWire wire = new OneWire(oneWirePort);
    var devices = wire.FindAllDevices();
    DallasOneWireDevices collection = new DallasOneWireDevices();   // Contains type defined devices with helper commands     

    foreach (byte[] device in devices) {         
        collection.AddDevice(device);   // If supported, it will add as the correct device type it identifies it as.          
    }        

    led.Write(true); // Just lights up the led while conducting 1-wire business :)  

    // Loop through all devices, and if we find any DS18B20, then we set the resolution to 12-bit.     
    foreach (OneWireTemperatureProbe probe in collection) {      
        DeviceDS18B20 probe2 = probe as DeviceDS18B20;           
        if (probe2 != null)                     
            probe2.SetResolution(12, wire);   
    }                
    collection.SendCommandToAll(OneWireDs18b20Reference.CmdConvert, 1050, wire);    // Sends the convert command to all devices connected, and waits 1050ms   
    foreach (OneWireTemperatureProbe probe in collection) {          
        probe.ReadScratchPad(wire); // Reads the scratchpad and updates the last temperature property (which is used below)                   
        Debug.Print(probe.ToString());          
    }         
}        
catch (Exception ex)       
{      
    Debug.Print(ex.ToString());          
}        
led.Write(false);

 

 

Attached Files



#2 Don King

Don King

    Advanced Member

  • Members
  • PipPipPip
  • 30 posts
  • LocationLawrence, KS

Posted 27 March 2013 - 02:35 AM

 

Hi,

 

I just wanted to share the little support library I created for my temperature sensor application that deals with 1-wire operations. 

 

The library is currently only supporting DS18S20 and DS18B20 temp sensors, but I created the library to be extendable in the future. 

 

I had fun creating it and it seems to work pretty good. Been logging temperature for the past 2 weeks every 5 mins from 3 probes on the same line. (Although now I rewired the NP2 to attempt to get an LCD display working so it's currently offline hehe).

 

Also here is the code I am using to probe the temp:

         OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);        OutputPort oneWirePort = new OutputPort(Pins.GPIO_PIN_D7, false);           try            {                Microsoft.SPOT.Hardware.OneWire wire = new OneWire(oneWirePort);                var devices = wire.FindAllDevices();                DallasOneWireDevices collection = new DallasOneWireDevices();   // Contains type defined devices with helper commands                foreach (byte[] device in devices)                {                    collection.AddDevice(device);   // If supported, it will add as the correct device type it identifies it as.                }                led.Write(true); // Just lights up the led while conducting 1-wire business 
:) // Loop through all devices, and if we find any DS18B20, then we set the resolution to 12-bit. foreach (OneWireTemperatureProbe probe in collection) { DeviceDS18B20 probe2 = probe as DeviceDS18B20; if (probe2 != null) probe2.SetResolution(12, wire); } collection.SendCommandToAll(OneWireDs18b20Reference.CmdConvert, 1050, wire); // Sends the convert command to all devices connected, and waits 1050ms foreach (OneWireTemperatureProbe probe in collection) { probe.ReadScratchPad(wire); // Reads the scratchpad and updates the last temperature property (which is used below) // My code for saving the temp to a textfile on the SD card ... not included in this sample // Logger.Log(probe.DeviceId.GetHex(), probe.LastTemperature.ToString()); Debug.Print(probe.ToString()); } } catch (Exception ex) { Debug.Print(ex.ToString()); } led.Write(false);

 

 

Well done friend. I ended up getting the Netduino Plus 2, fired up your library and it works wonderfully. Thanks so much for providing the code.

 

Thanks!

 

Don



#3 Xtrophic

Xtrophic

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationSweden

Posted 27 March 2013 - 09:57 PM

I am happy it worked out for you! :)



#4 Bayzter

Bayzter

    New Member

  • Members
  • Pip
  • 4 posts

Posted 01 April 2013 - 10:27 PM

Will this support library also work with the Netduino Plus? or is it NP2 only?



#5 louyo

louyo

    Member

  • Members
  • PipPip
  • 18 posts

Posted 28 June 2013 - 02:23 PM

Dumb question I guess. I am running the 4.2 SDK and get the following error when I build:

OneWire' does not exist in the namespace 'Microsoft.SPOT.Hardware'

I do have the using Microsof.SPOT.Hardware statement included and the assembly shows up in References. 

Could you please point me to the error of my ways? Is there another version of the dll somewhere?

Thanks much,

Lou



#6 louyo

louyo

    Member

  • Members
  • PipPip
  • 18 posts

Posted 28 June 2013 - 05:22 PM

Dumb question I guess. I am running the 4.2 SDK and get the following error when I build:

OneWire' does not exist in the namespace 'Microsoft.SPOT.Hardware'

I do have the using Microsof.SPOT.Hardware statement included and the assembly shows up in References. 

Could you please point me to the error of my ways? Is there another version of the dll somewhere?

Thanks much,

Lou

oops, the dummy just found the Hardware.OneWire reference. 

Apologies.

 

Louyo



#7 a2piazza

a2piazza

    New Member

  • Members
  • Pip
  • 1 posts

Posted 20 July 2013 - 06:38 PM

Hi, I am new in micro framework programming, the code you are using to probe the temp is inside a loop?

Can you provide the wiring for the probes on the same line?

 

TKS






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.