Saturday, March 21, 2009

Turtle Fileview

A fileviewer for Turtle Art using the programmable Python brick

The Python brick code
def myblock(lc,x):
if x==0:
dialog = gtk.FileChooserDialog("Load...", None, \
fname = None
response =
if response == gtk.RESPONSE_OK:
fname = dialog.get_filename()
f = open(fname, "r")
text =
text="".join([z for z in text if ord(z)>0])
The file selection dialog box

Output screen, viewing a py file

Labels: , ,

Sunday, March 15, 2009

Turtle Oscilloscope

For the experimental Turtle Art Portfolio V18 for the XO hardware, this program uses the programmable brick and sensor input . (As at V19 Turtle Art Portfolio, the 2 imports below are no longer required.) (As at V44 of Turtle Art, the programmable block is supported but sensor input still is not.)

# Oscilloscope
# Tony Forster, March 2009

from taturtle import *
from math import *
def myblock(lc,x): # x is volts input #old x coordinate #old y coordinate
nx=ox + 1 #new x coordinate
ny= x #new y coordinate
setxy(, nx, ny) #jump to new coord.

A better oscilloscope

Labels: , , , ,

Saturday, March 14, 2009

XO - Electricity and magnetism

XO laptop
75mm (3 inch) nail
insulated copper wire
3.5 mm phono plug
refrigerator magnet

Wrap 50 turns of insulated wire onto a nail and connect the two ends to a phono plug as shown (if it is a stereo plug, probably the red wire and the copper shield). Connect the phono plug to the microphone input.

Start the Measure activity, sound tab, time base, maximum vertical sensitivity, minimum sweep speed (as shown).

Wipe the sharp end rapidly over the back of the fridge magnet, try both directions.

Try a different number of turns of wire
Try moving the nail more slowly, what happens to the period, frequency and amplitude of the wave?
What is happening?
Why does it work better on one axis of the magnet? (hint rub 2 magnets together)

Labels: , ,

Thursday, March 12, 2009

Data logging with the OLPC

The OLPC XO can measure external inputs with its microphone jack


Standard 3.5mm 2-pin switched mono microphone jack; selectable 2V DC bias; selectable sensor-input mode (DC or AC coupled); (1)

If using a stereo plug it is the red wire plus the earth.

It is protected at the input by a 5V zener diode and has a measurement range of 0.3V to 1.9V. The allowable input is -0.5V to 5V Inputs outside this range will cause excessive current and damage. (2) (3)

Addition of a 150k ohm series resistor would (I expect, no guarantee) give a reduced sensitivity in voltage mode (0-4V) but allow inputs to +- 100V without damage. Input impedance in resistance, volume and pitch modes is much lower but a 1k ohm series resistor should still allow inputs to +-12V.

Measure V20

Resistance mode

350 ohms to 10 k ohms (0.2V to 1.78V, open circuit is 2.2V) the volume slider on the sound tab has no effect on sensitivity, half scale is 1.1V or 2.8k ohm resistance

Voltage mode

DC coupled, 0.3V to 1.78V

there is still 0.6V bias at open circuit, input resistance =140k ohms


Selecting the sound tab which allows sensitivity and timebase adjustment applies 2.2V bias and has AC coupling. Sensitivity is adjustable from 1mV peak-peak full screen to 0.2V peak-peak full screen.

TurtleArt V32

(sensor input is disabled in V42, maybe this stuff is irrelevant)


Measuring resistance with Turtle Art

299 = 16 k ohms (maximum)

150 = 3.2 k ohms

0.2= 350 ohms (minimum)

The bias voltage is only applied briefly, approximately 140 mS, any circuitry would need to stabilise in this time. The cycle repeats quite quickly in the above program.

Bias voltage, reading resistance in Turtle Art


When doing forever print voltage, open circuit gives a reading of 221. The bias is still applied but the cycle time is much slower, 500 mS for a program cycle

The voltage readings are inconsistent, when applying 0.3 V at the input ( from a source impedance of 30 K ohms), the output jumps between zero and full scale. Maybe its too sensitive, reading millivolts with a 0.3V deadband?


Forever print pitch is broken, error: global name real fft is not defined


With the internal microphone, forever print volume gives an unstable reading, 30-200. Forever print volume wait 1 gives a background level of round 30

External input shown below, 1 kHz square wave applied through 4 uF and 100 k ohms, reads 30 for low inputs but jumps to 200 for a 2V p-p square wave in the unbiased state, note that for the period bias is applied, the early period, the input impedance is lower and the square wave has a smaller amplitude.

Forever print volume wait 1, screen size 0-3V height and 200 mS width, for the earlier part bias is applied, initial pulses of bias as in previous shot are just visible

Turtle Art Experimental V18V19

forever print pitch fails on the 8th loop, error line 65 unpack requires a string length of n. This is a buffer underrun issue and does not occur for manually repeated print pitch. Specifically, unpack() is failing if the buffer from alsaaudio has an odd number of bytes. In the trace below, odd length buffers were hacked to return zero. Doesn't seem to be doing anything sensible.

pitch for a 30 mV 1 kHz square wave, Turtle Oscilloscope

forever print resistance 500 ohms to 15 k ohms but unstable at zero ohms, alternating between 0.2 and 150 . Again, the 150's are caused by undersize buffers, this time even length.

forever print voltage 299 for 0V and 1.9V, 0.2 for 1.2V

This can be fixed by replacing the code in at line 87

   elif self.sensor_type==3:
sensor_val1 = (audioop.avg(buf, 2)*0.00152333) + 50.0

Giving a range of 0.4V to 1.9V for 0-299 but similarly to resistance returns occasional 150's for zero volts input. Again, the 150's are caused by undersize buffers, this time even length.

Turtle Oscilloscope, 0V input, values of 0 occasionally returned by audioop.avg, which after scaling (x+50)*3 =150

At line 358

changing set_capture_gain() seems to have little effect on mode 3 (voltage)but
changing set_mic_boost() gives a range of 1.06V-1.2V in mode 3 (voltage).

forever print volume 299 is 40 mV p-p, occasionally gives 0 or large negative number. Again, the errors are caused by undersize buffers, -ve for buffer length =1.

Volume, Turtle oscilloscope, 30 mV 1 kHz square wave, note spikes to zero



Microphone input: standard 3.5mm 2-pin switched mono microphone jack; selectable 2V DC bias; selectable sensor-input mode (DC or AC coupled); (1)


"What is the maximum voltage I can put into the mic/input port on the XO without risking damaging it?

Short answer -- 0.3V to 0.9V . ... -- there is a 5V reverse biased Zener diode at the input that protects the input ...

My measurements (I used a current-limited adjustable voltage supply) indicate no more than -0.5 volts to +5.0 volts. Beyond these voltages my audio input port drew large, potentially-destructive currents. This voltage is measured relative to the "chassis common" (the outer "shell" of the audio plug). Therefore: even a little AA 1.5 volt battery improperly applied (i.e. "backwards") may damage the laptop.

The Analog Devices AD1888 sound chip has the ability to sample DC voltages. Experimentally it has been found out that the range is fairly linear, however the range that it can sample is restricted to 0.3V - 1.9V, with all the internal gains turned to the minimum."


"The XO hardware has been designed to facilitate measurement of DC voltages by the addition of an electronic switch that can be controlled via a setting on the Alsamixer called 'Analog Input' . The high-pass filter can also be turned on/off by a setting 'High Pass Filter' in Alsamixer. The ability to control V_REFOUT (bias voltage) is also available and is done by the control 'V_REFOUT' in Alsamixer.

Measured between the center conductor and the shield (ground, i.e. +0 volts). When an input voltage is greater than +5.0 volts or less than -0.5 volts the input-protection circuitry draws currents greater than 100 milliamperes and will damage the laptop. Also, the AD1888 codec's absolute maximum voltage (given a 5.0 volts supply) is -0.3 volts to +6.3 volts.

You must use input protection resistors and voltage divider if voltages greater than +5 volts will be applied. Resistors and a fast-blow fuse are recommended. Resistors should be present in both the ground circuit and the signal circuit, and this may introduce noise. A better circuit is a high-impedance differential-input amplifier."


John Graham-Cumming:Building a temperature probe for the OLPC XO-1 laptop


An XO Oscilloscope to Measure Children's OLPC Learning, One Laptop Per Child News

Labels: , ,

Sunday, March 08, 2009

One Player Pong for TurtleArt

For the experimental fork of TurtleArt V18

Move the bat with the A and D keys
Slow execution speed
Running out of canvas for the blocks

Labels: , , ,

Thursday, March 05, 2009

Orbital motion in Python and TurtleArt

Orbital motion according to Newton's law of gravity using the programmable block in the experimental fork of TurtleArt for the OLPC. (Now included in Turtle Art from V44)

Intended to demonstrate two things,
a) that programmable simulations are good ways for kids to learn physics and maths
b) that the programmable block provides a way for kids to move from simple drag and drop programming to more complicated text based programming

As at V18 of experimental TurtleArt, Rainbow is preventing the loading of the file from the journal. See previous post. The following hack gets round the problem.

Open Terminal,
go to /home/olpc/Activities/TurtleArtPortfolio.activity
Save your edited in the Journal immediately before typing
(as at v19 this is not required, neither are the 2 imports)

# Orbital motion with inverse square law
# Tony Forster, March 2009
# For each iteration, acceleration is calculated
# as inversely proportional to orbital distance.
# The horizontal and vertical components of the
# acceleration are added to the horizontal and
# vertical components of the velocity.
# The horizontal and vertical velocity components are
# added to the x and y coordinates.
# A line is drawn from the old to the new coordinates.
# The turtle is moved.

from taturtle import *
from math import *
def myblock(lc,x): # x is not used
hspeed=lc.heap.pop(-1) # pop hor speed from the heap
vspeed=lc.heap.pop(-1) # pop ver speed from the heap**
hspeed -=*800/(point_distance2*point_distance)
vspeed -=*800/(point_distance2*point_distance) #old x coordinate #old y coordinate
nx=ox + hspeed #new x coordinate
ny=oy + vspeed #new y coordinate
setlayer(,630) #make turtle visible
setxy(, nx, ny) #jump to new coord.
lc.heap.append(vspeed) #push vert speed onto heap
lc.heap.append(hspeed) #push hor speed onto heap

What was difficult:
Any syntax error in will prevent TurtleArt from loading.
The Rainbow problem makes it more complicated, also copy-from-journal is unreliable and poorly documented, I obviously do not understand the syntax.
The error log shows where your error was in the source listing but if you haven't reloaded TurtleArt, you can be running one version of the code and seeing errors in a different version.
The TurtleArt wait block is necessary to see the turtle but it slows execution too much, it could be shortened, i used a hack setlayer setlayer(,630) but don't fully understand.

Labels: , ,

Wednesday, March 04, 2009

Browse activity on the OLPC

In the spirit of "eat your own dogfood" I am trying to do as much as possible on my XO laptop. A laptop for children's learning should be "low entry, high ceiling and wide walls". That is, while providing an easy entry into computing, it should not have roadblocks to more complex tasks or uses which the designer never considered.

Here is today's roadblock on filling in a web form. Here is what I saw on a PC with Firefox 3.0.6
And on an XO with Browse V98, when selecting, no scroll bars:
And after moving to the next item, the selection unselects:
I am not sure if Browse supports JavaScript at all.

Here is part of the offending code, (html brackets changed to {})

{link rel="stylesheet" href="../fso.css"}
{style type="text/css"}
td {font-family: Arial, Helvetica, sans-serif ; font-size: 10pt; color: #090707}
{script language="JavaScript"}

{td colspan="1"}
{select name="Q136383" SIZE="3" }
{option}Not applicable{/option}

Labels: , ,

Monday, March 02, 2009

OLPC language localisation

image from

One of the strengths of the OLPC is its philosophy of the child being "not just a passive consumer of knowledge, but an active participant in a learning community" and so the software was designed with "no inherent external dependency in being able to localize software into their language".

Language localisation of software
It seems that language localisation of the software would be a good learning project for children, it would give them a relevant and authentic project which I would expect to be highly motivating. I would expect it to be quite challenging for them and require a deep understanding of language and of the subject that the language was describing.

I found the Wiki of the Bering Strait School District inspiring with wiki dictionaries of the Inupiaq and Yupik languages which could be edited by teachers and students. Students could use a similar process to localise the OLPC software into their own language.

Localising Speak text to speech
An activity which the students apparently enjoy is Speak , a text to speech synthesiser. I tried to reproduce the process of editing the language dictionary described in the instructions on and to provide more detail so that students could follow the instructions and localise Speak for their language.

I found the process quite difficult, largely due to the file management provided by the Journal. You can find the steps I followed here.

What was difficult:
Zip files can only be unzipped by Etoys
Etoys will not unzip to the Journal
Etoys has limited file privileges, I ended up unzipping to a temporary file in an obscure location
Transferring to the Journal requires Linux directory navigation and understanding of Mime
I was unable to transfer from the Journal to the target directory because of root user issues
The Journal added a .txt extension that had to be removed
copy to and from journal are poorly documented and complex

An operating system for children is ideally low entry, high ceiling and wide walls. That is it should be easy for children to start with, have a well graded pathway to very complex functions and it should allow children to do anything, including things that we could never anticipate.

I am trying to get to like the Journal and Browse but its not easy.

Labels: , ,