Program example GPIO Pi 5

Post

Posted
Rating:
#1 (In Topic #1438)
Trainee
Hello all!
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?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
I don't have a Pi 5, so I can't offer any code, but have a look at the command line tools you can use here. You should be able to Shell the necessary command in Gambas to change or read the pin(s) settings.
Online now: Yes Back to the top

Post

Posted
Rating:
#3
Trainee
Thanks Cogier
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
  
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Glad it worked. Tip use the gb button to add code to your post, it looks so much better

<IMG src="https://www.cogier.com/gambas/gb.png"> </IMG>

Code (gambas)

  1. Public Sub Form_Open()
  2. Dim Pininit As String
  3.   For f = 4 To 27
  4.       Pininit = "pinctrl set " & Str(f) & " ip pd"
  5.       Shell Pininit
  6.   Next
  7.  
  8. Dim shellResult As String
  9. Dim placeHolder As Integer
  10. Dim pinResult As String
  11. Dim returnIOvalue As Boolean
  12. Dim shellString As String
  13.  
  14.   shellString = "pinctrl get " & Str(PinNo)
  15.   Shell shellString To shellResult
  16.  
  17.   placeholder = InStr(shellResult, "|")
  18.   pinResult = Mid$(shellResult, placeholder + 2, 2)
  19.   If pinResult = "hi" Then
  20.     returnIOvalue = True
  21.   Else
  22.     returnIOvalue = False
  23.   Endif  
  24.  
  25.   Return returnIOvalue
  26.  
  27. Public Sub Timer1_Timer()
  28. Dim Redin As Boolean
  29. Dim GreenIn As Boolean
  30. Dim RedGreen As New Boolean[13, 3]
  31.  
  32.  '---- M140 ----
  33.  Redin = GetIO(4)
  34.  GreenIn = GetIO(5)
  35.  RedGreen[1, 1] = Redin
  36.  RedGreen[1, 2] = GreenIn
  37.  Label1.Background = Color.Gray
  38.  If RedGreen[1, 1] = True Then
  39.     Label1.Background = Color.Red
  40.  Else
  41.     If RedGreen[1, 2] = True Then
  42.       Label1.Background = Color.Green
  43.     Endif
  44.  
  45.  '---- S700 ----
  46.  Redin = GetIO(6)
  47.  GreenIn = GetIO(7)
  48.  RedGreen[2, 1] = Redin
  49.  RedGreen[2, 2] = GreenIn
  50.  Label2.Background = Color.Gray
  51.  If RedGreen[2, 1] = True Then
  52.     Label2.Background = Color.Red
  53.  Else
  54.     If RedGreen[2, 2] = True Then
  55.       Label2.Background = Color.Green
  56.     Endif
  57.  
Online now: Yes Back to the top
1 guest and 0 members have just viewed this.