My Account

Wish List (0)

Saved Carts

Compare

Approved Re-Seller
Follow us on Facebook! Follow us on Twitter! Follow us on Instagram!

GPIO & Python (1/9) - Hello World

February 21, 2017

Run your first python program “hello world”

Things you will need:

Raspberry Pi + SD Card
Keyboard + Mouse
Monitor + HDMI Cable
Power Supply

Prerequisites:

Latest version of Rasbian installed on your SD Card
Raspberry Pi setup with a keyboard, mouse and monitor

 

1. Start by opening a Terminal, by click the icon in the taskbar

2. Start by creating a new directory, this is where we are going to store all our scripts for this series of tutorials, make a directory called gpio_python_code:

 mkdir gpio_python_code

3. We can use the command ls -l to view the contents of the current directory:

 ls -l

You should be able to see the directory you created

4. Now we need to change our current directory to the newly created gpio_python_code directory:

 cd gpio_python_code

5. Using the touch command, we can create an empty file. This will be where we are going to code our Hello World script.

 touch 1_helloworld.py

6. Once we have created our empty file, we can use the command nano, to open it in a text editor.

 nano 1_helloworld.py

7. Now enter the following code:

#!/usr/bin/python
#Print Hello world
print "Hello World!"

8. Press ctrl+X to exit, you will be prompted to save the file, simply press Y, and then be you will be prompted to give the file a name.
It will automatically use its current name 1_helloworld.py, so just hit enter to accept.

9. To execute your script, simply enter the following command:

 sudo python 1_helloworld.py

Last update: February 22, 2017

2 Comments(3 Replies)

Leave a Comment

Leave a Reply

* Name:
* Comment:
* E-mail: (Not Published)
Website: (Site url with http://)
Verification code: