Hi Everyone
Its have been few days that i haven’t posted something. Today i am going to explain how to start writing programs in raspberry pi over SSH (Secure Socket Shell). So cope with me 😉
Lets start with some basics –
Which Programming Language?
Raspberry pi officially comes with “Python” as a major programming language. It comes with python IDE which is known as “IDLE3”. Well we are talking about programming over SSH, so forget about it.
Programming?
For writing a program in Raspberry pi or in any other system you first need an editor. If you are running “Raspbian Wheezy” on your r-pi, you have various options available (vi, nano etc).
You will find “vi” hard to understand and in case of nano (writing program in Python), you have to cope with indentation problem. So what to use?
Forget it for just now. We will be writing a python program in nano. So first we have to be logged in to our r-pi over SSH. We may use Chrome’s “Secure Shell” or “Putty” for our desktop. You can find link’s as follows –
Putty Link & Secure Shell Link (for Chrome)
So download it and run, you will find something like this –
Type username (pi) and IP (your raspberry ip address) and port (22 : default) and press ENTER. It will ask for password (“raspberry” – default). Type it and you have now successfully logged in.
Write a program!
Now its time to write a program. Lets say I want to write a program named “hello_world.py”. So type at your terminal –
$ sudo nano hello_world.py
It will write an empty file in your current working directory named “hello_world.py” and will open a window –
Whatever you want to code you have to write in here.
To save your code press CTRL + O and press ENTER.
To run your code first you have to close “nano” by pressing CTRL + X and then in your terminal write –
$ sudo python hello_world.py
Any Alternative?
If you find difficult like me to code in “nano”, definitely you will be looking for something better. As I also want to debug my python code but “pdb” is not so cool to do that. So what is an alternative?
Fortunately, Adafruit came up with something called “Adafruit WebIDE”. It is web based IDE (Integrated Development Environment) which allows me to debug my code and also it has one more cool feature called visualizer which helps us understand structure of the program while running it. You can find its overview @ Adafruit Web IDE overview Link
For installing WebIDE follow instructions @ installing instructions link
Now if you have installed WebIDE its time to run it. Type “r-pi IP-Address” in your web browser it will ask for login. So press sign in to login and screen which will follow is –
- In left side there is list of repositories (currently 2) –
- Adafruit-Raspberry-Pi-Python-Code
- My-pi-projects
Adafruit-Raspberry-pi-Python-Code contains some sample python programs provided by Adafruit.
My-pi-projects directory is meant to directory where you will store all your programs which you want to run, edit, debug and clone.
- Under this section there is “Clone Repository”. Clicking on this popup will open where you can enter GIT url of your code repository on git and click “Clone Repository”.
- On the right side at top, there is “Terminal” option to open Linux Terminal where current working directory is “/usr/share/adafruit/webide/repositories”.
- When you click on “my-pi-projects”, there is README.md file in this directory and just under this there is CREATE PROJECT FOLDER option to create new folder. Click on this and type desired name and press “Submit”.
- Folder is created and you have entered it. Now you can see 3 more options :
- CREATE NEW FILE
- CREATE NEW FOLDER
- UPLOAD FILE (To upload file to raspberry pi from your local pc)
- When you create new file, window that opens have few options on top:
- TERMINAL: Will open OS terminal.
- RUN: Will run your written code.
- DEBUG: Will help you debug written code.
- VISUALIZE: Will help you understand basic structure of code while running it.
- SAVE: Used to save code in repository.
- COMMIT AND PUSH: Will commit your code file in bitbucket.org repository.
That’s all for now. In my next post i will write more about web-ide and other ways to do programming. Till then i hope you will try above things. Feel free to ask anything related to r-pi.
Stay Connected 🙂 and don’t forget about feedback:)