Wednesday, April 29, 2015

Beginner Python with Raspberry Pi Tips

Below are some tips for beginners who want to develop python program on Raspberry Pi (assuming you are using Windows as the development environment.

1. Interact with Raspberry Pi
After connect rasberry pi to your computer, you need to configure the ip address of your network adapter, to ssh login to raspberry pi (e.g. configure an address such as 10.0.2.15), use Putty which can be downloaded from http://www.putty.org/ . After launching Putty, enter the "10.0.2.15" as  the address and select ssh and 22 as the port, and connect

2. Install TightVNC server for remote GUI access to Raspberry Pi
Accessing raspberry pi via putty or ssh won't allow you to launch the raspbian x11 GUI by running command such as "startx". In that case, you can use TightVNC server allows you to remote login to the Raspbian x11 GUI on the raspberry pi so that you can interact with the raspberry pi in its GUI.

>> sudo apt-get update
>> sudo apt-get install -y tightvncserver

To start and stop tightnvncserver on display 1:

>> vncserver :1
>> vncserver -kill :1

Now get a java tight vnc viewer from http://www.tightvnc.com/ and you will be able to login and view the GUI of the raspbian OS.

3. RPi.GPIO install with python

Normally for python, you will want to install the pip for easy installation of python package, this can be done by

>> sudo apt-get install python-pip

If the raspberry pi does not have the RPi.GPIO package installed, you can then run

>> pip install RPi.GPIO

The above command may failed for some errors such as "Python.h: no such a file...". The alternative is to run:

>> sudo apt-get install rpi.gpio

After this, you can start writing python codes to control raspberry pi using the RPi.GPIO package.

4. Note
Suppose you don't have a raspberry pi and just want to have a quick look of the raspbian os GUI on raspberry pi, you can download and run the emulator here:

http://sourceforge.net/projects/rpiqemuwindows/

No comments:

Post a Comment