Raspberry BASIC
Raspberry BASIC => Interpreters => BBC BASIC => Topic started by: Richard Russell 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):
(http://www.rtr.myzen.co.uk/rpigpio.gif)
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
-
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?
-
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-*.
-
/dev/i2c-* is what I used for the ScriptBasic SHAT extension module.
Thanks for the info how this stuff works!