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

OneWire ALPHA


  • Please log in to reply
167 replies to this topic

#1 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 29 August 2010 - 06:31 PM

WARNING: This is an experimental firmware intended for advanced users to get the feedback during early development phase. This is NOT an official build by Chris and his team. If you have any 1-Wire device, and you know how to use MFDeploy to update the firmware, and you are willing to help, this may be for you.

Edit 2011-03-31: Due to popular demand updated to the latest version based on v4.1.1 beta 1 firmware - for both Netduino and Netduino Plus

Attached is a zip archive that contains firmware with native 1-Wire driver, CW.NETMF.OneWire.dll (file version 1.0.5.0) where OneWire class is implemented and a sample application. Recommended steps:

  • Unzip attached archive,
  • Use MFDeploy to flash the firmware,
  • Wire your 1-Wire device to Netduino (pull-up resistor is mandatory),
  • Open CW.NETMF.OneWireTestApp.csproj in Visual Studio 2010,
  • If needed, adjust pin number in OneWire constructor (Program.cs line #43),
  • If needed, adjust 1-Wire communication code depending on your particular device,
  • Build, Deploy and run the demo application.
The previous (ALPHA) version limitations & known issues have been resolved and fixed, all 1-Wire commands with the exception of Alarm Search are implemented. The code is based on the latest available official source 4.1.1.0 beta 1. A helper class that wraps DS18B20 commands is also included.

Implementation Note: I was not able to properly calibrate HAL microsecond delay functions, so I have used slow timer (~22 µs resolution) where suitable and resorted to using pin state changing function to achieve shorter (<10 µs) delays. I am not really happy with this solution and I will change it in future version.[i]

I have used the following devices during development:

  • 5× DS18B20 Digital Thermometer
  • 2× DS1990A+F3 Serial Number iButton
Sample code snippets (for more please have a look at Program.cs in OneWireTestApp project):

public static void Main()
{
  var oneWire = new OneWire(Pins.GPIO_PIN_D0); // Adjust the pin if necessary
  if(oneWire.Reset())
  {
    // DS18B20 Thermometer
    oneWire.WriteByte(OneWire.SkipRom); // Address all devices
    oneWire.WriteByte(DS18B20.ConvertT);
    Thread.Sleep(750);                  // Wait Tconv (for default 12-bit resolution)

    oneWire.Reset();
    oneWire.WriteByte(OneWire.SkipRom);
    oneWire.WriteByte(DS18B20.ReadScratchpad);

    // Read just the temperature (2 bytes)
    var tempLo = oneWire.ReadByte();
    var tempHi = oneWire.ReadByte();
    var temp = DS18B20.GetTemperature(tempLo, tempHi); // ((short)((tempHi << 8) | tempLo))/16F
    Debug.Print(temp.ToString());
  }
  ThreadSleep(Timeout.Infinite);
}
Detecting number of devices present on the bus:

  // ...
  if(oneWire.Reset())
  {
    var rom = new byte[8]; // 64-bit
    oneWire.WriteByte(OneWire.ReadRom);
    oneWire.Read(rom);
    if(OneWire.ComputeCRC(rom, count:7) != rom[7])
    {
      // Failed CRC indicates presence of multiple slave devices on the bus
      Debug.Print("Multiple devices present");
    }
    else
    {
      Debug.Print("Single device present");
    }
  }
Enumerating all devices on the bus:

  // ...
  var rom = new byte[8]; // 64-bit
  var deviation = 0;  // Search result
  do
  {
    if((deviation = oneWire.Search(rom, deviation)) == -1)
      break;
    if(OneWire.ComputeCRC(rom, count:7) == rom[7])
    {
      // Found a valid device ID
      Debug.Print(OneWireExtensions.BytesToHexString(rom));
    }
  }
  while(deviation > 0);

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 29 August 2010 - 07:34 PM

Awesome! One really quick note... For firmware enhancements like this, be sure to put the changes/new features in a custom namespace (not one starting with Netduino or SecretLabs). Since we support the Netduino hardware, we need to make sure people understand what comes from us and what comes from the community. That said, adding OneWire support to the main firmware is on our short list...so we'd love to find a way to incorporate your contributions into the trunk and recognize you for them... :) Chris

#3 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 29 August 2010 - 09:05 PM

For firmware enhancements like this, be sure to put the changes/new features in a custom namespace (not one starting with Netduino or SecretLabs). Since we support the Netduino hardware, we need to make sure people understand what comes from us and what comes from the community.

Chris, I completely understand your concerns, and I agree. Personally, I would prefer using SecretLabs...Netduino namespace to indicate what the code is for, not whom it is developed by (a quote from Names of Namespaces: The namespaces belonging to a particular technology will have the same first and second level identifiers (Company.technology.*). And what company should I use if I am writing code as a single person, or a team of individuals not associated with any company?).

Thus, I would prefer the possibility to use namespaces like SecretLabs.NETMF.Hardware.Contrib, SecretLabs.NETMF.Hardware.Netduino.Experimental or similar. Of course, I will adhere to any rule we settle on.

That said, adding OneWire support to the main firmware is on our short list...so we'd love to find a way to incorporate your contributions into the trunk and recognize you for them...

I will be glad to contribute my code, the process we discussed in our PM conversation still applies. At this time, I just need some feedback from the community members to make sure the code reaches certain quality before I give it to your team (and save you from the necessity to spend time fixing the most stupid bugs ;- )

#4 Antioch

Antioch

    New Member

  • Members
  • Pip
  • 4 posts

Posted 31 August 2010 - 06:03 PM

Chris, I completely understand your concerns, and I agree. Personally, I would prefer using SecretLabs...Netduino namespace to indicate what the code is for, not whom it is developed by


I agree. Especially if the SecretLabs people will take this code and insert it into the official firmware in which case the code will certainly be "officially" from SecretLabs.

#5 Websteria

Websteria

    Member

  • Members
  • PipPip
  • 25 posts

Posted 02 September 2010 - 06:18 PM

I agree. Especially if the SecretLabs people will take this code and insert it into the official firmware in which case the code will certainly be "officially" from SecretLabs.


Please implement this same change on the main firmware. I need the Analog fix in there too! :-)

#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 08 September 2010 - 10:20 AM

Does anybody from those who downloaded the firmware and possibly tried it have any feedback? How should I interpret the silence, with regard to initial eager requests? Please let me know whether it works or not with your device, so I can fix possible problems and publish the code. Thanks in advance.

#7 Szymon

Szymon

    Advanced Member

  • Members
  • PipPipPip
  • 108 posts
  • LocationPoland, Krakow

Posted 09 September 2010 - 09:19 AM

Does anybody from those who downloaded the firmware and possibly tried it have any feedback? How should I interpret the silence, with regard to initial eager requests? Please let me know whether it works or not with your device, so I can fix possible problems and publish the code. Thanks in advance.


Hi CW2,
I finally got to look at this. I uploaded your firmware and tested with one DS18B20 sensor. I'm happy to report that it works fine with your demo app :-)

Did you managed to implement the search function? I think this is the only important thing missing from the native code. I compare it to arduino version http://www.pjrc.com/...bs_OneWire.html

The Skip and Select methods can be implemented in managed code because it only sends a command with WriteByte. We can also compute the Crc.

I can send you my version of Micro DallasTemperature library if you want to test it.


Edit: Oh, and I would definitively move the managed OneWire class to another assembly (at least until it makes to official firmware). Having two versions of the same assembly totally messed my project references.

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 09 September 2010 - 09:24 AM

CW2, We'll download this and play with it soon as well. Your efforts here are really appreciated. Chris

#9 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 09 September 2010 - 10:57 AM

I finally got to look at this. I uploaded your firmware and tested with one DS18B20 sensor. I'm happy to report that it works fine with your demo app :-)

This is really great news, thanks Szymon!

Did you managed to implement the search function?

Yes, there will be Search function in the next version.

Oh, and I would definitively move the managed OneWire class to another assembly (at least until it makes to official firmware). Having two versions of the same assembly totally messed my project references.

Yep, sorry about that Posted Image

#10 sweetlilmre

sweetlilmre

    Advanced Member

  • Members
  • PipPipPip
  • 62 posts

Posted 23 September 2010 - 03:37 PM

Does anybody from those who downloaded the firmware and possibly tried it have any feedback? How should I interpret the silence, with regard to initial eager requests? Please let me know whether it works or not with your device, so I can fix possible problems and publish the code. Thanks in advance.


Hi,

I have been meaning to look at this but I only just found a 1-wire supplier. I should be able to get hold of some sensors next week and I'll give it a go.

Looks like fun!
-(e)

#11 bxb

bxb

    New Member

  • Members
  • Pip
  • 6 posts

Posted 11 October 2010 - 07:12 PM

Hi CW2, I gave your FW a try, but I did make one mistake. I ordered a DHT11 sensor with my shield, in the believe that this sensor speaks the Maxim OneWire protocol. But meanwhile I found out that this is not the case. Its a proprietary single wire protocol, but also with timing requirements in the microseconds range, so no managed code here. So I have 2 choices now, writing my own native driver for this sensor (no idea how hard that would be), or switch to another sensor. Does anybody know of a cheap combined temp/humidity sensor (I know of Sensirion, but can't find a good price for a hobby project). bye, sascha

#12 boris

boris

    New Member

  • Members
  • Pip
  • 2 posts

Posted 18 October 2010 - 07:27 PM

Hi CW2, I tested your firmware with one DS 18B20 and my netduino, it work well. Thank's a lot ;-)

#13 boris

boris

    New Member

  • Members
  • Pip
  • 2 posts

Posted 29 October 2010 - 09:27 AM

Any news about the inclusion of the OneWire protocol in the official firmware ? It should be very helpfull for me. Thank's

#14 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 02 November 2010 - 08:24 AM

Any news about the inclusion of the OneWire protocol in the official firmware ?

The code has been submitted to Secret Labs team and is now undergoing evaluation, review etc. It may still require some iterations to improve thing here and there, so please be patient. Anyway, thanks for your feedback, I am glad it works for you.

#15 peterfjorgensen

peterfjorgensen

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationDenmark

Posted 07 November 2010 - 07:05 PM

This is just cool. I just found this post and as I had some iButtons (DS1990A+F5) laying around from another projekt where I never got to use it, I just had to try this out. I just works as a dream. Can't wait until this becomes part of the base firmware. Good work. Peter microframework.dk

#16 spur

spur

    Member

  • Members
  • PipPip
  • 27 posts

Posted 03 February 2011 - 06:28 PM

The demo application works great for me, thanks very much! :D I'm looking forward to this feature being in the official firmware. Any word on when that will happen?

#17 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 February 2011 - 07:20 PM

The demo application works great for me, thanks very much! :D

I'm looking forward to this feature being in the official firmware. Any word on when that will happen?


The goal is v4.1.2. v4.1.0.6 is about to go gold (and v4.1.1 is about to go into beta), so we'll be able to start on v4.1.2 within a week or two.

Chris

#18 spur

spur

    Member

  • Members
  • PipPip
  • 27 posts

Posted 03 February 2011 - 07:56 PM

The goal is v4.1.2. v4.1.0.6 is about to go gold (and v4.1.1 is about to go into beta), so we'll be able to start on v4.1.2 within a week or two.

Chris


Thanks for the update!

#19 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 04 February 2011 - 08:32 AM

Uh, I've never seen this post before. Nice work CW2. Edit: You haven't attached your source, I see? ;p

#20 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 04 February 2011 - 02:26 PM

I discovered that I have 18S20 sensors ("S" not "B"), and they output different. I goggled some and think this is the correct solution. I don't have any 18B20 that I can compare to.


          oneWire.WriteByte(0xCC);  // Skip ROM
          oneWire.WriteByte(0x44);  // Convert T
          Thread.Sleep(750);        // Tconv (default 12-bit resolution)

            
          oneWire.Reset();
          oneWire.WriteByte(0xCC);  // Skip ROM
          oneWire.WriteByte(0xBE);  // Read Scratchpad

          var tempLo = oneWire.ReadByte();
          var tempHi = oneWire.ReadByte();
          var _byte2 = oneWire.ReadByte();
          var _byte3 = oneWire.ReadByte();
          var _byte4 = oneWire.ReadByte();
          var _byte5 = oneWire.ReadByte();
          var tempR = oneWire.ReadByte();
          var tempC = oneWire.ReadByte();

          var _temp = ((short)((tempHi << 8) | tempLo));
          
          //DS18S20   
          double _temp18s20 = (float)(_temp >> 1) - 0.25 + ((float)(tempC - tempR) / (float)tempC);

          //DS18B20, DS1822
          double _temp18b20 = (float)_temp * 0.0625F;

          Debug.Print("S: " + _temp18s20);

          Debug.Print("B:" + _temp18b20); 

          //_temp18s20 is in Celsius.


I like to see the search function, so I can have multiple sensors.

/Ken




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.