B4R Question How To Use I/O PIn PCF8574

Hi There.. I'm new AT B4R.. Now i'm trying to work with i2c project with PCF 8574.. I already success with scanning the ID of PCF.. But i can't figure it out how to using a pin PCF 8574 AS I/O. Please Help Thx.
 
hello there.. i already read your source code and i want to ask about your source code using PCF 8574.. i'm sorry if my question is wrong (i'm very new in here XD).. can you explain to me why is the master.write to 0x71 but master.request from 0x38.. from your description what i get i, 0x38 is the PCF address. So what is 0x71 ? BTW thx for your repply..
 
If you are lost, I presume that you can use my 8575 code on an 8574 and just change the address and only read the first 8 bits, it's a lot easier to understand and follow. I don't own any 8574's but I would presume that reading and writing to them is basically the same the 8575, but I could be incorrect.
hi there.. i want to ask a question.. how can i send the data in bit not in bytes using WireMaster.Writeto .. Is that Posible.. or there is other way?
 

pucki

Active Member
Licensed User
Hello

i make it so :) And i use a Code from the Forum ;) https://www.b4x.com/android/forum/t...pcf8575-16-bit-io-port-expander-module.80354/

I have changed the two sub's in the code so they work with a PCF8574. The address of my PCF8574 is 0x24. All address pins at Ground.

i dont have read form the PCF8574 i only use him to write to change same LED's for a Modell.

For you info ';)

B4X:
Sub Process_Globals
Public ic As WireMaster
End sub

Private Sub AppStart
ic.Initialize
End sub

Writing is done like that.

Ic_Write (2, False) 'turns pin 2 of the PCF8574 OFF

Ic_Write (2, True) 'This turns ON pin 2 of the PCF8574


Translation of my text by google. My English is very bad.



B4X:
Private Sub ic_Read(pin As UInt)  As Boolean
    Dim pinstatus As Int
    ic.WriteTo(0x24, Array As Byte(0x00))
    Dim result() As Byte = ic.RequestFrom(0x24, 1)
    If result.Length = 0 Then
        Return False
    Else
        pinstatus= Bit.Get(result(0),pin)
        Log(pinstatus)
        If pinstatus=0 Then
            Return False
        Else
            Return True
        End If
            
    End If
End Sub

Private Sub ic_Write(pin As UInt,pinstate As Boolean)

    'ic.WriteTo(0x24, Array As Byte(0x00))
    Dim result() As Byte = ic.RequestFrom(0x24, 1)
    If pinstate =True Then
        Bit.Clear(result(0),pin)
        ic.WriteTo(0x24, Array As Byte(0x00,result(0)))
    Else
        Bit.Set(result(0),pin)
        ic.WriteTo(0x24, Array As Byte(0x00,result(0)))
    End If

End Sub
Sorry for my bad english but im from German.
 
Top