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.
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);
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
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 ;- )
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.
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! :-)
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.
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.
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.
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.
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
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.
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
The demo application works great for me, thanks very much!
I'm looking forward to this feature being in the official firmware. Any word on when that will happen?
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.