B4J Question RASBERRY PI4

roberto64

Active Member
Licensed User
Longtime User
Hi, or a problem with the PCF8574 (LCD) I'm using wiringPi lib, I run the program from no mistake but it does not write anything on the LCD, where it is wrong, this and the code.
rasberri:
ocess_Globals
    Public  LCD_ROWS As Int  = 2
    Public  LCD_COLUMNS  As Int= 16
    Public LCD_BITS As Int = 4
    
    Private BUS_1 As Int = 1
    
    Private RS  As Int = 0
    Private RW  As Int =  1
    Private EN  As Int =  2
    Private LED As Int =  3
    Private D4  As Int =  4
    Private D5  As Int =  5
    Private D6  As Int =  6
    Private D7  As Int =  7
End Sub

Public Sub IniziaProva
    
    Dim Gpio As JavaObject = Me
    Gpio.InitializeStatic("com.pi4j.wiringpi.Gpio")
    Private fd1 As Int = Gpio.RunMethod("wiringPiSetup", Null)
    Log(fd1)
    
    If CInt(fd1) <0 Then
        Log(" ==>> GPIO SETUP FAILED")
    Else
    Log("Fatto")
End If
    
    Dim bus As JavaObject = ADCDEVICE.wiringPiI2CSetup(0x27)
        
    For i = 0 To 7
        
    Gpio.RunMethod("pinMode", Array(i,ADCDEVICE.OUTPUT))
        
    Next

    Gpio.RunMethodJO("digitalWrite", Array As Object(LED,ADCDEVICE.HIGH))
    Gpio.RunMethodJO("digitalWrite", Array As Object(RW,ADCDEVICE.LOW))
    
    Private lcd As JavaObject = Me
    lcd.InitializeStatic("com.pi4j.wiringpi.Lcd")
    Private handle As Int = lcd.RunMethod("lcdInit", Array(2,16,4,RS,EN,D4,D5,D6,D7,0,0,0,0))
    If handle <0 Then
        Log("Fallita")
    End If
    
    lcd.RunMethodJO("lcdClear",Array As Object(handle))
    Sleep(1000)
'   
    Do While True
        lcd.RunMethod("lcdPosition",Array As Object(handle,0,0))
        
        lcd.RunMethod("lcdPuts",Array As Object(handle,"The Pi4J"))
        lcd.RunMethod("lcdPosition",Array As Object(handle,0,1))
        lcd.RunMethod("lcdPuts",Array As Object(handle,"The Pi4J"))
        Sleep(1000)
    Loop
End Sub

Sub  SetBit(b As Byte, index As Int, on As Boolean) As Byte
   If on Then
      Return Bit.Or(b, Bit.ShiftLeft(1, index))
   Else
      Return Bit.And(b, Bit.Not(Bit.ShiftLeft(1, index)))
   End If
End Sub   

Sub CInt(o As Object) As Int
    Return Floor(o)
End Sub
 
Top