### wiringPi

WiringPi is a GPIO access library written in C for the BCM2835 used in the Raspberry Pi.
Information: http://wiringpi.com
Installing wiringPi
Information: http://wiringpi.com/download-and-install/
• sudo apt-get update
• sudo apt-get upgrade
• sudo apt-get install git-core
• git clone git://git.drogon.net/wiringPi
• cd wiringPi
• git pull origin
• cd wiringPi
• ./build
• gpio -v
• gpio readall
Update wiringPi
• cd ~/wiringPi
• git pull
• ./build
Testing GPIO Pin
Example turning a LED on / off from a terminal:
The LED is connected to physical pin 12 = GPIO. 1 = wPi 1 = BCM 18 (pin numbering, see Raspberry Pi > GPIO Pin Table).
To switch the LED set the pin mode to output first:
gpio mode 1 out
Turn the LED on:
gpio write 1 1
Turn the LED off:
gpio write 1 0
B4J Setup & Read/Write Data
Reference: http://pi4j.com/apidocs/index.html
I2C
(requires the JavaObject library)
'Bus Class Methods applied in Subroutines
`Sub GetBus(BusNumber As Int) As JavaObject
Dim factory As JavaObject
Return factory.InitializeStatic("com.pi4j.io.i2c.I2CFactory").RunMethodJO("getInstance", Array As Object(BusNumber))
End Sub`
`Sub GetDevice(Bus As JavaObject, Address As Int) As JavaObject
Return Bus.RunMethodJO("getDevice", Array As Object(Address))
End Sub`
`Sub CloseBus (Bus As JavaObject)
Bus.RunMethod("close", Null)
End Sub`
'Device Class Methods applied in Subroutines
`Sub Read(Device As JavaObject) As Int
Return Device.RunMethod("read", Null)
End Sub`
`Sub Read2 (Device As JavaObject, Buffer() As Byte, Offset As Int, Size As Int) As Int
Return Device.RunMethod("read", Array As Object(Buffer, Offset, Size))
End Sub`
`Sub Write(Device As JavaObject, b As Byte)
Device.RunMethod("write", Array As Object(b))
End Sub`
`Sub Write2(Device As JavaObject, Buffer() As Byte, Offset As Int, Size As Int)
Device.RunMethod("write", Array As Object(Buffer, Offset, Size))
End Sub`
Example:
Dim bus As JavaObject = GetBus(0)
Dim device As JavaObject = GetDevice(bus, 0)
Write(device, 120)
SPI
`Sub WiringPiSPISetup(Channel As Int, Speed As Int) As Int
Dim jo As JavaObject
Return jo.InitializeStatic("com.pi4j.wiringpi.Spi").RunMethod("wiringPiSPISetup", Array As Object(Channel, Speed))
End Sub`
`Sub WiringPiSPIDataRW(Channel As Int, Data() As Byte, Len As Int) As Int
Dim jo As JavaObject
Return jo.InitializeStatic("com.pi4j.wiringpi.Spi").RunMethod("wiringPiSPIDataRW", Array As Object(Channel, Data, Len))
End Sub`
LCD Library (HD44780U)
The wiringPi LCD devLib allows driving most of the popular 1, 2 and 4-line LCD displays based on the Hitachi HD44780U or
compatible controllers.
Information: http://wiringpi.com/dev-lib/lcd-library/
Reference
com.pi4j.wiringpi
Class Lcd
java.lang.Object
com.pi4j.wiringpi.Lcd
Example API call in B4J
Dim lcd As JavaObject
lcd.InitializeStatic("com.pi4j.wiringpi.Lcd")
Dim handle as Int = lcd.RunMethod("lcdInit", Array())
lcd.RunMethod("lcdPuts", Array(handle, "text"))
C Compiler Line Parameter
To compile programs with wiringPi, add:
-lwiringPi
to the compile line(s).
To use the Gertboard, MaxDetect, etc. code (the devLib), add:
-lwiringPiDev
to the compile line(s).

Changed: 2018-03-26 15:07, Category: Raspberry Pi, File: T6C234M1718.htm, ID: 1718