# GPIO port for Raspberry Pi

DevFeed: [GPIO port for Raspberry Pi](<https://devfeed.tech/articles/gpio-port-for-raspberry-pi-22369.md>)

Original publisher: [Read original article](<https://www.red-lang.org/2019/07/gpio-port-for-raspberry-pi.html>)

Author: Nenad Rakocevic (noreply@blogger.com)

Published: 2019-07-18T16:08:00Z

Content type: release

Language: en

Sources: [Red](<https://devfeed.tech/sources/red.md>)

Topics: [Raspberry Pi](<https://devfeed.tech/topics/raspberry-pi.md>), [Hardware](<https://devfeed.tech/topics/hardware.md>), [API](<https://devfeed.tech/topics/api.md>), [Code](<https://devfeed.tech/topics/code.md>), [Software](<https://devfeed.tech/topics/software.md>), [GTK](<https://devfeed.tech/topics/gtk.md>)

Tags: [3](<https://devfeed.tech/tags/3.md>), [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [dsl](<https://devfeed.tech/tags/dsl.md>), [gpio](<https://devfeed.tech/tags/gpio.md>), [hardware](<https://devfeed.tech/tags/hardware.md>), [led](<https://devfeed.tech/tags/led.md>), [port](<https://devfeed.tech/tags/port.md>), [pwm](<https://devfeed.tech/tags/pwm.md>), [raspberry-pi](<https://devfeed.tech/tags/raspberry-pi.md>), [raspberrypi](<https://devfeed.tech/tags/raspberrypi.md>)

## AI overview

The article announces a GPIO driver for Raspberry Pi boards implemented as Red's gpio:// scheme. It describes board detection, GPIO state access, hardware PWM, and a command DSL, and demonstrates the functionality with a joypad project running on a Raspberry Pi 3.

## Source excerpt

As part of the R&D work on port! datatype in port-type branch, we have implemented a GPIO driver for Raspberry Pi boards, as a gpio:// scheme (no third-party library needed). This work helped define the low-level API for ports written in purely Red/System or a mix of Red and Red/System. The Raspberry Pi is a very popular board with millions of units sold, so this is a market where Red could be potentially helpful to developers. We could run Red on such boards for years but did not have proper GPIO support, so this is now fixed! The current features supported by the GPIO port are: auto-detecting the Raspberry Pi board type uses /dev/mem or/dev/gpiomem for direct and fast access. reading a GPIO pin state. writing to a GPIO pin state. hardware PWM output support (on capable pins). a simple DSL for sending commands. Planned (but not scheduled) future features include: generating events when a pin state changes. software PWM on all GPIO pins. a higher-level reactive object layer for a API-less interface. various drivers for common peripherals. The source code for the gpio:// scheme can be found there. In the short video below, you can find a little pet project meant for testing some of the features. It implements a simple joypad with 4 directions support, a red LED indicating when the pad is active and a green one for notifying when a level is completed. The game is the Red port contributed by Huang Yongzhao of Rebox!, my old clone of BoxWorld written in Rebol. In the video below, it is running on a Raspberry Pi 3 using our work-in-progress red/GTK backend for Red (contributed by Rcqls), locally merged with the red/port-type development branch (EDIT: that branch has been merged into master now). You can find the breadboard layout below made using Fritzing. Sorry for the messy wiring, it is my first try with such kind of tool. If you have the skills to improve it, here is the sketch file. The buttons rely on the internal pull-down resistors. Note that in the video, the bo