Showing changes from revision #2 to #3:
Added | Removed | Changed
N.B. Please take care if connecting your own circuits to the Raspberry Pi, not exceeding voltage or current limits, avoiding short circuits etc.GPIO pins, not exceeding voltage limits, and avoiding short circuits etc.
Let’s make a short BASIC program to demonstrate using GPIO pins on a Raspberry Pi. We’re going to set use pin 24 as an output, set high (so anGPIO 24 as an output, set high (so an LED connected through a resistor would light up), and set pin 25 as an input, reading its current value.GPIO 25 as an input, reading its current value.
The first line makes any errors reported nicely.
ON ERROR ON ERROR OFF : PRINT REPORT$;" at line ";ERL : END
Pins The on the Raspberry Pi can be used for things other thanGPIO , so connections we on need the to Raspberry tell Pi it can first be that used we’re for going things to other do thanGPIO , on so pins we 24 need and to 25. tell it first that we’re going to doGPIO on GPIO 24 and GPIO 25.
SYS "GPIO_WriteMode", 24, 0 : REM 0 means GPIO, other values select things like I2C or UART
SYS "GPIO_WriteMode", 25, 0
We also need to tell it which is an input, and which is an output.
SYS "GPIO_WriteOE", 24, 0 : REM 0 means output
SYS "GPIO_WriteOE", 25, 1 : REM 1 means input
Now we’re all ready to go.
First we wanted to set the output pin 24 high.GPIO 24 high.
SYS "GPIO_WriteData", 24, 1 : REM 1 means high, 0 means low
And we also wanted to read the state of input pin 25.GPIO 25.
SYS "GPIO_ReadData", 25 TO state% PRINT "Pin "GPIO 25 is "; IF state% = 1 THEN PRINT "high" IF state% = 0 THEN PRINT "low"