The GPIO (General Purpose Input/Output Port) is a special port on the Pi that you can use to connect your own hardware, devices and circuits.

To use GPIO with Xojo you will need to install the wiringPi library. After doing so you can use the WiringPiXojo module to communicate with the GPIO port on the Raspberry Pi. This code in the Run event handler of a Console app flashes an LED:


Const kLEDPin = 4 ' "#4" on the pinout

// Set the pin to accept output

// Blink LED every 1/2 second
While True
  ' Turn the pin on (give it power)
  GPIO.DigitalWrite(kLEDPin, GPIO.ON)

  // Turn the pin off (no power)
  GPIO.DigitalWrite(kLEDPin, GPIO.OFF)

GPIO apps usually have to be started with sudo, so if you built a console app called LEDBlink you would start it like this from terminal:

sudo ./LEDBlink

You can also create a desktop app using GPIO. To start a desktop app as sudo, you have to use the gksudo command from terminal:

gksudo ./LEDBlinkUI

Starting with Raspbian Jessie, you no longer have to use sudo to access GPIO. In order to not require sudo, you have to first set an environment variable before you run the app:


WiringPi GPIO Module

The Xojo GPIO module maps the wiringPi library to a set of methods that you can call in your Raspberry Pi Xojo apps. In order to use the GPIO module, you’ll need to install the wiringPi library on your Raspberry Pi.

The GPIO module is included with the Xojo examples and is available on GitHub:

The official wiringPi docs will not be replicated here, but links are provided for your reference:

GPIO in desktop apps

You can also create desktop apps that can control GPIO using the same techniques as above. The primary difference is how you launch the app so that it has sudo access.

Use gksudo to start a desktop app from the command line with sudo:

gksudo ./WiringPi-UI

Or set the environment variable before starting the app from the command line:


Refer to the desktop example project that uses the circuits created in the Making a LED Light Blink Part I and the Making a LED Light Blink Part II.

Example Projects/Platform-Specific/RaspberryPi