Difference between revisions of "Raspberry Pi - Week 3"

From Robert-Depot
Jump to: navigation, search
(Further Python Help)
(Further Python Help)
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Raspberry_Pi#Course_of_Instruction | <<< back to Raspberry Pi]]
 +
 
==Review==
 
==Review==
Connecting to the pi from a local computer with ssh.
+
Installed an OS image, created a user account with super-user permissions.
 +
Connected to the pi from a local computer via ssh. Copied files with SCP.
  
 
==Graphical Interface through the Network==
 
==Graphical Interface through the Network==
Line 26: Line 29:
 
==logging onto raspberry pi from vnc client==
 
==logging onto raspberry pi from vnc client==
 
*You need a vnc client. This will connect to the vnc server which is currently running on your raspberry pi.  
 
*You need a vnc client. This will connect to the vnc server which is currently running on your raspberry pi.  
*Adafruit suggests "VNCViewer", available for free for most platforms from http://www.realvnc.com/.
+
*Adafruit suggests "VNCViewer".
*Download and install VNCViewer.
+
*Download and install VNCViewer. http://www.realvnc.com/download/viewer/
 
*Run the software.
 
*Run the software.
*In the "VNC Server:" field, enter the IP address for your PI and the port number you started vncserver on. For instance <code>192.168.2.2:1</code> is IP 192.168.2.2, port 1.
+
*In the "VNC Server:" field, enter the IP address for your PI and the display number you started vncserver on. For instance <code>192.168.2.2:1</code> is IP 192.168.2.2, display 1.
 
**You selected the port when you started vncserver on the pi.
 
**You selected the port when you started vncserver on the pi.
 
*Click connect.  
 
*Click connect.  
Line 49: Line 52:
 
*If you have installed python, you have IDLE. most likely on your laptop as well.
 
*If you have installed python, you have IDLE. most likely on your laptop as well.
 
*Raspbian comes with two python installs, Python 2.7 and Python 3. We are going to use 2.7. 3 is the future.
 
*Raspbian comes with two python installs, Python 2.7 and Python 3. We are going to use 2.7. 3 is the future.
*Subprocess.call
+
 
**python subprocess documentation - http://docs.python.org/2/library/subprocess.html
+
*Example, taking photos and sending them to the laptop. take_photos_and_send.py [[:File:photo_loop.tar]]
 +
*Uses <code>subprocess.call</code>, and <code>time.sleep</code>
 +
*python subprocess documentation - http://docs.python.org/2/library/subprocess.html
 +
*time documentation - http://docs.python.org/2/library/time.html
  
 
==Festival example==
 
==Festival example==
*
+
[http://wiki.roberttwomey.com/images/5/5d/Speech_loop.tar speech_loop.tar ]
 +
*For both of these examples, you will need to edit the path to the festival command.
 +
*The program was written on my Laptop, so I used the path to festival there. ''/Users/rtwomey/...''. On the raspberry pi the festival install path is ''/usr/bin/festival''.
 +
*You can find the path to a program with the <code>which</code> command. For ex:
 +
**<code>which festival</code>
 +
**gives you the current festival install directory.
 +
*'''speech_loop.py''' - counts up from 0.
 +
*'''speech_potato.py'''. try it and see ;)
  
 
==Client - Server architecture==
 
==Client - Server architecture==
 
*My Convex Mirror project uses a client-server architecture:
 
*My Convex Mirror project uses a client-server architecture:
[[:File:convex_mirror_client_server.tar]]
+
[http://wiki.roberttwomey.com/images/3/36/Convex_mirror_client_server.tar convex_mirror_client_server.tar]
 
*Server on raspberry pi. '''convex_mirror_server.py'''
 
*Server on raspberry pi. '''convex_mirror_server.py'''
 
**opens a socket on a certain port, and waits for requests from clients.
 
**opens a socket on a certain port, and waits for requests from clients.
Line 67: Line 80:
  
 
==Further Python Help==
 
==Further Python Help==
*Interactive introduction, in browser - http://www.learnpython.org/
+
*[http://learnpythonthehardway.org/book/ Learn Python the Hard Way]
*Code Academy
+
*Interactive introduction, in browser - [http://www.learnpython.org/ learnpython.org].
**start with [[Python Syntax | http://www.codecademy.com/courses/introduction-to-python-6WeG3?curriculum_id=4f89dab3d788890003000096]]
+
*Code Academy's [http://www.codecademy.com/tracks/python python track]
*A Gentle Introduction to Programming Using Python, MIT OCW [http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/index.htm]
+
**start with [http://www.codecademy.com/courses/introduction-to-python-6WeG3?curriculum_id=4f89dab3d788890003000096 Python Syntax] course.
 +
*[http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2011/index.htm A Gentle Introduction to Programming Using Python], MIT Open Course Ware (OCW).
 +
*Python.org links for [http://wiki.python.org/moin/BeginnersGuide/NonProgrammers Python for Non-Programmers]. A lot to sort through, you pick one.

Latest revision as of 07:18, 26 April 2013

<<< back to Raspberry Pi

Review

Installed an OS image, created a user account with super-user permissions. Connected to the pi from a local computer via ssh. Copied files with SCP.

Graphical Interface through the Network

  • VNC, Virtual Network Computing:
In computing, Virtual Network Computing (VNC) is a graphical desktop sharing system that uses the Remote Frame Buffer protocol (RFB) to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction, over a network. [1]
  • Remote Desktop.
  • You need a client and a server. The server runs on the raspberry pi. The client is on whatever machine you are connecting from.
  • We can install our vncserver through the raspbian package manager, apt-get.

using apt-get to install vncserver on the pi

  • apt-get, Advanced Packaging Tool:
works with core libraries to handle the installation and removal of software on the Debian GNU/Linux distribution and its variants. APT simplifies the process of managing software on Unix-like computer systems by automating the retrieval, configuration and installation of software packages, either from binary files or by compiling source code.[2]
  • apt-get is is included with the raspbian operating system, by default.
  • While logged in as a user with Super User (su) permissions.
  • First you want to update your package index with the most recent info from the source repositories.
    • sudo apt-get update
  • Now install the new software you want. In this case, we want tightvncserver. This is a VNC server for the raspberry pi.
    • sudo apt-get install tightvncserver
  • Answer the prompt about XYZ new files will be installed, "Y".
  • The package manager should download and install the appropriate files.
  • Check that it works. Start the VNC Server from the command line:
    • vncserver :1
    • You will be prompted to set a password for people to login to the system with VNC. Decide on a password and enter it. Then reenter it. You can decline the offer to enter a view-only password.
  • Now you need to login from your remote machine.

logging onto raspberry pi from vnc client

  • You need a vnc client. This will connect to the vnc server which is currently running on your raspberry pi.
  • Adafruit suggests "VNCViewer".
  • Download and install VNCViewer. http://www.realvnc.com/download/viewer/
  • Run the software.
  • In the "VNC Server:" field, enter the IP address for your PI and the display number you started vncserver on. For instance 192.168.2.2:1 is IP 192.168.2.2, display 1.
    • You selected the port when you started vncserver on the pi.
  • Click connect.
    • The software will prompt you about an unencrypted connection. Respond as you see fit.
  • You'll see a popup window for VNC Viewer - Authentication. The Username field is blank. Enter the password you selected above when you ran vncserver.
  • You should now see the LXDE with large raspberry picture.
  • Have fun in a comfortable, windowing environment style.

Adapted from Adafruit - http://learn.adafruit.com/adafruit-raspberry-pi-lesson-7-remote-control-with-vnc/overview

Installing Festival TTS with apt-get

We can install other sorts of packages with apt-get on the pi. For instance if we want to install The Festival page for Text To Speech (TTS) synthesis. (http://www.cstr.ed.ac.uk/projects/festival/)

Basic Scripting of command-line tools with python

  • IDLE - Python's Integrated DeveLopment Environment.
    • an IDE.
  • If you have installed python, you have IDLE. most likely on your laptop as well.
  • Raspbian comes with two python installs, Python 2.7 and Python 3. We are going to use 2.7. 3 is the future.

Festival example

speech_loop.tar

  • For both of these examples, you will need to edit the path to the festival command.
  • The program was written on my Laptop, so I used the path to festival there. /Users/rtwomey/.... On the raspberry pi the festival install path is /usr/bin/festival.
  • You can find the path to a program with the which command. For ex:
    • which festival
    • gives you the current festival install directory.
  • speech_loop.py - counts up from 0.
  • speech_potato.py. try it and see ;)

Client - Server architecture

  • My Convex Mirror project uses a client-server architecture:

convex_mirror_client_server.tar

  • Server on raspberry pi. convex_mirror_server.py
    • opens a socket on a certain port, and waits for requests from clients.
  • Client on laptop.
    • bgprocessing_client.py does background subtraction.
    • layering_client.py interacting with the same server, does layering of images with not bg subtract.
  • If you wanted to use these examples you would need to change the IP addresses to match your own setup, and install the necessary external packages (command line tools such as potrace, opencv, gphoto2 etc.) that I am using on each of my systems.
  • Use package management!

Further Python Help