> ## Documentation Index
> Fetch the complete documentation index at: https://docs.t3gemstone.org/llms.txt
> Use this file to discover all available pages before exploring further.

# GPIO

> General Purpose Input Output (GPIO)

<Tip>
  By the end of this section, you will gain experience in the following topics:

  * Using GPIO via Gemstone
  * Preliminary preparation for the [t3gemstone/examples/gpio](https://github.com/t3gemstone/examples/tree/main/gpio) project.
</Tip>

GPIO (General Purpose Input/Output) refers to pins used for general-purpose input and output operations in
microcontrollers and development boards. These pins can be configured for both receiving digital data (input)
and sending digital signals (output). Below is an example of an LED blink operation performed via GPIO pins on the Gemstone.

<Frame caption="GPIO Pins">
  <img className="rounded-lg" src="https://mintcdn.com/t3gemstone-754bcb96/xXa-dgH9QsK0Txx6/images/o1-board/32-gpio.png?fit=max&auto=format&n=xXa-dgH9QsK0Txx6&q=85&s=b40d4b34304fda2eef06394e3f64e68f" width="1221" height="750" data-path="images/o1-board/32-gpio.png" />
</Frame>

In addition to the materials listed on the [Quick Start](/en/quickstart) page, you will need an LED, a button,
and a resistor.

<AccordionGroup>
  <Accordion title="LED">
    <Frame>
      <img height="500" width="800" src="https://mintcdn.com/t3gemstone-754bcb96/oFj6OOIrYSQVBj-3/images/led.jpg?fit=max&auto=format&n=oFj6OOIrYSQVBj-3&q=85&s=7fabccda02e21bf3b0f9eb0aaf6d6f27" data-path="images/led.jpg" />
    </Frame>
  </Accordion>

  <Accordion title="Button">
    <Frame>
      <img height="500" width="800" src="https://mintcdn.com/t3gemstone-754bcb96/S1XNwAfVXiylpyYD/images/button.jpeg?fit=max&auto=format&n=S1XNwAfVXiylpyYD&q=85&s=a32c778718490e38e42b12f2b6cb52d7" data-path="images/button.jpeg" />
    </Frame>
  </Accordion>

  <Accordion title="Resistor">
    <Frame>
      <img height="500" width="800" src="https://mintcdn.com/t3gemstone-754bcb96/oFj6OOIrYSQVBj-3/images/resistor.jpg?fit=max&auto=format&n=oFj6OOIrYSQVBj-3&q=85&s=0f719a158cb67ac09e6b6b7d69bef4c1" data-path="images/resistor.jpg" />
    </Frame>
  </Accordion>
</AccordionGroup>

<Steps>
  <Step title="GPIO Connections">
    Make the GPIO connections to the Gemstone board.
  </Step>

  <Step title="SSH/VNC Connection">
    Connect to the development board using either [SSH](../../../quickstart#2-3-connecting-via-ssh-over-network) or
    [VNC](../../../quickstart#2-2-remote-desktop-connection-via-vnc-from-browser).
  </Step>

  <Step title="Shell">
    Create Bash Shell scripts.
  </Step>
</Steps>

## 1. Turning on an LED

### 1.1. GPIO Connections

Connect the LED to GPIOX on the Gemstone, which is available for Input/Output, as shown below.

<Frame caption="LED connection">
  <img className="rounded-lg" src="https://mintcdn.com/t3gemstone-754bcb96/DqBDlLDn29Knu23Y/images/o1-board/22-led.png?fit=max&auto=format&n=DqBDlLDn29Knu23Y&q=85&s=e7ad53e1248db7b80595d398020b7325" width="1337" height="884" data-path="images/o1-board/22-led.png" />
</Frame>

### 1.2. Creating a Shell Script

After connecting to the Gemstone, create a script file for the LED blink operation.

```bash theme={"system"}
touch led-blink.sh
```

Open the `led-blink.sh` file using the `nano` text editor in the terminal interface.

```bash theme={"system"}
nano led-blink.sh
```

Copy and paste the following code into the `led-blink.sh` file.

```bash lines theme={"system"}
#!/bin/bash

while :
do
    gpioset $(gpiofind GPIOX)=1
    sleep 1
    gpioset $(gpiofind GPIOX)=0
    sleep 1
done
```

Press `CTRL+X`, then `Y` to exit the nano editor and save the file.

### 1.3. Running the Shell Script

Make the `led-blink.sh` file executable using the `chmod` command.

```bash theme={"system"}
chmod +x led-blink.sh
```

Run the `led-blink.sh` script.

```bash theme={"system"}
./led-blink.sh
```

Finally, observe the LED blinking at 1-second intervals as shown in the video below.

<Frame caption="LED blink application">
  <video controls className="w-full aspect-video" src="" />
</Frame>

## 2. Reading a Button and Turning on an LED

### 2.1. GPIO Connections

Connect the LED to GPIOX and the button to GPIOY on the Gemstone, as shown below.

<Frame caption="LED and Button Connection">
  <img className="rounded-lg" src="https://mintcdn.com/t3gemstone-754bcb96/DqBDlLDn29Knu23Y/images/o1-board/07-buttons-breadboard.png?fit=max&auto=format&n=DqBDlLDn29Knu23Y&q=85&s=199147c992c807b335d32a24c5786531" width="1337" height="884" data-path="images/o1-board/07-buttons-breadboard.png" />
</Frame>

### 2.2. Creating a Shell Script

Create the script file.

```bash theme={"system"}
touch button-led.sh
```

Open the `button-led.sh` file using the `nano` text editor in the terminal interface.

```bash theme={"system"}
nano button-led.sh
```

Copy and paste the following code into the `button-led.sh` file.

<SnippetExamplesLedScript />

Press `CTRL+X`, then `Y` to exit the nano editor and save the file.

### 2.3. Running the Shell Script

Make the `button-led.sh` file executable using the `chmod` command.

```bash theme={"system"}
chmod +x button-led.sh
```

Run the `button-led.sh` script.

```bash theme={"system"}
./button-led.sh
```

Finally, observe the LED turning on while the button is pressed, as shown in the video below.

<Frame caption="Turning on an LED with a button">
  <video controls className="w-full aspect-video" src="" />
</Frame>
