OneWire where is the class?

OK so i’m new to NetMF but I’ve plugged my Cerbuino in, updated, made the LED flash… all pretty easy

Now i’m convinced i’m going mad. I’ve got myself a OneWire DS18B20 temp sensor

I’m tying to follow

But i cant for the life of me find the OneWire class

If i’m understanding it right
GHIElectronics.NETMF.Hardware;
GHIElectronics.NETMF.FEZ;
have been replaced with
GHI.OSHW.Hardware

ive got that but from what i can see its not in there and from what I’ve goggled it not supposed to be its in
Microsoft.SPOT.Hardware

however its just not there intellisense doesn’t recognize it, its not in the object browser, even the API reference for netmf 4.2

Doesn’t list it as one of the members, it is there in 4.3 but not 4.2.

for reference i’m using VS2012 programming in Visual Basic with netmf 4.3 RTM installed but the project is set to 4.2.

any help would be appreciated.

Thanks
Tim

That page is too old and need to be updated. In 4.1, GHI had its own one wire but on 4.2 it is moved to be part of netmf core libs. We are in the process of updating all tutorials.

Welcome to the community.

welcome Tim !

Not sure VS2012 + Netmf4.3 RTM SDK is a supported combination. That might be part of your problem.

I am not developing in 4.2 yet, so still using the 4.1 GHI-provided one-wire, but if you search here there are some other threads that talk about OW in 4.2 and there’s sample code there. I’ll be back with a new link shortly :slight_smile:

http://www.tinyclr.com/forum/topic?id=9446 is the thread

Hi,
For DS18B20, you can you this code:
This code will work with multi one-wire devices (DS18B20)


using System;
using Microsoft.SPOT;

using GHI.Premium.Hardware;
using Microsoft.SPOT.Hardware;
using System.Threading;
using System.Collections;

namespace one_wire_premium_42_libs_check
{
    public class Program
    {

        static OutputPort port;    
        static OneWire ow ;
        public static void Main()
        {
            port = new OutputPort((Cpu.Pin)28, false); //28 on G120, 27 on EMX// socket 9, pin 9 // G120 socket 4 pin 9         
             ow = new OneWire(port);
            ArrayList list;

            while (true)
            {
                Debug.Print("=======================================");
                Debug.Print("TouchReset: " + ow.TouchReset());

                list = ow.FindAllDevices();

                foreach (byte[] s in list)
                {
                    Debug.Print(s[0].ToString() + "." +
                        s[1].ToString() + "." +
                        s[2].ToString() + "." +
                        s[3].ToString() + "." +
                        s[4].ToString() + "." +
                        s[5].ToString() + "." +
                        s[6].ToString() + "." +
                        s[7].ToString() + ". Temperture: " + GetTemperture(s)
                        );

                }
                Debug.Print("Count: " + list.Count);
                list.Clear();

                //System.Threading.Thread.Sleep(2000);
            }
        }
        static String GetTemperture(byte[] ow_address)
        {
            byte[] scratchpad = new byte[9];
            ushort tempLow = 0;
            ushort tempHigh = 0;
            ushort temp = 0x0;
            int temptemp;
            float TemperatureC = 0;
            ow.TouchReset();
            ow.WriteByte((byte)Command.MatchROM);
            for (int i = 0; i < 8; i++)
            {
                ow.WriteByte((byte)ow_address[i]);
            }
            ow.WriteByte((byte)Command.StartTemperatureConversion);
            while (ow.ReadByte() == 0) { }
            ow.TouchReset();
            ow.WriteByte((byte)Command.MatchROM);
            for (int i = 0; i < 8; i++)
            {
                ow.WriteByte((byte)ow_address[i]);
            }
            ow.WriteByte((byte)Command.ReadScratchPad);
            for (int i = 0; i < 9; i++)
            {
                scratchpad[i] = (byte)ow.ReadByte();
            }
            tempLow = scratchpad[0];
            tempHigh = scratchpad[1];
            byte config = scratchpad[4];
            temp = tempLow;
            temp |= (ushort)(tempHigh << 8);
            temptemp = (((int)(tempHigh) << 8) | tempLow);
            TemperatureC = temptemp * 0.0625f;
            return TemperatureC.ToString();
        }
        enum Command
        {
            SearchROM = 0xF0,
            ReadROM = 0x33,
            MatchROM = 0x55,
            SkipROM = 0xCC,
            AlarmSearch = 0xEC,
            StartTemperatureConversion = 0x44,
            StartVoltageConversion = 0xB4,
            ReadScratchPad = 0xBE,
            WriteScratchPad = 0x4E,
            CopySratchPad = 0x48,
            RecallEEPROM = 0xB8,
            ReadPowerSupply = 0xB4,
            ScratchPadPage0 = 0x00,
            ScratchPadPage3 = 0x03
        }        
    }
}


And here is simple code in case you have only one device:


using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHI.Premium.Hardware;

namespace one_wire_premium_42_libs_check
{
    public class Program
    {
        public static void Main()
        {
            // Change this your correct pin!
           
            OutputPort myPin = new OutputPort((Cpu.Pin)EMX.Pin.IO4, false); 

            OneWire ow = new OneWire(myPin);
            ushort temperature;

            // read every second
            while (true)
            {
                if (ow.TouchReset() >0)
                {
                    ow.WriteByte(0xCC);     // Skip ROM, we only have one device
                    ow.WriteByte(0x44);     // Start temperature conversion

                    while (ow.ReadByte() == 0) ;   // wait while busy

                    ow.TouchReset();
                    ow.WriteByte(0xCC);     // skip ROM
                    ow.WriteByte(0xBE);     // Read Scratchpad

                    temperature = (byte)ow.ReadByte();                 // LSB 
                    temperature |= (ushort)(ow.ReadByte() << 8); // MSB

                    Debug.Print("Temperature: " + temperature / 16);
                    Thread.Sleep(1000);
                }
                else
                {
                    Debug.Print("Device is not detected.");
                }

                Thread.Sleep(1000);
            }
        }
    }
}

GHIElectronics.NETMF.Hardware;
GHIElectronics.NETMF.FEZ;
These are removed on 4.2

If you are using EMX, G120, they will be replaced by :
GHI.Premium.Hardware;
otherwise that is
GHI.OSHW.Hardware

Beside, the reference Microsoft.SPOT.Hardware.OneWire need to be added.

thanks all for the responses very impressed with the speed, got fed up and went to watch some Tv and i come back and i’ve got 6 reply s!
As ever the answer is obvious when you know it, its a separate DLL for OneWire, feel stupid now, though MSDN still doesn’t list it.

It would be great for newbies like me if the out of date tutorials were marked as such even if not updated or even had the netmf version number on them some where.

Thanks again
Tim

The wiki has been updated, you can take a look on that now. :))

Thanks Brett,
That link also will tell you some problems on EMX with one wire if this device is what you are using.