Telepointer

I’ve had a bit of time to play with my Imps now, and in the spirit of the beta programme, thought it might be fun to document what I’ve been up to. So, without further ado, I present the “Telepointer”. Possibly slightly inspired by the Fing-longer.

Materials

  • 2 × Imps
  • 1 × April board
  • 1 × Hannah board
  • 1 × Arduino Uno
  • 1 × VID29 stepper motor (with natty brass pointer)


Motivation

The basic idea was to connect one of my brand new Imps to an existing Arduino board which was sitting around on my desk from another project. I know that there’s work under-way to create a proper Arduino Impee, but this was very much a case of experimenting with the first things which came to hand.

Along the way, it expanded to encompass HTTP-enabled remote pointing devices, and then a crude attempt at telepresence. Read on for gory details.


Method

The first challenge was to get the Arduino to be able to receive commands from the Imp. As I am lazy with wiring, I opted for I2C, saving two pins compared to an SPI solution. Wiring was thus trivial:

AprilUno
GNDGND
VIN3.3V
Pin 1A5 (SCL)
Pin 2A4 (SDA)

The Arduino was then set up to wait for three characters of data to arrive over I2C, at which point it would convert those characters to an integer between 0 and 945, and call the excellent Switec X25 library to update the position of the pointer (945 is, incidentally, the number of steps available to the VID29 motor attached to pins 4-7 of the Uno board).

The Imp in the April was set up with the following code:

// Web pointer

class PointerInput extends InputPort
{
    name = "angle";
    type = "number";
 
    // Construct an LED and enable it
    constructor()
    {
        base.constructor(this.name, this.type);
        hardware.configure(I2C_12)
    }
 
    function set(val)
    {
        server.show("Value: " + val + " " + typeof val)
        hardware.i2c12.write(1 << 1, val + "")
    }
}
 
// Register with the server
imp.configure("Web Pointer", [ PointerInput() ], []);

This provided a convenient input port in the planner, so that values could be fed in by an HTTP Input Vimp. This somewhat baroque creation thus allowed me to hit a URL with a ?value parameter which would be sent to a Web server somewhere in the Cloud, passed back around the world to an Imp, banged out over I2C, parsed back into a number and finally reflected in the position of a pointer. This sounds almost straightforward when summarised in a sentence, so I decided to add a second Imp into the mix, doubling the potential for latency issues.

The second Imp was placed in a Hannah board, and provided with code to output the position of the on-board potentiometer as a convenient 0-945 integer. As using the pot currently requires a little bit of IO expander fiddling, I have put the code in this gist (most of it is shamelessly lifted from the dimmer example).

This allowed the following planner setup, receiving pointer positions either from HTTP requests or the position of the potentiometer on the Hannah:



Results

After about 90 minutes' experimentation, ta-da:

Telepointer Experiment from Gavin Sallery on Vimeo.

One fully-working Internet-enabled remote pointing device. Twiddling the knob on the Hannah causes the brass pointer to move to a similar angle - no matter where in the world the Imps happen to be! (assuming good WiFi coverage)

Most of the time was spent looking at the Squirrel manual, learning how type coercion works (perfectly obvious once you're used to it). I'm amazed how much it's possible to do, in so little time, using the Imp. Truly impressive, and I have several more mini-projects lined up. Can't wait to get stuck in. Some of them may be a fraction more practical than this.

On a sidenote, even using two Imps and all the intermediate plumbing, and with the Imp service currently hosted only in the US, there was still hardly any perceptible lag. Great work, you guys!

Does anybody know how to embed Vimeo videos? YouTube doesn’t like me.

Like this?  I checked settings and you should be able to.  Do a test and let me know if not.  BTW, very awesome and thanks for the detailed info.   Just curious but, excluding the time you used for figuring out the Squirrel stuff, how long did it take you to build this?

http://vimeo.com/49196141

Oh, cool, thanks for that. I’ll test later (on the train at the moment). Excluding software learning-curve stuff, I’d say about 20 minutes. Probably 2 minutes for the hardware (looking up pinouts), 5 minutes working out how to do I2C on the Arduino, the rest just straightforward coding/debugging. The next one will be much faster!