Read ds2401 with 1-wire protocol

Hi Sir,
I 'm new in this forum.

I am trying to read ds2401 with 1-wire protocol.
Are there any examples where to take the lead?

Thank you

If you are trying to read the temperature I am using the TMP36 here:

This is the class library I wrote is here.

Imports System
Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
'Need reference to SecretLabs.NETMF.Hardware.AnalogInput.dll
Imports SecretLabs.NETMF.Hardware.AnalogInput
Imports SecretLabs.NETMF.Hardware.Netduino
Imports Microsoft.VisualBasic.Strings


‘’’ Class to read the Tmp36 temperature sensor
‘’’ Avaliable from
‘’’ Set the TemperatureAdjustment if needed
‘’’ Open PortAnalogPort
‘’’ GetTemperature will return a string in Fahrenheit and the degree char

Public Class Tmp36
Private Shared Port As SecretLabs.NETMF.Hardware.AnalogInput
'Changed 12/15/15
'Public Shared TemperatureAdjustment As Integer = 0
Public Shared TemperatureAdjustment As Integer = -2
Public Shared CurrentTemperature As String = String.Empty

Public Shared NewThread As Thread = New Thread(AddressOf PollTemperature)

Public Shared Sub PollTemperature()
    While True

        '5 min.
    End While
End Sub

Public Shared Sub OpenAnalogPort(Optional AnalogInputPin As Integer = 0)


        Select Case AnalogInputPin
            Case 0
                Port = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0)
            Case 1
                Port = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A1)

            Case 2
                Port = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A2)

            Case 3
                Port = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A3)

            Case 4
                Port = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A4)

            Case 5
                Port = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A5)
            Case Else
                Port = New SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A0)
        End Select

    Catch ex As Exception

        Debug.Print("Error in OpenAnalogPort " & AnalogInputPin.ToString & ": " & ex.ToString)
    End Try

End Sub

Public Shared Sub GetTemperature()


        Dim CurrentValue As Double = 0
        Dim CurrentVoltage As Single = 0
        Dim Temperature As Single = 0
        Dim Fahrenheit As Integer = 0
        Dim Degree As String = ChrW(176)

        For i = 1 To 20
            CurrentValue += Port.Read
        Next i

        CurrentValue = CurrentValue / 20

        CurrentVoltage = CSng(CurrentValue * 3.3)

        CurrentVoltage = CurrentVoltage / 1024

        Temperature = CSng(CurrentVoltage - 0.5) * 100

        Fahrenheit = CInt((Temperature * 1.8) + 32.0) + TemperatureAdjustment

        CurrentTemperature = Fahrenheit.ToString

    Catch ex As Exception
        Debug.Print("Error in GetTemperature: " & ex.ToString)

    End Try

End Sub

End Class

To use just start the thread:

Now the temperature can be read at any time using this.

I hope this helps

1 Like

Hi David,
Thanks for replay, but TMP36 is analog sensor.
DS2401 is digital device.



This example should help:

Someone wrote a driver for the DS18B20 a while ago. Discussion is here:

Original code is here:

Could this be reused?


1 Like

Strange , I read fine ds18b20 with onwire, but no work with ds2401.
There is a sample in comunity?