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

#101 Angus

Angus

    New Member

  • Members
  • Pip
  • 8 posts
  • LocationBrisbane, Australia

Posted 20 February 2012 - 10:56 PM

Hi everybody, Finally got some success last night and read some temps from my DS18B20. I flashed the firmware, added the DS18B20 class to my project, added a reference to the Onewire dll shipped in the zip, and just kept getting error after error when debugging the app. It would just crash out when loading saying it could not reference the OneWire.dll. I eventually tracked back a little further in the logs and it was saying the Onewire dll checksum had failed validation. I recompiled the solution provided in the zips, cleared my bin and debug folders, and then re-added the reference to the newly compiled dll. Bingo, all up and working, and was a balmy 19.5 degrees Celsius in Brisbane last night around 10PM. Just thought I'd post this up in case it would help someone else. Angus.

#102 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 27 February 2012 - 10:51 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.


Hi! I have a DS18S20+, and it seems that it is also different. Although I get better results with your method, the temperature reading is still off by circa 3 degrees Celsius. Didn't have time to test it with lower temperatures yet (tomorrow).

Do you think it is possible I damaged my sensor when I reversed it? (pin1->pin3, pin3->pin1)? I misread the datasheet at first...

Regards,
Miha.

#103 Miha

Miha

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts

Posted 28 February 2012 - 08:39 AM

Hi! I have a DS18S20+, and it seems that it is also different. Although I get better results with your method, the temperature reading is still off by circa 3 degrees Celsius. Didn't have time to test it with lower temperatures yet (tomorrow).


It measures 3 degrees below using either parasite or direct power.

I'm also having problems using OneWire in my own program. I copied OneWire.cs, DS18B20.cs and OneWireExtensions.cs (though not needed) to my project and it compiles fine, but when I run it, it breaks on instantiating OneWire with:
#### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) ####

I'll buy a DS18B20 senzor and see what kind of results I'll get with this one.

Regards,
Miha.

#104 satkye

satkye

    Member

  • Members
  • PipPip
  • 13 posts

Posted 04 March 2012 - 09:24 PM

When runbning the test app. I keep getting "The thread '<No Name>' (0x2) has exited with code 0 (0x0)." Never mind i figured it out

#105 h3mp

h3mp

    Member

  • Members
  • PipPip
  • 21 posts

Posted 22 March 2012 - 08:02 PM

This is brilliant - thanks guys... Just got my first little netduino project running - just a DS18B20 being read then displayed on a 4 Digit 7-Seg display All works beautifully thanks to this :) Mark

#106 GrZeCh

GrZeCh

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationPoland

Posted 28 March 2012 - 11:15 AM

Hello, has someone maybe tried to connect to DS2408 ("1-Wire 8-Channel Addressable Switch" - http://www.maxim-ic....dex.mvp/id/3818) to 1-wire on netduino? Regards EDIT: Arduino code: https://github.com/q...e/master/DS2408

#107 GrZeCh

GrZeCh

    Member

  • Members
  • PipPip
  • 29 posts
  • LocationPoland

Posted 03 April 2012 - 05:02 PM

I want to thank CW2 for helping me with proper handling of DS2408 because whatever I was doing it didn't worked. 1-2 messages to and from CW2 solved my problem right away. Thank you CW2 once again.

Here is my updated code for DS2408 and DS18B20 onewire devices:

    /// <summary>
    /// DS18B20 Programmable Resolution 1-Wire Digital Thermometer
    /// </summary>
    public class DS18B20 : OneWireDevice
    {
        public const byte FamilyCode = 0x28;

        // Commands
        public const byte ConvertT = 0x44;
        public const byte CopyScratchpad = 0x48;
        public const byte WriteScratchpad = 0x4E;
        public const byte ReadPowerSupply = 0xB4;
        public const byte RecallE2 = 0xB8;
        public const byte ReadScratchpad = 0xBE;

        internal DS18B20(OneWire core, byte[] rom) : base(core, rom) { }

        private float Temperature()
        {
            // Write command and identifier at once
            var matchRom = new byte[9];
            Array.Copy(_rom, 0, matchRom, 1, 8);
            matchRom[0] = OneWire.MatchRom;

            _core.Reset();
            _core.Write(matchRom);
            _core.WriteByte(DS18B20.ConvertT);
            System.Threading.Thread.Sleep(750);  // Wait Tconv (for default 12-bit resolution)

            _core.Reset();
            _core.Write(matchRom);
            _core.WriteByte(DS18B20.ReadScratchpad);

            // Read just the temperature (2 bytes)
            var tempLo = _core.ReadByte();
            var tempHi = _core.ReadByte();

            return ((short)((tempHi << 8) | tempLo)) / 16F;
        }

        public static float getTemperature(string oneWireAddress)
        {
            foreach (var item in Program.deviceNetwork)
            {
                if ((item.Address == oneWireAddress) && (item as DS18B20) != null)
                {
                    return (item as DS18B20).Temperature();
                }
            }
            return -100;
        }
    }

    /// <summary>
    /// DS2408 8 I/O
    /// </summary>
    public class DS2408 : OneWireDevice
    {
        public const byte FamilyCode = 0x29;
        internal DS2408(OneWire core, byte[] rom) : base(core, rom) { }

        private void Set(string activatedPorts)
        {
            // Write command and identifier at once
            var matchRom = new byte[9];
            Array.Copy(_rom, 0, matchRom, 1, 8);
            matchRom[0] = OneWire.MatchRom;

            _core.Reset();
            _core.WriteByte(OneWire.SkipRom);
            _core.WriteByte(0x5A); // Channel Access Write command
            byte statusSet = ActivatePorts(activatedPorts);

            _core.WriteByte(statusSet);
            _core.WriteByte((byte)(~statusSet));

            var verification = _core.ReadByte();
            var status = _core.ReadByte();

            if (verification == 0xAA)
            {
                // status should be 0xFE (?)
            }
            _core.Reset();
        }

        public static void setActivePorts(string ports, string oneWireAddress)
        {
            foreach (var item in Program.deviceNetwork)
            {
                if ((item.Address == oneWireAddress) && (item as DS2408) != null)
                {
                    (item as DS2408).Set(ports);
                }
            }
        }

        private byte ActivatePorts(string ports)
        {
            if (ports == null || ports == "")
            {
                return 0xFF;
            }
            else
            {
                var portsArray = ports.Split((",").ToCharArray());
                Hashtable ht = new Hashtable() { { "0", 1 }, { "1", 2 }, { "2", 4 }, { "3", 8 }, { "4", 16 }, { "5", 32 }, { "6", 64 }, { "7", 128 } };
                int number = 255;
                for (int i = 0; i < portsArray.Length; i++)
                {
                    number = number - int.Parse((ht[portsArray[i]]).ToString());
                }
                return byte.Parse(number.ToString());
            }
        }
    }

I'm using OneWireNetwork.cs class from OneWireTestApp sent by Valkyrie-MT here:

http://forums.netdui...4488#entry14488

I've made small change to Discover method by replacing

_devices.Add(new DS2408(this.core, newrom));

with

if (rom[0] == DS2408.FamilyCode)
                    {
                        _devices.Add(new DS2408(this.core, newrom));
                    }
                    if (rom[0] == DS18B20.FamilyCode)
                    {
                        _devices.Add(new DS18B20(this.core, newrom));
                    }

OneWire deviceNetwork variable which defines OneWire port must be set to public static to make my classes to work.

Sample of usage:

This sets port nr 2 to on:
DS2408.setActivePorts("2", "000000058D06");
This sets port nr 2 and 5 to on:
DS2408.setActivePorts("2,5", "000000058D06");

This reads temperature:
Debug.Print(DS18B20.getTemperature("0000039F6BB9").ToString());

Probably this could be done better but for me it works. Of course if someone could make it batter then it would be great.

#108 mrxer

mrxer

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationAustralia

Posted 12 April 2012 - 12:04 PM

How do i get my netduino to support 1wire ( onewrire) protocol? I am using ClrInfo.clrVersion: 4.1.2821.0 ClrInfo.clrVendorInfo: Netduino by Secret Labs LLC ClrInfo.targetFrameworkVersion: 4.1.2821.0 SolutionReleaseInfo.solutionVersion: 4.1.0.4 SolutionReleaseInfo.solutionVendorInfo: Netduino by Secret Labs LLC SoftwareVersion.BuildDate: Sep 29 2010 SoftwareVersion.CompilerVersion: 400771 Get this error on line ... // TODO: Change pin according to the actual wiring oneWire = new OneWire(Pins.GPIO_PIN_D0); #### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (1) #### #### Message: #### OneWireTestApp.Program::Main [IP: 0020] #### A first chance exception of type 'System.NotSupportedException' occurred in OneWireTestApp.exe Uncaught exception

tony


#109 ccfoo242

ccfoo242

    Member

  • Members
  • PipPip
  • 16 posts

Posted 25 April 2012 - 02:35 AM

How do i get my netduino to support 1wire ( onewrire) protocol?


Did you load the firmware from the first post?

#110 ccfoo242

ccfoo242

    Member

  • Members
  • PipPip
  • 16 posts

Posted 25 April 2012 - 02:38 AM

Why do I ALWAYS get the power on default of 85C when reading temp? I've seen this mentioned in some other places and people allude to it being wiring but never state what was wired wrong. I can read all bytes the scratchpad, but never get a temperature other than 85C. I should add that I'm a hardware noob.

#111 ccfoo242

ccfoo242

    Member

  • Members
  • PipPip
  • 16 posts

Posted 25 April 2012 - 03:42 AM

Here's how I have this wired. Its the waterproof version from adafruit:

Posted Image

Posted Image

Do I need to have the shielding connected to ground?

#112 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 25 April 2012 - 06:12 AM

Why do I ALWAYS get the power on default of 85C when reading temp? I've seen this mentioned in some other places and people allude to it being wiring but never state what was wired wrong. I can read all bytes the scratchpad, but never get a temperature other than 85C. I should add that I'm a hardware noob.

This is a silly question, but do you actually perform the temperature measurement (i.e. issue 'Convert T' 0x44 command) before reading the scratchpad?

#113 ccfoo242

ccfoo242

    Member

  • Members
  • PipPip
  • 16 posts

Posted 25 April 2012 - 10:25 AM

This is a silly question, but do you actually perform the temperature measurement (i.e. issue 'Convert T' 0x44 command) before reading the scratchpad?


Looking over my code again I see when I moved it into a loop I wasn't calling Reset before ConvertT.

Argh! Thanks for making me double check myself. :)

#114 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 April 2012 - 07:22 AM

Hi bloughead, CW2 can probably pitch in with better diagnostics on this. That's a very interesting error which may or may not be related to the OneWire support. But to start out: can you tell what line of code is causing the issue? Are you targeting .NET MF 4.1 (in the project properties > .NET MF dialog)? Chris

#115 satkye

satkye

    Member

  • Members
  • PipPip
  • 13 posts

Posted 27 April 2012 - 05:44 PM

Hello, Just wanted to make sure. With the onewire firmware which I can get to work. Is there no support for SD/micro sd which doesnt work for me.

#116 ccfoo242

ccfoo242

    Member

  • Members
  • PipPip
  • 16 posts

Posted 27 April 2012 - 05:49 PM

Hello,

Just wanted to make sure. With the onewire firmware which I can get to work. Is there no support for SD/micro sd which doesnt work for me.


It appears a rebuild of the firmware would be required. I tried using an add-on sd card shield but the IO library to support is part of 4.2 (I think).

#117 satkye

satkye

    Member

  • Members
  • PipPip
  • 13 posts

Posted 27 April 2012 - 06:32 PM

That is what I thought. Maybe if we ask the Firmware gods nicely we can get it. Or the 4.2 firmware will finally come out. For now i think I will have to update to 4.2 and deal with my sensors for this project later. I was really hopeing to get this done by July.

#118 pixpix

pixpix

    New Member

  • Members
  • Pip
  • 1 posts

Posted 04 June 2012 - 08:29 AM

Hi phantom, grimbouk:

When the .NET MF 4.2 firmware is finished in the next month or so, we'll be happy to build a custom version with CW2's latest OneWire feature...for Netduino, Netduino Plus, and Netduino Mini.

Chris


Hi Chris,

I appreciate all the work you do, but I am waiting almost a year for firmware with OneWire support and extra memory for my Netduino Plus project. So far I can use the only available firmware with OneWire based on v4.1.1 beta 1 and get out of memory exceptions from time to time which make my device unstable and due to lack of memory for bigger buffers also slow. I know your answer will be to wait for release of final 4.2 firmware, but for how long? 38K+ RAM or even less would help me definitely. I think OneWire support is also the most demanded feature according to poll I remember seen somewhere on the forum or other Netduino pages.

Thanks,
Jakub

#119 ross

ross

    New Member

  • Members
  • Pip
  • 1 posts

Posted 08 July 2012 - 06:34 AM

Hi all

I'm new to Netduino but not c#.

I've tried implementing the oneWire application - without much luck.

I've installed the CW firmware on the Netduino.

For some reason it's not picking up the correct dll - but I'm mystified as to why it doesn't as it is there in the path where it should be
- and it compiles OK.

------ Rebuild All started: Project: OneWire_test, Configuration: Debug Any CPU ------
OneWire_test -> C:\Users\Me\Documents\Visual Studio 2010\Projects\OneWire_test\OneWire_test\bin\Debug\OneWire_test.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


deploys OK


Incrementally deploying assemblies to device
Deploying assemblies for a total size of 9200 bytes
Assemblies successfully deployed to device.

but when going through debug to isolate why it's not working:

Rebooting...
Found debugger!
Create TS.
Loading start at 13cc08, end 14fee8
Attaching file.
Assembly: mscorlib (4.1.2821.0) (3880 RAM - 33236 ROM - 19134 METADATA)
Attaching file.
Assembly: Microsoft.SPOT.Native (4.1.2821.0) (1144 RAM - 6516 ROM - 4479 METADATA)
Attaching file.
Assembly: Microsoft.SPOT.Hardware (4.1.2821.0) (1760 RAM - 11552 ROM - 7395 METADATA)
Attaching file.
Assembly: Microsoft.SPOT.Hardware.SerialPort (4.1.2821.0) (512 RAM - 3488 ROM - 1543 METADATA)
Attaching file.
Assembly: Microsoft.SPOT.IO (4.1.2821.0) (740 RAM - 4620 ROM - 2522 METADATA)
Attaching file.
Assembly: System.IO (4.1.2821.0) (1548 RAM - 13292 ROM - 5862 METADATA)
Attaching file.
Assembly: Microsoft.SPOT.Hardware.Usb (4.1.2821.0) (580 RAM - 3740 ROM - 1844 METADATA)
Attaching file.
Assembly: SecretLabs.NETMF.Hardware (4.1.0.0) (256 RAM - 1108 ROM - 491 METADATA)
Attaching file.
Assembly: SecretLabs.NETMF.Diagnostics (4.1.0.0) (180 RAM - 440 ROM - 166 METADATA)
Attaching file.
Assembly: SecretLabs.NETMF.IO (4.1.0.0) (220 RAM - 564 ROM - 279 METADATA)
Loading Deployment Assemblies.
Attaching deployed file.
Assembly: SecretLabs.NETMF.Hardware.Netduino (4.1.0.0) (268 RAM - 796 ROM - 423 METADATA)
Attaching deployed file.
Assembly: OneWire_test (1.0.0.0) (588 RAM - 7648 ROM - 2331 METADATA)
Attaching deployed file.
Assembly: CW.NETMF.OneWire (1.0.0.0) (236 RAM - 756 ROM - 429 METADATA)
Invalid native checksum: CW.NETMF.OneWire 0x0!=0xA1BB949
Resolving.
Link failure: some assembly references cannot be resolved!!
Assembly: OneWire_test (1.0.0.0) needs assembly 'CW.NETMF.OneWire' (1.0.0.0)
Error: a3000000
Waiting for debug commands...
The program '[16] Micro Framework application: Managed' has exited with code 0 (0x0).

This is really frustrating! Any clues what to do?

When is onewire support going to be implemented in firmware?

#120 CyberChris

CyberChris

    New Member

  • Members
  • Pip
  • 2 posts

Posted 24 August 2012 - 06:47 PM

Hello, when will we see a 4.2 Firmware with the CW2 OneWire support compiled in? I just installed the new NETMF 4.2 QFE2 and the new netduino 4.2 sdk, but all my projects used the CW2 OneWire library. Unless a new Firmware with OneWire support is released, it makes no sense to me to port my projects to 4.2.... Regards, Chris




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.