New pigpio - GPIO wrapper for Raspberry Pi

Is it not in there?

There is a terminate function that can be called in the examples with a Window->Close event handler with the code:

As Derk mentioned, if this is missed then the Raspberry Pi will not allow other programs to use the gpio pins until the next reboot.

Iā€™ll try and have a book update for January for the examples with this code.

2 Likes

Or when not released by failing to call terminate you can

sudo systemctl restart pigpiod
1 Like

Is there any sample code that shows how to instantiate pigpiod? I already have wiringpi running, but obviously it wonā€™t work on a RPi4. It has only a little bit of code to instantiate but I have not been able to find that for pigpiod - even in the book. Also is there a conversion list/instruction to go from wiringpi to pigpiod?

Thanks,
Tim

This is the current code:

Run event:
#If TargetLinux And TargetARM Then
GPIO.SetupGPIO
// k_GPIO_ShutDown_Switch
// k_GPIO_CPU_On
// k_GPIO_Engine_On
// k_GPIO_FirePanelInput
// k_GPIO_FirePanel_LED
// k_GPIO_GUI_On
// k_GPIO_PMS_On
// k_GPIO_Relay1
// k_GPIO_Relay2
// k_GPIO_ShutDown_LED

GPIO.PinMode( k_GPIO_Input2, GPIO.Input)
GPIO.PinMode( k_GPIO_LCD_EnSw, GPIO.Input)
GPIO.PullUpDnControl(k_GPIO_LCD_EnSw, GPIO.HIGH )
GPIO.PullUpDnControl(k_GPIO_Input2, GPIO.HIGH )
GPIO.PinMode( k_GPIO_LCD_En_LED, GPIO.OUTPUT)

GPIO.PinMode( k_GPIO_ShutDown_Switch, GPIO.Input)
GPIO.PinMode( k_GPIO_FirePanelInput, GPIO.Input)
GPIO.PullUpDnControl( k_GPIO_ShutDown_Switch, GPIO.HIGH ) // k_ShutDown_Switch, GPIO.HIGH ) //turn on the pull up
GPIO.PullUpDnControl( k_GPIO_FirePanelInput, GPIO.HIGH ) //k_FirePanelInput, GPIO.HIGH) //turn on the pull up

GPIO.PinMode( k_GPIO_CPU_On, GPIO.OUTPUT)
GPIO.PinMode( k_GPIO_Engine_On, GPIO.OUTPUT)
GPIO.PinMode( k_GPIO_FirePanel_LED, GPIO.OUTPUT)
// GPIO.PinMode( k_GPIO_GUI_On, GPIO.OUTPUT)
// GPIO.PinMode( k_GPIO_PMS_On, GPIO.OUTPUT)
GPIO.PinMode( k_GPIO_Relay1, GPIO.OUTPUT)
GPIO.PinMode( k_GPIO_Relay2, GPIO.OUTPUT)
GPIO.PinMode( k_GPIO_ShutDown_LED, GPIO.OUTPUT)

GPIO.DigitalWrite( k_GPIO_CPU_On, GPIO.OFF )
GPIO.DigitalWrite( k_GPIO_Engine_On, GPIO.OFF )
GPIO.DigitalWrite( k_GPIO_FirePanel_LED, GPIO.OFF )
// GPIO.DigitalWrite( k_GPIO_GUI_On, GPIO.OFF )
// GPIO.DigitalWrite( k_GPIO_PMS_On, GPIO.OFF )
GPIO.DigitalWrite( k_GPIO_Relay1, GPIO.OFF )
GPIO.DigitalWrite( k_GPIO_Relay2, GPIO.OFF )
GPIO.DigitalWrite( k_GPIO_ShutDown_LED, GPIO.OFF )

GPIO.DigitalWrite( k_GPIO_Input2, GPIO.OFF )
GPIO.DigitalWrite( k_GPIO_LCD_EnSw, GPIO.OFF )
GPIO.DigitalWrite( k_GPIO_LCD_En_LED, GPIO.OFF )

ControllerShutDown = New clsControllerShutDown
#EndIf

SetupGPIO Method:
#If TargetARM And TargetLinux Then
Soft Declare Sub wiringPiSetup Lib ā€œlibwiringPi.soā€
wiringPiSetup
// #Else
// #Pragma Error ā€œwiringPi library only works on Raspberry Piā€
#EndIf

Hello @Tim_Seyfarth,

The steps I usually use to instantiate pigiod are:

  1. create a global property

Then put the following in an Open command:

An Example to turn on a pin looks like this:

Does this help?

Shameless plug: Many examples have been created in the Xojo Raspberry Pi 4B book.

Note: After thinking more about your request, it is a great idea! Iā€™ll create a chart and put it on my website at: Program Raspberry Pi 4B Electronics with Xojo - Buster Edition. It will likely be missing some commands, and it will be a good start.

Thanks Eugene
I forgot to send this before I shut down the computerā€¦

I did find something to help, but a note that page 88 still references GPIO

I bought your book earlier toniteā€¦
Thank you,
Tim

That would be a good thing. You can see some of the commands/pins I use. Having not delved into it yet, I am not sure how hard it will be to translate but my guess is it will be fairly straightforward.

Thanks again,
Tim

1 Like

Thank you Tim. I have tried to remove most of the references to WiringPi, and there are a few that still slip through.

My website has been updated with a starting chart to convert WiringPi commands to pigpio at: Program Raspberry Pi 4B Electronics with Xojo - Buster Edition

1 Like

Thank you Eugene!
Tim

1 Like

HI,
Iā€™m fighting 4 days with waves. Can someone help me?

dim m as new MemoryBlock(30)

m.UInt32Value(0)=16 //GPIO 4
m.UInt32Value(1)=0
m.UInt32Value(2)=1000

m.UInt32Value(3)=0
m.UInt32Value(4)=16 //GPIO 4
m.UInt32Value(5)=1000

var p as ptr
p=m

call pi.wave_clear()
call pi.wave_add_new()
call pi.wave_add_generic(2,m)
dim i as integer = pi.wave_create()

if i >= 0 then
//call pi.wave_send_once(i)
call pi.wave_send_repeat(i)
//call pi.wave_send_using_mode(i,0)
else
msgbox(ā€œFailā€)
end if

Now it works

dim m as new MemoryBlock(50)
m.UInt32value(0)=16 //On GPIO 4
m.UInt32value(4)=0 //Off
m.UInt32value(8)= 10 //Delay us 50Khz
m.UInt32value(12)=0 //On
m.UInt32value(16)=16 //Off GPIO 4
m.UInt32value(20)=10 //Delay us 50Khz

if pi.wave_clear() >0 then
msgbox(ā€œFail 1ā€)
end if

if pi.wave_add_new()>0 then
msgbox(ā€œFail 2ā€)
end if

dim result as integer = pi.wave_add_generic(2,m)

dim i as integer = pi.wave_create()

if i >= 0 then
//call pi.wave_send_once(i)
call pi.wave_send_repeat(i)
//call pi.wave_send_using_mode(i,0)
else
msgbox(ā€œFailā€)
end if

Hello @Alberto_Canovas,

Glad to see that you have it working.

All the best!