Raspberry BASIC

Author Topic: Simple GPIO demo  (Read 6324 times)

Richard Russell

  • Moderator
  • *****
  • Posts: 65
    • View Profile
Simple GPIO demo
« on: April 30, 2019, 05:00:57 PM »
This is a very simple demo of the Raspberry Pi's GPIO being controlled by BBC BASIC, using the supplied 'gpiolib' library.  It cycles through six of the outputs, setting each one high in sequence.  The code is listed below, and this is the result (with LEDs fitted to monitor the outputs):



Code: [Select]
      REM Initialise GPIO:
      INSTALL @lib$ + "gpiolib"
      GPIO% = FN_gpio_setup

      REM Pin numbers to activate, in sequence:
      DATA 17, 23, 25, 12, 16, 26

      REM Set to input first:
      RESTORE
      FOR I% = 1 TO 6
        READ pin%
        PROC_gpio_inp(GPIO%, pin%)
      NEXT

      REM Set pins to output:
      RESTORE
      FOR I% = 1 TO 6
        READ pin%
        PROC_gpio_out(GPIO%, pin%)
      NEXT

      REM Cycle LEDs in sequence:
      REPEAT
        RESTORE
        FOR I% = 1 TO 6
          READ pin%
          PROC_gpio_set(GPIO%, 2^pin%)
          WAIT 20
          PROC_gpio_clr(GPIO%, 2^pin%)
        NEXT
      UNTIL FALSE
      END

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 234
    • View Profile
    • ScriptBasic
Re: Simple GPIO demo
« Reply #1 on: April 30, 2019, 08:29:37 PM »
 Very cool Richard. Have you had any luck with the RPi Sense HAT board? Will your GPIO library allow use of the Sense HAT emulator that comes with Raspbian?
ScriptBasic Project Manager/Facilitator

Richard Russell

  • Moderator
  • *****
  • Posts: 65
    • View Profile
Re: Simple GPIO demo
« Reply #2 on: April 30, 2019, 10:19:02 PM »
Have you had any luck with the RPi Sense HAT board? Will your GPIO library allow use of the Sense HAT emulator that comes with Raspbian?

I don't have a Sense HAT here.  My understanding is that it's an I2C device and therefore not really accessible via the GPIO (I know that the I2C clock and data lines appear on GPIO pins, but it would be a bit daft to try to interface with I2C devices that way!).   So to that extent my GPIO library isn't really relevant to the Sense HAT, but BBC BASIC could no doubt access it via the virtual I2C device at /dev/i2c-*.

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 234
    • View Profile
    • ScriptBasic
Re: Simple GPIO demo
« Reply #3 on: April 30, 2019, 10:44:31 PM »
/dev/i2c-* is what I used for the ScriptBasic SHAT extension module.

Thanks for the info how this stuff works!
« Last Edit: May 01, 2019, 01:23:09 AM by John Spikowski »
ScriptBasic Project Manager/Facilitator