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.
Is there any proper documentation for OneWire class?
Hi. I have found many examples of how to use a DS18B20 and exactly what code to write. However, I don't understand the why. Microsoft has some documentation for the Microsoft.SPOT.Hardware.OneWire class, however there are no descriptions. It mentions all of the methods, but there is no hint to exact implementation. What I specifically need help with is something like this;
[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I know the 'ow' is the onewire object and the WriteByte() is the method, but why am I using '0xBE'? What is that?[/color]
Most of the .NET MF classes that provide functionality of hardware interfaces or protocols assume prior knowledge, often at rather deep level. An electronic engineer usually has to look into the specification or device datasheet, in this particular case DS18B20 datasheet provides detailed description of 1-Wire protocol communication and commands - these are that 'magic' 0xXX numbers in the code.
There are two kinds of 1-Wire commands, "ROM" and "Function": "ROM" commands are used for addressing and are supported by all 1-Wire devices, "Function" commands are device-specific.
0xCC is "SKIP ROM" command, which is used to address multiple slaves at once, for example when you want to start temperature conversion of all DS18B20 present on the bus (including case when there is only one device),
0xBE is "READ SCRATCHPAD" command to get the temperature measurement from a particular DS18B20 device.
It is considered good practice to use constants instead of hard-coded magic numbers, so you could define for example OneWireCommand class or enum with SkipRom = 0xCC, ReadScratchpad = 0xBE and use symbolic names, e.g. ow.WriteByte(OneWireCommand.SkipRom). I've done this in my alternative implementation.
Hi. I have found many examples of how to use a DS18B20 and exactly what code to write. However, I don't understand the why. Microsoft has some documentation for the Microsoft.SPOT.Hardware.OneWire class, however there are no descriptions. It mentions all of the methods, but there is no hint to exact implementation. What I specifically need help with is something like this;
[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I know the 'ow' is the onewire object and the WriteByte() is the method, but why am I using '0xBE'? What is that?[/color]
[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Same here, what is the '0xCC' ?[/color]
When do I ReadByte() or WriteByte() or TouchReset()? What exactly do the methods mean and which ones do you use, and when? I am a .NET engineer for my day job, however I am used to having SDK docs for everything I code. Writing standard software to be run on Windows 7 or 8 I understand. The lack of documentation for the OneWire class has me very frustrated!
Can anyone please help and point me in the right direction? Thanks.
Hi. I have found many examples of how to use a DS18B20 and exactly what code to write. However, I don't understand the why. Microsoft has some documentation for the Microsoft.SPOT.Hardware.OneWire class, however there are no descriptions. It mentions all of the methods, but there is no hint to exact implementation. What I specifically need help with is something like this;
[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I know the 'ow' is the onewire object and the WriteByte() is the method, but why am I using '0xBE'? What is that?[/color]
Most of the .NET MF classes that provide functionality of hardware interfaces or protocols assume prior knowledge, often at rather deep level. An electronic engineer usually has to look into the specification or device datasheet, in this particular case DS18B20 datasheet provides detailed description of 1-Wire protocol communication and commands - these are that 'magic' 0xXX numbers in the code.
There are two kinds of 1-Wire commands, "ROM" and "Function": "ROM" commands are used for addressing and are supported by all 1-Wire devices, "Function" commands are device-specific.
0xCC is "SKIP ROM" command, which is used to address multiple slaves at once, for example when you want to start temperature conversion of all DS18B20 present on the bus (including case when there is only one device),
0xBE is "READ SCRATCHPAD" command to get the temperature measurement from a particular DS18B20 device.
It is considered good practice to use constants instead of hard-coded magic numbers, so you could define for example OneWireCommand class or enum with SkipRom = 0xCC, ReadScratchpad = 0xBE and use symbolic names, e.g. ow.WriteByte(OneWireCommand.SkipRom). I've done this in my alternative implementation.
If I could hijack this thread to post an arguably related follow-on question:
My Microsoft.SPOT.Hardware namespace doesn't have a OneWire class. Which file do I have to reference to pick this up please?
How does the class hook into any specific hardware implementation? Is this done at a low level or via a C# driver? In my specific case I'm talking about Netduino Go.
Wow! Thank you all for your excellent and very speedy responses. You have given me several places to go find what I'm looking for. Thanks! Now it's off to do some research.
My Microsoft.SPOT.Hardware namespace doesn't have a OneWire class. Which file do I have to reference to pick this up please?
You'd need to add Microsoft.SPOT.Hardware.OneWire.dll assembly reference to your project.
How does the class hook into any specific hardware implementation? Is this done at a low level or via a C# driver? In my specific case I'm talking about Netduino Go.
OneWire methods are native, except FindAllDevices() which is managed. The 1-Wire protocol is implemented via 'bit-banging', i.e. in software (native driver).
As far as I know, Netduino Go does not include OneWire, so you'll probably get 'not implemented' exception when calling OneWire methods. If I remember it correctly, Chris has mentioned in one of the GoBus-related posts that they are planning 1-Wire profile support, which enables use of 1-Wire Go modules. So you'll be able to connect 1-Wire device, such as DS18B20 temperature sensor, to this 1-Wire module and OneWire methods will provide its functionality via virtualized 1-Wire communication link (over GoBus transport).
It is considered good practice to use constants instead of hard-coded magic numbers, so you could define for example OneWireCommand class or enum with SkipRom = 0xCC, ReadScratchpad = 0xBE and use symbolic names, e.g. ow.WriteByte(OneWireCommand.SkipRom). I've done this in my alternative implementation.
Thank you. Emphasis added to the quote is by me. I was twitching about this before I got to your post. I'm new to netduino, C#, .NET, all that, but always make many many comments in your code. Two recent highlights while porting Adafruit ST7735 from AVR to PIC32: