April 28, 2012

Remote BeagleBone GUI with Squeak and VNC

In my last post, I gave a brief demonstration of installing and using Squeak smalltalk on the BeagleBone.  In this post, I'd like to show you how to install VNC and configure the BeagleBone to automatically start Squeak on boot.  Squeak has a native smalltalk VNC client and server available, which gives you the ability to leave your graphical environment running after disconnecting from the BeagleBone.  By adding Squeak to the boot process, the programs we write will be automatically started and our development environment will always be available.

* If you don't have a working X11 desktop or just want to try the example from the previous demo using VNC, you can download a VNC enabled Squeak image here and skip the first step.  The default password is "beagle" (without the quotes).

Step 1: Install VNC in Squeak

Login to your BeagleBone using ssh and start Squeak as demonstrated in my previous post.  Once Squeak is running you can follow along with this video:


Step 2: Configure Squeak as a service

Now that the Squeak image has been prepared for VNC access, we can add it to Systemd so it will be started as a service.  Run the following commands from the BeagleBone CLI as root:

cd /lib/systemd/system
wget http://unthinkable.org/dl/squeak.service

Next we will configure the Squeak service to automatically start at boot time:

systemctl enable squeak.service

We can also start it on our currently running system:

systemctl start squeak.service

Step 3: Connect with a VNC client

The Squeak VNC server will now be running on your BeagleBone and you can connect with a VNC client.  I normally use the 2.0 release of cotvnc on OS X, but for this next demo I'll use Vinagre, which is installed by default on Ubuntu Linux:

VNC doesn't allow us to resize the remote GUI, but we can use the following procedure to resize with X11:
  1. save and quit from the VNC session
  2. login to the BeagleBone via ssh with X11 forwarding
  3. start Squeak as demonstrated in my previous post
  4. resize the GUI to the preferred dimensions
  5. save and quit
  6. run "systemctl start squeak.service" from the CLI to restart Squeak as a service

April 20, 2012

Smalltalk on the BeagleBone

If you've ever struggled with (or simply tired of) the tedious code-compile-upload-boot-test-debug-code-compile... cycle of creation on the arduino, this may be the platform you were looking for.  Running Squeak smalltalk on the BeagleBone allows you to create your software and interact with your hardware while it is running.

Smalltalk is an easy to use programming environment that also happens to be very powerful.  It is used for everything from embedded devices, educational programming, and 3D Online Worlds to semiconductor manufacturingstock trading, and international shipping.

For this quick introduction, I'm going to show how to connect a photoresistor to the BeagleBone and display it's value in a real-time graph, in 11 lines of code.  To follow along you will need to have:
  •  BeagleBone
  •  breadboard
  •  photocell and 10kΩ resistor
  •  desktop or laptop computer with a network connection to the BeagleBone

Since the BeagleBone doesn't have a video output and we're going to be working in a graphical environment, we need to use an alternative. Here are a few options:
  1. Buy a DVI or LCD expansion board.
  2. Use VNC to remotely display the smalltalk environment.
  3. Use X11 to remotely display the smalltalk environment.
I'm going to use option 3 for this demo, since is easy and can be done without modification to any of the software we are using.  X11 is pre-installed on Mac OSX and Linux.  You can get X11 for Windows, but it tends to be difficult to get running and you will probably be happier with VNC. VNC adds some very useful functionality and is what I use for most of my BeagleBone development.  I'll cover VNC in my next post.

Step 1: Build the circuit

The electronics components needed for this demo consist of a photoresistor (aka photocell) and a 10kΩ resistor that I picked up from my local Radio Shack.  Of course you will also need some bits of wire ( I'm using jumper wires, which aren't a bad investment).  Using these components, we'll build a pull-down circuit.  Here is a breadboard view from Fritzing:

The BeagleBone pin connections are as follows:
  1. Header P9 Pin 32 to one end of our photocell
  2. Header P9 Pin 39 to the other side of the photocell along with one end of our resistor,
  3. Header P9 Pin 34 to the other end of the resistor.

Step 2: Configure the BeagleBone

I am using a 5V wall adapter and an ethernet cable connected directly to my Mac for this demo.  I've enabled Internet Sharing which has assigned the IP address to my BeagleBone. To use X11 forwarding on the BeagleBone we need to add the xauth package.  First, login to your BeagleBone with ssh from a terminal window:

ssh root@

Now that you have a root shell, run the following:

opkg update
opkg install xauth

Next we can install Squeak:

mkdir /opt
cd /opt
wget http://unthinkable.org/dl/squeak4.2-beaglebone.tgz
tar xvzf squeak4.2-beaglebone.tgz

Now you are ready to follow along with the video.

Step 3: Play

Here is the smalltalk code I used for this demo:

graph1 := GraphMorph new.
graph1 openInWorld.
graph1 extent: 700@500.
graph1 clear.

analog1 := FileStream readOnlyFileNamed: '/sys/devices/platform/tsc/ain1'.

[1000 timesRepeat: [
 | lightValue |
 lightValue := (analog1 contents) asInteger.
 graph1 appendValue: lightValue.
 (Delay forMilliseconds:50) wait.
]] fork.