Log In  

Hi, I'm ghettobastler ! I make stuff using electronics and programming, and recently I became interested in PICO-8 because of its ability to control a Raspberry Pi's GPIO from within a game.
I read that this was done by using peek() and poke() on an address in the 0x5f80..0x5fff range, but unfortunately, I was not able to find the exact mapping online (i.e. which particular address corresponds to a given GPIO pin). So I made this tool to help me figure that out.

This is meant to be used on a Raspberry Pi or a similar board that has GPIO pins. It will not work in a browser or on a computer (I mean it will run... but there isn't any point in doing that)

Cart #rpi_gpio_mapper-0 | 2022-08-30 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2

It is pretty bare-bones, but it does the job. To use it, connect an LED and a resistor to one of the GPIO and run the cartridge (see this guide if you don't know how to do that).

This tool works by performing a dichotomic search to find the address that matches a particular GPIO pin:

  • At the start, half of the 0x5f80..0x5fff range is turned ON, and the other half is turned OFF. The program then asks the user if the LED they connected is on.
    • If it is, the process repeats, but only on the first half of the range
    • If it's not, the program uses the other half of the range
      This goes on until only one address remains.

I ran this tool on my Raspberry Pi and found this mapping:

  • GPIO 0 (pin 27): 0x5f9e
  • GPIO 1 (pin 28): 0x5f9f
  • GPIO 2 (pin 3): 0x5f88
  • GPIO 3 (pin 5): 0x5f89
  • GPIO 4 (pin 7): 0x5f87
  • GPIO 5 (pin 29): 0x5f95
  • GPIO 6 (pin 31): 0x5f96
  • GPIO 7 (pin 26): 0x5f8b
  • GPIO 8 (pin 24): 0x5f8a
  • GPIO 9 (pin 21): 0x5f8d
  • GPIO 10 (pin 19): 0x5f8c
  • GPIO 11 (pin 23): 0x5f8e
  • GPIO 12 (pin 32): 0x5f9a
  • GPIO 13 (pin 33): 0x5f97
  • GPIO 14 (pin 8): 0x5f8f
  • GPIO 15 (pin 10): 0x5f90
  • GPIO 16 (pin 36): 0x5f9b
  • GPIO 17 (pin 11): 0x5f80
  • GPIO 18 (pin 12): 0x5f81
  • GPIO 19 (pin 35): 0x5f98
  • GPIO 20 (pin 38): 0x5f9c
  • GPIO 21 (pin 40): 0x5f9d
  • GPIO 22 (pin 15): 0x5f83
  • GPIO 23 (pin 16): 0x5f84
  • GPIO 24 (pin 18): 0x5f85
  • GPIO 25 (pin 22): 0x5f86
  • GPIO 26 (pin 37): 0x5f99
  • GPIO 27 (pin 13): 0x5f82

You can use this mapping as is on your Pi, but I cannot guarantee that it is consistent across all models (I used a Raspberry Pi 3).

I hope this is useful, have a nice day !

P#116585 2022-08-30 17:13

The documentation is here: https://www.lexaloffle.com/dl/docs/pico-8_manual.html#GPIO

Specifically:

> Raspberry Pi: 0x5f80..0x5f9f mapped to wiringPi pins 0..31
> // see http://wiringpi.com/pins/ for mappings on different models.

P#116599 2022-08-30 17:42

Dang, I did not check the manual... 😔
Thank you, that's exactly what I was looking for !

P#116600 2022-08-30 17:56

[Please log in to post a comment]