GPIO: Difference between revisions

From Pico-8 Wiki
Jump to navigation Jump to search
imported>Felice Enellen
(→‎API: that was what I get for trying to use the automatic undo button instead of doing it by hand like my instincts tell me to do. what a mess. I'm an idiot. anyway this one is right.)
(→‎Raspberry Pi 2 and newer models: fixes + requesting clarification)
Line 1: Line 1:
The PICO-8 builds for [[Raspberry Pi]] and [[PocketChip|PocketChip include]] support for reading and writing to the [https://en.wikipedia.org/wiki/General-purpose_input/output 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).
The PICO-8 builds for [[Raspberry Pi]] and [[PocketChip]] include support for reading and writing to the [https://en.wikipedia.org/wiki/General-purpose_input/output 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==
==API==
To access the GPIO pins, [[peek]] or [[poke]] to bytes
To access the GPIO pins, [[peek]] or [[poke]] to bytes
Line 23: Line 23:
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.
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===
===Raspberry Pi 2 and newer models===
One 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.
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.
 
''*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===
===Older models===
On older models of the Raspberry Pi than the B+ model, GPIO may not work at all with PICO-8.
On older models of the Raspberry Pi than the B+ model, GPIO may not work at all with PICO-8.
==PocketChip Setup==
==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.
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.

Revision as of 16:37, 1 April 2019

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

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.

*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.