Writing outputs seperately on IC PCF8574

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

Post Reply
Tubes4sale
Posts: 7
Joined: Thu Jan 28, 2010 7:15 am

Writing outputs seperately on IC PCF8574

Post by Tubes4sale »

Hi,

I am using the SUB -20 to write outputs of several PCF8574 that controls relays. I can write to a single outputs, But I am not able to write another output without changing the other output .
What I a want to do is write the different outputs separately. Can anyone help. I am using VB.net 2010.
Thanks.

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Writing outputs seperately on IC PCF8574

Post by xol »

Hi,
Drop us a piece of your code and we will tell you where the problem is.

Tubes4sale
Posts: 7
Joined: Thu Jan 28, 2010 7:15 am

Re: Writing outputs seperately on IC PCF8574

Post by Tubes4sale »

Code to write to several PCF8574 only writing one output

'START WRITE PINS
Private Sub DoI2CWrite_pin(ByVal Card As String, ByVal data As String, ByVal test As Boolean)
'local variable

Dim Sub20 As New Xdimax.Sub20
Dim StrBytes As String()
Dim Bytes As Byte()
Dim i As Integer
Dim N As Integer
Dim WriteData1 As String = ""
Dim pinnumber As String = ""
Dim StringData As String = ""
Dim address As String = ""
'Read address for card
If Card = 1 Then
address = "38"
pinnumber = "01"
ElseIf Card = 2 Then
address = "39"
pinnumber = "02"
ElseIf Card = 3 Then
address = "3a"
pinnumber = "03"
ElseIf Card = 4 Then
address = "3b"
pinnumber = "04"
ElseIf Card = 5 Then
address = "3c"
pinnumber = "05"
ElseIf Card = 6 Then
address = "3d"
pinnumber = "06"
ElseIf Card = 7 Then
address = "3e"
pinnumber = "07"
ElseIf Card = 8 Then
address = "3f"
pinnumber = "08"
ElseIf Card = 9 Then
address = "20"
pinnumber = "09"
ElseIf Card = 10 Then
address = "21"
pinnumber = "10"
ElseIf Card = 11 Then
address = "22"
ElseIf Card = 12 Then
address = "23"
ElseIf Card = 13 Then
address = "24"
'text from label
End If
If data = "1" Then
WriteData1 = "00"
StringData = Label_NC.Text
ElseIf data = "2" Then
WriteData1 = "01"
StringData = Label_Ground.Text
ElseIf data = "3" Then
WriteData1 = "02"
StringData = Label_Heater.Text
ElseIf data = "4" Then
WriteData1 = "04"
StringData = Label_Screen1.Text
ElseIf data = "5" Then
WriteData1 = "08"
StringData = Label_Screen2.Text
ElseIf data = "6" Then
WriteData1 = "20"
StringData = Label_Anode.Text
ElseIf data = "7" Then
WriteData1 = "10"
StringData = Label_Screen3.Text
ElseIf data = "8" Then
WriteData1 = "40"
StringData = Label_Test_1.Text
ElseIf data = "9" Then
WriteData1 = "80"
StringData = Label_Test_2.Text
End If

Sub20 = New Xdimax.Sub20

If 0 = DeviceList.Items.Count Then
AddInfoLine("ERROR: No device")
Return
End If
If Not Sub20.Open(DeviceList.SelectedItem.Ref) Then
AddInfoLine("ERROR: Cannot open SUB-20 WrtPIN")
Return
End If
'---------------------------------------------------------------------------------

StrBytes = Split(WriteData1, " ")
If StrBytes(0).Length = 0 Then
N = 0
Else
N = StrBytes.Length
End If

Bytes = Array.CreateInstance(GetType(Byte), N)

For i = 0 To N - 1
Bytes(i) = Val("&H" + StrBytes(i))
Next

If Not Sub20.I2C_Write(Val("&H" + address), _
Val("&H" + "1"), Val("&H" + "0"), Bytes) Then
AddInfoLine("failed, err=" + Sub20.GetLastError().ToString())
End If
If test = 0 Then
AddInfoLine("Connect pin: " + pinnumber + " to " + StringData)
End If

Sub20.Close()

End Sub

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Writing outputs seperately on IC PCF8574

Post by xol »

OK,
Now tell us in plain English with register addresses and values, what are you doing, what do you expect to get and what actually happens.

Tubes4sale
Posts: 7
Joined: Thu Jan 28, 2010 7:15 am

Re: Writing outputs seperately on IC PCF8574

Post by Tubes4sale »

Hi,

The address range for the PCF8574 is &H20 to &H27 and for PCF8574A is &H38 to &H3F.
To write a output data is &H01'(bin 1) for ouput 1, &H02(bin 10) for ouput 2, &H04 (bin 100)for ouput3, &H08 (bin1000) for output 4 etc.

My problem is when output1 is 1 and I want to write output 3 on the same PCF8574(A) a don't know how to do this. If you write output 3, output 1 goes low.
If you want 1 and 3 high then the data is &H01 + &H03 = &H04 (bin101).
I expect to write each single output (1 to 8) seperately, without disturbing the other outputs.
Something like write_output (address, number of output, on or off).
Hope this helps.
Regards

Image

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: Writing outputs seperately on IC PCF8574

Post by xol »

OK,
But how is it related to SUB-20? You should talk to PCF8574 manufacturer.
SUB-20 is only a channel between your PC program and PCF.

Post Reply