Saturday, May 23, 2015

Control an LED remotely using VNC (Virtual Network Computing)

1. Make sure an LED can be switched ON/OFF locally with a Raspberry Pi. See instructions here.

2. Connect Raspberry Pi to the internet and install the VNC server with the following command:

sudo apt-get install tightvncserver


3. Start the VNC server:

vncserver







One line of the results could be like this:

New 'X' desktop is raspberrypi:2

where 2 is the port number.


4. Add VNC viewer to Google Chrome with a PC/Mac.

Connect to Raspberry Pi's IP address, a colon character(:), and the port number. The IP address can be obtained by typing the ifconfig command or the hostname -I command in Raspberry Pi's terminal.)


Click 'Connect'
















Enter the password. (Note: If you want to change the VNC password, simply type vncpasswd command in Raspberry Pi's terminal.)

Congratulations when you can see the desktop of Raspberry Pi!!

5. Open the terminal and type in the following commands:

sudo python

>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup(4,GPIO.OUT)
>>> GPIO.output(4,1)

(Note: VNC is a convenient way to take screenshot / print screen of Raspberry Pi.)

Now the LED connected to GPIO4 should be turned ON!!

No comments:

Post a Comment