Program example GPIO Pi 5
Posted
#1
(In Topic #1438)
Trainee
Since the architecture of Raspberry Pi 5 is different than the Pi 4 Pigpio doesnt work anymore. Do anyone have a programming example (in Gambas) for declaring and using the GPIO pins on a Pi 5?
In python you can use GPIOD like this:
Code
import gpiod
import time
LED_PIN = 17
chip = gpiod.Chip('gpiochip4')
led_line = chip.get_line(LED_PIN)
led_line.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT)
try:
while True:
led_line.set_value(1)
time.sleep(1)
led_line.set_value(0)
time.sleep(1)
finally:
led_line.release()
Can you use gpiod in a similar way and how do you declare it?
Posted
Guru

Posted
Trainee
Pinctrl worked. If someone is interested in a program example I attach one below.
Code
Public Sub Form_Open()
Dim f As Integer
Dim Pininit As String
For f = 4 To 27
Pininit = "pinctrl set " & Str(f) & " ip pd"
Shell Pininit
Next
End
Function GetIO(PinNo As Integer) As Boolean
Dim shellResult As String
Dim placeHolder As Integer
Dim pinResult As String
Dim returnIOvalue As Boolean
Dim shellString As String
shellString = "pinctrl get " & Str(PinNo)
Shell shellString To shellResult
placeholder = InStr(shellResult, "|")
pinResult = Mid$(shellResult, placeholder + 2, 2)
If pinResult = "hi" Then
returnIOvalue = True
Else
returnIOvalue = False
Endif
Return returnIOvalue
End
Public Sub Timer1_Timer()
Dim Redin As Boolean
Dim GreenIn As Boolean
Dim f As Integer
Dim RedGreen As New Boolean[13, 3]
'---- M140 ----
Redin = GetIO(4)
GreenIn = GetIO(5)
RedGreen[1, 1] = Redin
RedGreen[1, 2] = GreenIn
Label1.Background = Color.Gray
If RedGreen[1, 1] = True Then
Label1.Background = Color.Red
Else
If RedGreen[1, 2] = True Then
Label1.Background = Color.Green
Endif
Endif
'---- S700 ----
Redin = GetIO(6)
GreenIn = GetIO(7)
RedGreen[2, 1] = Redin
RedGreen[2, 2] = GreenIn
Label2.Background = Color.Gray
If RedGreen[2, 1] = True Then
Label2.Background = Color.Red
Else
If RedGreen[2, 2] = True Then
Label2.Background = Color.Green
Endif
Endif
Posted
Guru

<IMG src="https://www.cogier.com/gambas/gb.png">
</IMG>Code (gambas)
- Shell Pininit
- returnIOvalue = True
- returnIOvalue = False
- Return returnIOvalue
- '---- M140 ----
- Redin = GetIO(4)
- GreenIn = GetIO(5)
- RedGreen[1, 1] = Redin
- RedGreen[1, 2] = GreenIn
- Label1.Background = Color.Gray
- Label1.Background = Color.Red
- Label1.Background = Color.Green
- '---- S700 ----
- Redin = GetIO(6)
- GreenIn = GetIO(7)
- RedGreen[2, 1] = Redin
- RedGreen[2, 2] = GreenIn
- Label2.Background = Color.Gray
- Label2.Background = Color.Red
- Label2.Background = Color.Green
1 guest and 0 members have just viewed this.



