Updated 24 September 2020

Kits and Gadgets Electronics Inc.
Farwaniya, Kuwait 80003
Kuwait

ph: +965 99571844

kits@kits-gadgets.com

  • Electronic Kits
  • Parts on Sale
  • Parts in StockClick to open the Parts in Stock menu
    • Resistor
    • Potentiometer
    • Capacitor
    • Trimmer Capacitor
    • Transistor
    • Crystal
    • Diode
    • LED
    • Diac
    • Thyristor
    • IC Socket
    • IC - Logic
    • IC - Linear
    • IC - Op-Amp
    • IC - VLSI
    • Relay
    • Motor
    • Lamp
    • Transducer
    • Gear
    • Switch
    • Heatsink
    • Parts Store Inventory
  • Brand New Items
  • Used Items
  • Power Supply
  • Raspberry Pi VaultClick to open the Raspberry Pi Vault menu
    • Demonstration Kit
    • Demonstration Kit - R3
    • The P1 Header Guide
    • BBC BASIC Tutorials
    • Activating the GPIO
    • LED Program
    • Motor Program
    • Solenoid Program
    • Stepper Motor
    • 8 Relay Program
    • GPIO as Input
    • Motors and Sensors Connection Diagram
    • Autonomous Program
    • Infrared Sensor
    • Ultrasonic Sensor
    • Camera Controller
    • PWM Program
    • Robotic Arm
    • STRYDER Robot
    • Demo Kit Program
  • Arduino VaultClick to open the Arduino Vault menu
    • Stepper Motor w/ LED
    • DCMotor
  • NodeMCU ProjectsClick to open the NodeMCU Projects menu
    • Running 8 LEDs
    • 8 LEDs and ULN2803
    • 8 LED Active Modes
    • ON-OFF Switch
    • Switch, Relay and LEDs
    • Motor Drive Interface
    • Connecting to Wi-Fi
    • IR Sensor
  • More GPIOsClick to open the More GPIOs menu
    • Accessing the P5 GPIOs
  • Prototypes
  • Computer Parts
  • Picture GalleryClick to open the Picture Gallery menu
    • Other Prototypes
    • Revived HP Laptop
    • Dismantled Helicopter
    • Dismantled Phone
    • ACER Laptop Repair
    • Revived Laptop
    • Inside of Electric Drill
    • Video Cam Automation
    • My Tours and Travels
  • My Original DesignClick to open the My Original Design menu
    • Handycam Automation
    • Autonomous Robot
  • What's New!Click to open the What's New! menu
    • Article-1
    • Article-2
    • Article-3
    • Article-4
    • Article-5
    • Article-6
    • Article-7
    • Article-8
    • Article-9
    • Article-10
    • Article-11
    • Article-12
    • Article-13
    • Article-14
    • Article-15
    • Article-16
    • Article-17
    • Article-18
    • Article-19
    • Article-20
    • Article-21
    • Article-22
    • Article-23
    • Article-24
    • Article-25
    • Article-26
    • Article-27
    • Article-28
    • Article-29
    • Article-30
    • Article-31
  • Forum
  • Video GalleryClick to open the Video Gallery menu
    • IR Proximity Sensor
    • Robot Vacuum Cleaner
    • Robotic Arm - RPi
    • Raspberry Pi Demo Kit
  • About Us
  • Contact Us

Activating the GPIO

GPIO stands for General Purpose Input/Output. It is a type of Input/Output port used in Raspberry Pi Computer, Arduino and Beagle Microcontrollers or similar platforms.

In Raspberry Pi, there are a total of 21 GPIO Ports. Seventeen in P1 Header and four in P5 Terminal. The rest of the pins are DNC or 'do not connect' pins, 5 Volts line, 3.3 Volts line and Ground. Some GPIO ports on RPi function on different ways but can be programmed to work as a normal I/O. 

 

GPIO PORTS               DEFAULT STATE        PIN NUMBER 

1. GPIO-2             -                     H                -       P1-3

2. GPIO-3             -                     H                -       P1-5

3. GPIO-4             -                     L                 -      P1-7

4. GPIO-7             -                     L                 -      P1-26

5. GPIO-8            -                      L                 -      P1-24

6. GPIO-9            -                      L                -       P1-21

7. GPIO-10         -                       L                -       P1-19

8. GPIO-11         -                       L                -      P1-23

9. GPIO-14         -                       L                -      P1-8

10. GPIO-15      -                       L                -      P1-10

11. GPIO-17      -                       L                -      P1-11

12. GPIO-18      -                       L                -      P1-12

13. GPIO-22      -                       L                -      P1-15

14. GPIO-23      -                       L                -      P1-16

15. GPIO-24      -                       L                -      P1-18

16. GPIO-25      -                       L                -      P1-22

17. GPIO-27      -                       L               -      P1-13

18. GPIO-28      -                       L               -      P5-3

19. GPIO-29      -                       L                -      P5-4

20. GPIO-30      -                        L              -       P5-5

21. GPIO-31      -                        L              -       P5-6

 

To activate and utilize these ports under RISC Operating System, you need to download the GPIO Module. Copy the files into the RISCOS main folder and load the program by clicking the icon. Write a short program in BBC BASIC Programming Language using StrongArm Editor. BBC BASIC can call the GPIO loaded command and instruct any of the GPIO ports to change its status from high to low or low to high.

A simple one line instruction is shown below to command GPIO4 to change its status from 0 to 1 or L to H:

 

SYS "GPIO_WriteData",4,1

 

The number 4 in the command is the GPIO port and the 1 is the status. Changing the number 1 to 0 revert to the default of this GPIO port which is 0 or LOW. To try the other GPIO ports, just change the number 4 with different values according to GPIO port numbers above.

So, you can switch ON and OFF an LED lamp in series with 1000 Ohms resistor connected to PIN 7 of P1 Header on Raspberry Pi to ground by just running this very short program.

Note that proper polarity of LED must be observed in order for this to work.

But not so fast, in order for the above command to work, you need to initialize first the loaded GPIO module through BBC BASIC program to activate or control the GPIO ports and this is a bit tricky. 

However, there is a simplest and fastest command to do it and is shown below which I believed the most minimal of doing it.

 

SYS"GPIO_ExpAsGPIO",2

SYS "GPIO_WriteData",4,1

 

The problem with this two line routine is, it activates GPIO4 on HIGH-state continuously. Meaning, the LED connected to this port  remain ON even if you close the BBC BASIC Window. The only way to return the GPIO4 to LOW-state is to switch OFF the RPi. 

So, the two line program shown above may not be helpful in utilizing it for ON/OFF control or automation of any device since it is cumbersome to switch OFF the RPi power everytime you want to check each GPIO port.

Nevertheless, it is the safest way for novice who wish to check and confirm the state of each GPIO ports. 

An alternative BBC BASIC routine as shown below is much useful compare to the two line program given above. 

 

 ON ERROR PRINT REPORT$;" at line ";ERL:END

 PROCinit

 DEFPROCinit

 OSCLI"RMEnsure GPIO 0.00 RMLoad GPIO"

 OSCLI"RMensure GPIO 0.40 ERROR Please install the GPIO module"

 SYS"GPIO_EnableI2C",0

 SYS"GPIO_ExpAsGPIO",2

 SYS"GPIO_GetBoard",12

 DIM Port%(16)

 Port%()=3,4,17,27,22,10,9,11,7,8,25,24,23,18,15,14

 INPUT "GPIO NO.:" N%

 SYS "GPIO_WriteData",N%,1

 FOR D%= 1 TO 8000000: NEXT

 SYS "GPIO_WriteData",N%,0

 FOR D%= 1 TO 5000000: NEXT

RUN

 

The above program can switch ON and OFF each GPIO port without having to switch OFF the power of RPi by just entering a valid GPIO port number everytime the program ask for INPUT number.

If you connect an LEDs on P1 Header PIN 7, 11, 13, 15, 19, 21, 23, and 26 which corresponds to GPIO ports 4, 17, 27, 22, 10, 9, 11 and 7 respectively, you can verify eight GPIO ports status everytime you enter a valid value.

You can try to change the value of the delay command statement to change the ON/OFF time duration or how long the LED will be ON or OFF.

For Example:

FOR D%= 1 TO 1000000: NEXT

                        OR

FOR D%= 1 TO 15000000: NEXT

 

Copyright 2013 Kits and Gadgets Electronics Inc. All rights reserved.

Web Hosting by Yahoo

Kits and Gadgets Electronics Inc.
Farwaniya, Kuwait 80003
Kuwait

ph: +965 99571844

kits@kits-gadgets.com