GPIO

From Pico-8 Wiki
Jump to navigation Jump to search

The PICO-8 builds for Raspberry Pi and PocketChip include support for reading and writing to the GPIO pins on those devices (added in v0.1.9). You can also use the GPIO interface from read/write to JavaScript in web exports of PICO-8 carts (added in v0.1.7).

API

To access the GPIO pins, peek() or poke() to bytes

0x5f80..0x5fff / 24448..24575

in memory. PICO-8 will automatically set a pin to read mode when you peek the memory address or write mode when you poke to the address.

In the web exports, you may use arbitrary bytes in these memory locations to be read from and written to by JavaScript code. To access it, you have to declare a new array, as following:

var pico8_gpio = new Array(128);

You can then write to the bytes like so :

pico8_gpio[0] = 10;

This allows JavaScript to communicate with PICO-8.

In the hardware implementations, the GPIO pins act digitally, with 0 representing 0 and 255 representing 1. Also, hardware implementations may not support all 128 pins. Raspberry Pi, for instance, reportedly only supports the first 8 pins.

Raspberry Pi Setup

Raspberry Pi B+

On a Raspberry Pi B+ model, no additional setup was necessary (using v0.1.10). Run the pico8 binary via

> sudo ./pico8

to enable access to the GPIO pins. If you do not use sudo to run PICO-8, the program will crash with a WiringPi error when your cart tries to access the GPIO memory space.

Raspberry Pi 2 and newer models

On newer Raspberry Pi models, the version of WiringPi included in the statically-linked pico8 binary.* Instead, you will have to build and install SDL 2.0.5 from source as well as a more recent version of WiringPi. Then, use the pico8_dyn binary to run PICO-8.

* Requesting assistance: Is it included? Is it not included? What is the issue here? Would appreciate someone with a Raspi 2 or newer clarifying what this means in less broken English. Feel free to delete this when done.

Older models

On older models of the Raspberry Pi than the B+ model, GPIO may not work at all with PICO-8.

PocketChip Setup

TODO: document experience using PocketChip with PICO-8. Example: I think we had to install a newer (unofficial?) version of PICO-8 using the Debian package manager.