1-Wire Energy Management Projects

Home Telemetry and Control Systems to Monitor and Reduce Energy Costs

  Bench Test Software

All this wonderful automation is impossible without software so one of my first priorities was to get a .NET program working that supported the DS18S20 temperature chips. (Actually some of the first programs were written in VB6)

I created this "test" program years ago (Jun 2009) and have continually improved it. I used it as my bench-test for everything I'm doing!

I'm currently working on an MSI (setup) file you can download and run test with the USB Micro u4x1 controllers.

I then took most of the "functions" I created to work with the different  device types to write the Windows Services that monitors temperature and runs my sprinkler system and attic fans.

This software is based on the USB Micro controller u4x1.

Currently the program supports the DS18S20, DS2406, DS2408 and DS2450 chips. Working on support for the DS2438, DS1822 and DS18B20.

Some example code below is part of the DS2406 Module and turns on/off the DS2406 chip (switch).

Public Function SwitchDS2406PIOPin(ByVal DataPin As Integer, ByVal ROMCode As String, ByVal OnOFF As Integer) As String
'** This function Turns On or Off the single PIO Pin DS2406
'** OnOff, 0 = Off and 1 = On

Dim Job As Integer
Dim PinHex As String
Dim NewPinBinary As String

'** Set returned data space to zeros
dataarray(0) = 0
dataarray(1) = 0
dataarray(2) = 0
dataarray(3) = 0
dataarray(4) = 0
dataarray(5) = 0
dataarray(6) = 0
dataarray(7) = 0

'** reset all devices on Pin X
USBm_Reset1Wire(0, CByte(DataPin))

' Write "Match ROM"
USBm_Write1Wire(0, &H55)
' Send the ROM Code a Byte at a time
' LSB first (Least Significant Byte) Left to Right
For Job = 16 To 2 Step -2
USBm_Write1Wire(0, CByte("&H" & Left(Right(ROMCode, Job), 2)))
Next

'** "Channel Access"
USBm_Write1Wire(0, &HF5)

'** Turn on PIN Pin
If OnOFF = 0 Then
NewPinBinary = "00000100"
Else
NewPinBinary = "00100100"
End If

PinHex = BinaryToHex(Microsoft.VisualBasic.Left(NewPinBinary, 4))
PinHex = PinHex & BinaryToHex(Microsoft.VisualBasic.Right(NewPinBinary, 4))
'MsgBox("Sending: " & PinHex, MsgBoxStyle.Information)
'** turn all pins (bits) on (zeros)
USBm_Write1Wire(0, "&H" & PinHex)

'** send FF only
USBm_Write1Wire(0, "&HFF")

USBm_Read1Wire(0, dataarray(0))
'MsgBox("Returned 0: " & TwoHexCharacters(dataarray(1)), MsgBoxStyle.Critical)

'** turn all pins (bits) on (zeros)
USBm_Write1Wire(0, "&H" & TwoHexCharacters(dataarray(1)))

'** send FF only
USBm_Write1Wire(0, "&HFF")

'** reset all devices on Pin X
USBm_Reset1Wire(0, CByte(DataPin))

End Function

A couple of notes about this code example. About halfway down, under the section of code that starts "Write Match ROM" I'm showing you how to send the actual ROM Code of the device to be turned off and on. This is important since you can have dozens of the DS2406 chips on the same bus and you only want to switch one of them.

Plus there is another module I wrote called Logic Functions but it's not shown here.

Finally, all the USBm_.... commands are supplied by USB Micro and they have an entire section of the web site dedicated to using the u401 and u421 controller in different languages.