### GPIO Blinking LED

Blink an LED connected to a Raspberry Pi Experiment .
The Raspberry Pi GPIO controller changes the state (HIGH/LOW) of the LED every 5 seconds.
App Type: B4J Non-UI (Console)
Parts Needed
• 1x Raspberry Pi
• 1x LED 3.3v
• 1x Resitor 220Ohm
• 1x GPIO Extension Board with GPIO cable, Breadboard, several jumper wires
Wiring
LED = Raspberry Pi (Wirecolor)
GND (-) = GND (black)
Anode (+) = Physical Pin #12 (=Name GPIO.1, wiringPi #1, BCM #18)
Description
Connecting the Parts
The RasPi GPIO is connected via the GPIO Extension Board (T-Cobbler) and GPIO cable to a breadboard.
On the Breadboard: place the LED with a 220 ohm resistor in series with the GND (Physical Pin 6) and the GPIO18 Pin (Physical Pin 12, Pi4J GPIO.1).
Developing the B4J Non-UI program
The B4J Non-UI program uses the jPi4J Library (Raspberry Pi GPIO controller) - see category Raspberry Pi Libraries > jPi4J.
The B4J pseudo code:
• Init the gpio controller
• Init the gpio pin to shich the led is connected
• Init the timer and start
• Start the message loop
• Handle switching the LED on / off
Running the Experiment
On the RasPi start the B4J-Bridge by login on as user Pi, open a terminal, go to folder /home/pi/b4j and run sudo java -jar b4-bridge.jar, note the MyIp address.
Open the B4J IDE and load the B4J project file, connect to the B4J-Bridge (Menu Tools > B4J Bridge > Connect > Enter IP address.
Run the application from the B4J IDE by pressing F5.
Download Source Code
Documentation on request.
Additional Libraries
jPi4J
Published External
No
ToDo
• Experiment is completed.
Version
20170301
B4J Non-UI Example Code
`Sub Process_Globals
Private CAPPVERSION As String = "Raspberry Pi Experiment - Flashing an LED v20170301"
'Define the gpio controller which uses the jPi4J library
Private controller As GpioController
'Define the LED pin
Private Pin1 As GpioPinDigitalOutput
'Define the flashing timer and interval
Private FlashingTimer As Timer
Private FlashingInterval As Long = 5000
End Sub`
`Sub AppStart (Args() As String)
Log(CAPPVERSION)
'Init the gpio controller
Try
controller.Initialize
Catch
Log("Controller Initialize Error:" & CRLF & LastException.Message)
Return
End Try
'Init the gpio pin to shich the led is connected
Pin1.Initialize(1, True)
'Init the timer and start
FlashingTimer.Initialize("FlashingTimer", FlashingInterval)
FlashingTimer.Enabled = True
Log("Monitoring Pin1 state")
'Do not forget
StartMessageLoop
End Sub`
'Handle switching the LED
`Sub FlashingTimer_Tick
Pin1.State = Not(Pin1.State)
Log($"LED switched to ${Pin1.state}"$)
End Sub`

Changed: 2018-06-07 09:20, Category: Raspberry Pi Sample Projects, File: T6C238M1737.htm, ID: 1737