Monday, September 24, 2012

Hackable places

I recently got my Raspberry Pi, a cheap single board Linux computer designed for education and hacking. I already have OLPC laptops and Arduinos as hackable places, but it looked like fun. Now I have it I can assess it as a learning tool in home and school contexts.

You can buy from Element 14/Farnell or RS Components  for A$38 but after freight it was A$56 (A$1 is approximately US$1). It arrived from Element 14 in 2 days. Home/school will probably have some of the accessories at hand, but if not the full cost is:

 Rasperry Pi with tax and freight           A$56
 Power supply 5V micro USB              A$20
 Memory card 4GB                             A$15
 AV cable                                            A$2
 USB keyboard                                    A$14
 USB mouse                                         A$5
 Television                                            ?
 Total                                                   A$112+

Compare that with another Linux computer designed for educational hacking, the OLPC laptop at $188 or more realistically $200+ with freight. Consider an old unused PC or laptop as a hacking platform.

Writing the OS, Raspian (Debian) Wheezy, to the memory card was easy, once I really read the instructions. I used the Linux method to setup the card using dd an OLPC XO laptop, I did have to use another computer to unzip the 1.9GB OS when it failed on the XO.

Not having a hi definition TV I used composite video (the yellow plug). I was disappointed with the screen resolution. Its presumably quite good on a hi def tv.

Rasperry Pi GUI, LXDE displayed on a composite TV

Next step was to run the Raspberry Pi remotely from an OLPC laptop using ssh.

Get the IP address of the raspberry Pi

  hostname -I


That's the last time you will need the Rasperry Pi keyboard or TV unless its IP address changes. On the OLPC XO laptop in Terminal enter:

ssh -X ipaddress -l logon 
for example
ssh -X 10.1.1.5 -l Pi

That brings up the Raspberry PI command line interface on the XO. You can run xwindow programs, they display using the XO's window manager.

The Rasperry Pi File Manager displaying on an XO

You cannot start the Pi's desktop with the usual startx, but you can run almost everything using the XO desktop eg

pcmanfx  the file manager
midori      web browser
leafpad     text editor
idle          python IDE
lxtask      the task manager


Though startx does not start the Pi desktop but startlxde gives some success. In Sugar, the desktop is always hidden but the bottom menu bar is available. Using OLPC build 3 13.1.0 in Gnome, the Pi's desktop is visible, possibly due to a bug where the XO's Gnome desktop is not displayed.

The Pi's desktop, LXDE displaying on an XO running Gnome, (build 3, 13.1.0)

So why use the Pi at home or school? School is unlikely to have a class set of TV's or space for them. Home is unlikely to have the USB keyboard, power supply and cables. But both school and home are likely to have older underpowered PC's or laptops (which can be reimaged to Linux if desired) and used as hacking platforms. Those with OLPC laptops have a computer, purpose designed for hacking.

The Pi does provide an additional hacking platform, having multiple platforms is a good thing, not all tasks 'click' or work for all learners.

The Pi can be used as an I/O board like the Arduino. Unfortunately its I/O pins are not protected and can be damaged by 0V (27mA) or voltage >3.3V. Compare with the Arduino I/O which can source up to 20mA to ground and be connected to 5V.

Labels: , , , , ,

Saturday, January 21, 2012

Arduino and the XO laptop


The Freetronics Leostick is a low cost Arduino board. (It is presumed to be low cost, it was cheap enough to place into the satchels of the attendees of LCA2012.) The XO-1.5 already has 2 channel analogue input, an Arduino board can add a lot of extra input and output channels.

This could facilitate a number of low cost science and robotics experiments in schools, experiments at a cost suitable for developed and even developing countries.


There are a number of ways such a board could be used:
  • from the Arduino IDE
  • from TurtleArt, Firmata running on the Arduino
The second version is probably the most practical for classroom use. Once the Leosticks are loaded with Firmata (and this could even be at the factory) all that is requited is TurtleArt drag and drop programming.

Installing the Arduino IDE onto a XO-1.5 laptop (OS880)
In terminal enter the following

sudo yum install arduino

This installs an older version (0021), more importantly it installs all the dependencies including Java and avr-gcc. It is a 60MB download which expands to 200MB of storage, be warned it uses up a lot of precious space.


The IDE can be started from the Gnome menu or with the command

arduino

but it does not have the permissions to see the Arduino board on the USB serial port so start it as root (maybe why)

sudo arduino

The IDE can then be upgraded to version 1.0. This is the version recommended for the Leostick. Download version1.0 from http://www.arduino.cc/en/Main/Software
The file arduino-1.0-linux.tgz uncompresses with the Gnome archive manager. Uncompress it to a convenient location, if for example if you uncompress it to Documents, you will find a directory arduino-1.0 in this directory.

You now have 2 versions of the program, 1.0 (at /home/olpc/Documents/arduino-1.0 ) and 0021 (with components at /usr/share/doc/arduino-0021 and /usr/bin). The later versions 1.0 uses the dependencies installed with the earlier one 0021.

As described at http://www.freetronics.com/pages/leostick-quickstart-guide uncomment the following lines in /home/olpc/Documents/arduino-1.0/hardware/arduino/boards.txt

(or in version 0021 you would need to add them)

leonardo.name=Arduino Leonardo
leonardo.upload.protocol=arduino
leonardo.upload.maximum_size=28672
leonardo.upload.speed=1200
leonardo.bootloader.low_fuses=0xde
leonardo.bootloader.high_fuses=0xd8
leonardo.bootloader.extended_fuses=0xcb
leonardo.bootloader.path=diskloader
leonardo.bootloader.file=DiskLoader-Leonardo.hex
leonardo.bootloader.unlock_bits=0x3F
leonardo.bootloader.lock_bits=0x2F
leonardo.build.mcu=atmega32u4
leonardo.build.f_cpu=16000000L
leonardo.build.core=arduino
leonardo.build.variant=leonardo

Launch the Arduino IDE (sudo /home/olpc/Documents/arduino-1.0/arduino), and select Tools > Board > Arduino Leonardo.
to select the Leonardo hardware

select Tools > Serial Port
a new device appears with Leostick plugged in, dev/ttyACM0, select it.

You can now upload example programs, eg blink, to the Leostick.

NOTE: this will overwrite the program that came with your Leostick that plays a tune, watch
http://forum.freetronics.com/viewtopic.php?f=27&t=167
for the original program


Controlling the Arduino with Turtle Art
Load Firmata software into the Leostick, this can be done on an OLPC, another Linux PC or Windows. Once this is done the Leostick can be used as a I/O expander for Turtle Block drag and drop programming. No Terminal or Gnome work would be needed.

http://tonyforster.blogspot.com/2010/10/arduino-fork-of-turtle-art.html

The version here works for older Arduino boards on Sugar 0.88 It needs patching at TurtleArtActivity.py, line 834 as described in the link above. The baud rates of Turtle Art and Firmata need to be patched.

Sugar 0.88 (Fedora 11) recognises an older Arduino board as as serial device but not the Leostick. Later Arduino boards are dev/ttyACM0

This version is hard coded to dev/ttyACM0, that means it only works the first time the Leostick is plugged in and not at all for older Arduino boards. It is patched and works on Sugar 0.94.

The quick and dirty patches are:
Turtleartactivity line 835
self.palette_buttons[i].set_tooltip('thing')
line 868 commented out
# palette_toolbar_button.set_expanded(True)
serialposix.py line 273
# self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)
self.fd = os.open('/dev/ttyACM0', os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK)



see also:
http://tonyforster.blogspot.com/2010/10/turtle-arduino-display-inputs.html
http://tonyforster.blogspot.com/2010/10/turtle-arduino-digital-write.html

Labels: , , ,

Monday, May 09, 2011

Turtle Art and USB serial devices

Using the Python block to interface with a USB serial device (tested with the Arduino)

Requires the Pyserial library. The recommended install procedure does not work because it requires a developer installation of Python python2.6-dev

Instead copy the serial directory here to the directory home/olpc/Activities/TurtleArt.activity

Load the Python block with this code

Tested on an Arduino, the Arduino had a simple echo program loaded using the Arduino IDE on another computer but this should work with any board with a FTDI FT232R USB serial chip

Ideas for controlling devices with the FTDI FT232R USB serial chip here

Labels: , , , ,

Saturday, October 16, 2010

Turtle Arduino digital write


Turtle art source
Python code block source (Python in open doc format)

Get Turtleart Arduino working with your version of Sugar. Load the Turtle code into TurtleArt Arduino. Load the python code. Then run.
Click with the mouse to switch a digital output.

Labels: , , , ,

Friday, October 15, 2010

Turtle Arduino, display inputs

This Turtle Art Arduino project reads and displays the digital inputs.




http://wiki.sugarlabs.org/go/File:Ard.ta

Labels: , , ,

Arduino fork of Turtle Art

I tried the Arduino fork (here) (or here) of Turtle Art. This version of the Arduino fork (based on V86) can co-exist with Turtle Blocks. There is another based on V80.

I first loaded Firmata into the Arduino using the Arduino software on a PC. Then I tried to control the Arduino from Turtle Art but got errors:

OS19 Sugar 0.90 fails to start TurtleArtActivity.py", line 834
OS373pyg Sugar 0.88 fails to start TurtleArtActivity.py", line 834
OS373pyg Gnome starts but fails firmata.py line 140
OS67 Sugar 0.84 fails to start permission denied opening USB0
OS67 Gnome permission denied opening USB0
OS67 Gnome (as Superuser) starts but fails firmata.py line 140
OS767 Sugar 0.82 permission denied opening USB0


Then realised that TurtleArt and the Arduino were set to different baud rates causing the error at firmata.py line 140:

I edited file taarduino.py line 5 to set the baud rate to 57600

class TAArduino(object):
def __init__(self, baud=57600):

To match the setting in Arduino Standard Firmata (loaded into the Arduino board) line 274

Firmata.begin(57600);

Thes gets Arduino working under Gnome under OS373pyg (and presumably OS67 in Gnome as superuser). The following blocks will flash the light on output 13

To get it working under Sugar (OS373pyg), and presumably Sugar 0.88 and 0.90 builds the following dirty hack worked:
TurtleArtActivity.py, line 834
replace
self.palette_buttons[i].set_tooltip(HELP_STRINGS[name])
with
self.palette_buttons[i].set_tooltip("thing")

There is another version,
http://people.sugarlabs.org/rafael/TurtleArdu.xo

This can not co-exist with Turtle Blocks, you need to uninstall Turtle blocks first.
After that it still fails on import serial
on OS373pyg. Copy a serial directory from the other version
into the Activity directory gets past that bug.
You also need to set the baud rate as described.

Oscilloscope

Labels: , , , ,