B4J Question Raspberry Pi GPIO Write a byte?

techknight

Well-Known Member
Licensed User
Longtime User
So, I was looking at this tutorial:

https://www.b4x.com/android/forum/threads/iot-jpi4j-raspberry-pi-gpio-controller.37493/#content

I have used raspberry pis in alot of projects, but this is the first time I am interacting with the GPIO.

I see there is examples on how to control each pin individually, But is it possible to group a bunch of pins for Byte-wide transfers?

I have a FIFO hooked into the GPIO and I would like to transfer binary files I open into the FIFO which requires me to write 8 bits at a time as a byte, and not sure how to do that with the library.

any ideas? Thanks.
 

techknight

Well-Known Member
Licensed User
Longtime User
Actually, I did it this way:

B4X:
    Dim DataOut0 As GpioPinDigitalOutput = AD0.ChangeToOutput
    Dim DataOut1 As GpioPinDigitalOutput = AD1.ChangeToOutput
    Dim DataOut2 As GpioPinDigitalOutput = AD2.ChangeToOutput
    Dim DataOut3 As GpioPinDigitalOutput = AD3.ChangeToOutput
    Dim DataOut4 As GpioPinDigitalOutput = AD4.ChangeToOutput
    Dim DataOut5 As GpioPinDigitalOutput = AD5.ChangeToOutput
    Dim DataOut6 As GpioPinDigitalOutput = AD6.ChangeToOutput
    Dim DataOut7 As GpioPinDigitalOutput = AD7.ChangeToOutput
  
    DataDirection.State = False 'Switch our bus transceivers to Outputs
  
    'Grab the bits from our byte, and store them into the respective GPIO Pins.
    DataOut0.State = GetBit(Data, 0)
    DataOut1.State = GetBit(Data, 1)
    DataOut2.State = GetBit(Data, 2)
    DataOut3.State = GetBit(Data, 3)
    DataOut4.State = GetBit(Data, 4)
    DataOut5.State = GetBit(Data, 5)
    DataOut6.State = GetBit(Data, 6)
    DataOut7.State = GetBit(Data, 7)

    'Latch in the new value.
    VMEWrite.State = True    'Clock in the new data to the latch
    VMEWrite.State = False    'De-assert the Latch Write.
    DataDirection.State = True 'Switch our transceivers back to inputs.
   
    'When we are finished writing to the latch, We switch back to inputs.
    AD0 = DataOut0.ChangeToInput
    AD1 = DataOut1.ChangeToInput
    AD2 = DataOut2.ChangeToInput
    AD3 = DataOut3.ChangeToInput
    AD4 = DataOut4.ChangeToInput
    AD5 = DataOut5.ChangeToInput
    AD6 = DataOut6.ChangeToInput
    AD7 = DataOut7.ChangeToInput
   
    InterruptCPU.State = True 'Tell the main CPU to interrupt. Will be cleared by the ACK Event.
    InterruptCPU.State = False

Messy and slow, But it works :)
 
Upvote 0
Top