This is an old revision of the document!


Resources

XO Laptop

Getting Started

General Tips

  1. An XO can be installed with one of many Sugar(OS) versions. You may or may not need to have the most updated version of Sugar. See the table for what versions have been installed at CCCS: Version Numbers for XO-1 laptops at CCCS
  2. There is no password for root so it is fairly easy to brick the XO
  3. CTL-ALT-ERASE is the XO equivelent to CTL-ALT-DEL on a windows computer, you also need to do this anytime you make a change in Terminal before it will take effect
  4. When the touchpad gets too sensitive it needs to be recalibrated; for instructions on how to do this look at issue 4 in the Past Issues section
  5. The battery tends to die in about 1.5-2 hrs of constant use
  6. Be very aware of the hardware limitations
  7. There is a slot on the lower right hand side of the screen where a SD card can be inserted if you need extra storage space.
  8. The floss manual is a great place to get more information on the XOs.

Investigating the XO

These are general ideas of things you should do and understand before trying to program for the XO

  • Turn on your XO, go to the control panel, give it a new name, and choose a new color icon for your XO
  • Flip through and understand the different views: Neighborhood, Group, Home, and Activity
    • Neighborhood: Press the circle on the left side of the keyboard that has a ring of dots around it
    • Group: The circle next to the neighborhood view key that contains three dots
    • Home: the circle located next to the group view, and containing a single dot
    • Activity:The fourth button in the row of keys, It is a circle with a square in the middle
  • Look at the information available in the frame
    • The frame is the square in the top right corner of the keyboard
  • Investigate the journal and how to open and save files there
  • Investigate the wireless networks available and how they appear
  • Go to the Terminal Activity and play around, try to figure out the filesystem layout
  • Note that there are no folders in the journal

Sugar GUI

Sugar is the Fedora Linux based operating system used by OLPC on their XO laptops and now maintained by SugarLabs. For more information on sugar look at the floss manuals

Preparing for crashes

  • DO NOT try to open more than three activities at the same time
  • Save work early and often
  • Create a USB drive for your group with the image of the operating system so that if you brick your XO is can be fixed quickly.
  • Keep a backup copy of all of your code on a USB or another computer

Reflashing

Reflashing will restore the XO to its factory settings. This process can be used for upgrading or downgrading the XO. Directions can be found in the Floss manual. While off, insert a USB stick with the image to reflash with, and while holding down the four game buttons, power on the XO.

Running Sugar

Version numbers for XO-1 laptops at CCCS

  • XO series: (CT4Y machine: XO-1)
  • Sugar OS version: (CT4Y machine: 8.2.1 if not upgraded)
  • Python version: (CT4Y machine: 2.5.1)
  • PyGame version: (CT4Y machine build 802: 1.8.0, CT4Y machine build 852: 1.8.1)
    • pygameversion.py
      import pygame.version
      print "PyGame version:", pygame.version.ver
  • OLPCGames version: (CT4Y machine: won't be installed. It is only installed on xo machines that are used to develop games and publish xo files. xo files can be transferred to other xo machines without OLPCGames.)
  • Security: disabled

Machine Information

Version Numbers

See this page which describes how to check your XO version. The information is most likely found under “Control Panel : About my XO”.

Build, release, and update information.

CCCS has XO-1's with build 802.

“OLPC is not the only one making XO-1 operating system builds. You can also obtain builds from others in the wider community” (link).

  • Sugar Labs build: Dextrose, Sugar 0.88, Fedora 11.

How to differentiate between XO-1 and XO-1.5?

Success with getting to the OK prompt by holding the “X” game button when powering on, and then hitting ESC when prompted to halt the normal startup. So, the laptops at CCCS all appear to be unsecured, and that we will not need a developer key.

Differences between XO versions

Xo-1 XO-1.5 XO-1.75
Number of dots on hinge none three seven
Wiki Pages XO-1XO-1.5XO-1.75
DRAM 256 MiB 1 GiB n/a
Mass Storage 1024 MiB 4 GiB n/a
Fedora varied 11 14
Python Version n/a v2.6 v2.7

Emulation

Emulating the XO

  • The XO Laptop Wiki no longer recommends using the QEMU emulator for emulating the XO. For new information on emulating the XO look here:

Install the sugar package that comes with Ubuntu to use their Sugar Emulator. You can actually open up two different emulators and have them act as two different XOs.

Open two different emulators using these two seperate commands:

ubuntu-prompt$ SUGAR_PROFILE=cat sugar-emulator ubuntu-prompt$ SUGAR_PROFILE=dog sugar-emulator

Note that cat and dog can be anything, as long as they are different.

Sugar on a Stick

With Sugar on a Stick (SOAS), you can boot directly to the Sugar OS on any machine without the need virtualizing or emulating Sugar. Students can use the journal on the stick to save their work.

Windows

In order to use sugar on a stick:

  1. Download the liveUSB creator
  2. Either download sugar on a stick onto the flash drive or use the liveUSB creator to install a version of sugar
  3. Follow the instructions for the USB creator to make a live USB
  4. Note: When making a live USB make sure to leave persistent storage space if you want to be able to save anything
  5. Restart your computer and look for an option to go into settings and change BIOS boot order so that the USB flash drive is first
    1. Some computers do have the option of booting to a USB drive without changing your settings, but if you intend to use sugar on a stick more than a couple of times, you will most likely want to change your BIOS settings anyway
    2. You should now boot to your flash drive. It is possible that you will have to press and extra key in order to successfully boot sugar on a stick, so pay attention
  6. For more information on booting to a flash drive look here
Mac

Go here for information on downloading sugar on a stick. The instructions are still in beta, and may not be effective.

Virtual Box

Virtual box is useful for emulating a variety of operating systems including sugar. To download Virtual box go here

You will also need a virtual image of the OS you wish to emulate. You can get a .iso file of fedora here. Once you have a running emulation of Fedora you can open the add/remove software application to install Sugar.

If you run into errors attempting to run your virtual machine, your disk image may have been corrupted during the download. You can click on the settings option to change the disk image.

Linux

Familiarity with the Linux family of operating systems can be useful when dealing with the XO. If you haven't done so before, you might consider installing Linux on a machine you have access to. Ubuntu is a distribution that is particularly suited for beginners, and Fedora (the basis for the XO operating system) is good for intermediate users. The Gentoo installation process is considerably more involved, but upon completion you will have a better understanding and appreciation for Linux. For Windows users, the Ubuntu CD provides Wubi, a Windows program that allows Ubuntu to be installed without re-partitioning your computer. Sun Microsystem's VirtualBox provides Windows and Mac OS X users the ability to install any flavor of Linux as a virtual machine inside their existing OS, free of charge.

Some useful links related to Linux:

Programming

Setting up a Development Environment

The XO Laptop Wiki Provides these guides for setting up a development environment (These are extremely important!!):

XO API and Software

Extracting activity source code from .xo actvity files

When an application is ready for deployment on the XO, the source code is packaged into a .xo file which can be natively imported by the XO laptop. If you need to obtain the source code for an XO application, there are 2 possible ways to do it:

If the program has been imported as an XO activity:

  • The source code may be found in the directory called /usr/share/sugar/activities/ACTIVITY_NAME.activity

If you have access to the .xo file:
A .xo file is really a compressed zip file: it can be extracted/opened to show the source code and other relevant files. Use:

  • unzip FILENAME.xo -d DESTINATION_DIRECTORY

or a similar command. The source code for the application can be found in DESTINATION_DIRECTORY/bin/

Downloading an activity

  • Copy the activity folder onto a flash drive
  • Plug the flash drive into the XO and give it about 20 seconds to process
  • Open the Terminal and type in the following commands pressing enter at the end of each line:
    • cd /media
    • ls (this will make the name of your flash drive appear)
    • cd NameOfYourFlashDrive
    • cd NameOfActivity.activity
      • You may have to move down a couple of levels to get to this point using the ls and cd commands
    • python setup.py dist_xo
  • Go to the journal and find the activity there. If you click on it, it should install

Bundling activities for the XO

Mesh

Mesh Networks are no longer supported in XO 1.5 source

Python

Install Python on your computer

For Windows Users:

  1. Python
    1. The first step in this process is to download a copy of the Python installer, this can easily be accomplished via Python’s website.
      • Online guides will frequently point you toward ActivePython, while this program is highly rated it also requires an email subscription to access the download. For this reason I have avoided using it
    2. Go to Python’s website ( http://www.python.org )
    3. Click on “Downloads”
    4. Select the appropriate Windows installer and download it.
      • Pygame will will mostly work with python 3 with a few exceptions Pygame FAQ but version 2 is still necessary for working on the XOs.
    5. After the file is completely downloaded, open the containing folder and open the executable file you just downloaded
    6. Follow the installer instructions
      • This method of installation will also install the default Python IDE (called IDLE) for editing code, there is additional information needed to install Python for a different IDE such as Emacs, Eclipse, or VI
  2. Pygame
    1. Go to the official website for Pygame ( http://www.pygame.org/ )
    2. Click on the “Download” tab from the main page
    3. Under the sub-category Windows select the appropriate version of the installer for your machine (this is completely dependent on which version of Python was installed in Step1)
      • If one were to install the build for Python 2.5.4 they would then want to download the Pygame installer file titled “pygame.x.x.x.win32-py2.5.msi” (where the x’s represent the version number of Pygame).
    4. Find and open this update to Python, it will run an automated installer
    5. Upon completing the setup be sure to test that functions and other aspects of Pygame are working correctly.

For Ubuntu (or similar Unix Distributions)

Python
  • Being a developer friendly environment, Ubuntu comes with a pre-installed and fully operational version of Python
  • Otherwise, one would the package manager of your specific distribution to download the necessary files…
  • Ubuntu/Debian use aptitude:
# apt-get install python
  • RHEL/CentOS/Fedora (this includes your XO) use yum:
# yum install python
  • Gentoo/Sabayon use portage (consult documentation about USE flags for these distributions):
# emerge -av python
  • These package managers are to be executed from the terminal command line, a shell (search “term”). They must be run with root (administrator) privileges, using the “sudo” command.
  • To access Python, simply enter ‘python’ in the command shell; this will allow one to interact with the Python interpreter via the shell
  • The pre-installed build of Python on Ubuntu does not come with an editor, however, it is fairly easy to configure Emacs or any other editor to be used with the language.
    • To install Emacs you can, once again, use a package manager like apt-get
# apt-get install emacs21
  • Python's default editor, IDLE, is also friendly for programmers new to python, and can be installed with the package manager.
Pygame
  • Pygame is not a standard library for the Python programming language, therefore it is not included in your Ubuntu environment and must be installed
  • As mentioned in Step 1, the package manager can be made use of to install applications and packages – the same can be done to install the Pygame graphics library using:
# apt-get install python-pygame

Vista and PyGame Instructions

If you have Python (2.5 or higher) and PyGame 1.8 installed, you should be good to go. I've tested crashRun on both MacOS X and Windows and I hope it'll run on Linux, too.
If you need Python, you can download it from: http://python.org/download/
And PyGame is available here: http://pygame.org/download.shtml

Vista users note: when I tried the python installer on a Vista machine, the installer didn't modify the PATH to include Python (it appeared to on XP). You can set this variable by right-clicking My Computer in the Start menu, selecting Properties, Advanced, and then pressing the Environment Variables button. You'll need to append “;C:\Python25\” to the end of the PATH variable.

Some Python Notes

Recursion

  • Python is not optimized for tail recursion
  • Recursion uses a lot of memory, not good on an XO laptop
  • It is recommended to use loops instead of recursion when possible

For those new to python, the following links can be of great benefit:

Some Slides from previous classes:

Python and Game development tutorials:

A separate page has been created that contains example python programs and games made by previous classes.
Python Example Programs

Pygame

Pygame provides a relatively simple API for programming games in python, and is incredibly useful for animations. It does not however, provide GUI elements such as buttons/text fields/menus/etc. These must be created by hand when using pygame.

Pygame Tips

Spyral

Virtual Machine

We have a virtual machine set up for our server needs. The information for it is located on this page.

The database information is here

Example Communication via POST

This file passes data via the POST method to the server. The server will log all data passed by $_POST[“data”]. So in this example, “test data from python again” will be passed.

The server script post-server.php catches this string and appends it to an output file test-output.txt.

Try it out, and run this python script from your local machine!

python-client.py
'''
Richard Burns
November 28, 2010
 
Test script which passes information to the class apache server via the POST method.
 
The server script currently captures this information and appends it to a testing
output file, demonstrating one way that we can pass data to the server for it to 
record.
 
Taken from:
http://docs.python.org/library/httplib.html
 
TODO: test size limitations of the POST
'''
 
import httplib, urllib
 
#params = urllib.urlencode({'milk': 1, 'eggs': 2, 'bacon': 0})
params = urllib.urlencode({'data': "test data from python again"});
 
headers = {"Content-type": "application/x-www-form-urlencoded",
                "Accept": "text/plain"}
 
conn = httplib.HTTPConnection("cisc367.acad.cis.udel.edu:80")
 
#conn.request("POST", "/cgi-bin/query", params, headers)
conn.request("POST", "/post-server.php", params, headers)
 
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()