Controlling GPIO pins of Raspberry Pi Zero


In the previous post, we saw how we can control a Raspberry Pi Zero over UART. We took control over the command prompt through UART. Now we can write a small python script for controlling the Raspberry Pi Zero’s GPIO pin, using the command prompt!!!. (Assuming we are connected to the Pi over UART as mentioned in the previous post.)

Ok, now we have the command prompt in our hand. At present, we are in the home directory. So move to the desktop by typing in the command.


Now we are on the desktop directory of Pi Zero. Now let’s create a file for writing the python code. Type in as followscreate_file

When you press enter after typing the above command, a file named “led_blink” will be created in the Desktop directory. And we can type in the code for blinking an LED in the command window.



The above code can be used for blinking an LED. Here the pin number 4 refers to GPIO 4 of the Pi Zero (not 4th pin but 7th pin) as shown in the following pin map.


The “time” library is used for setting a time delay. While writing code make sure the indentation is proper (since it is important in python).

After finishing the code press ctrl+X to exit from the text editor. Now the command prompt asks for the name in which the file to be saved. save_name

Press enter without changing anything as we have already given the name of the file. So once again we are back to the command window.


You can check whether the file is present in the Desktop by typing the command “ls”. It lists all files and directories present in the Desktop (present folder).


Now we need to have an LED connected to the 4th pin before running the code. The connection is simple. What you need is an LED, two jumper wires, a bread board, and a small resistor. Connect them as shown


Connect the Red wire to the GPIO4 of Pi Zero and Black wire (to which the negative of the LED is connected) to the ground.


Now run the code by typing the following commands in the command window.


Tada!!!!!!!! The LED is blinking Now.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s