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 manufacturing, stock 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:
- 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:
- Buy a DVI or LCD expansion board.
- Use VNC to remotely display the smalltalk environment.
- 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:
- Header P9 Pin 32 to one end of our photocell
- Header P9 Pin 39 to the other side of the photocell along with one end of our resistor,
- 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 192.168.2.2 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:
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 exit
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.