This is a complete application chain using my widget, a Sparkfun WiFly 802.11 module and some custom code in C++ and Python to control a servo from a smart phone or tablet.

It consists of a very simple Android app with one slider that talks to a tiny Ardunio clone that controls a SparkFun WiFly module. I’ve tried to keep it cookbook super simple.

I’ve posted all of the parts, designs and code here and on my site, feel free to take a look.

It’s extremely simple. There are three basic parts. The board and the Wifly module, the Ardunio compatible code and libraries that go into that board and a simple Android App written in Python to control it.

First is the board. You can find details on building this board on my site- BOARD CONSTRUCTION

Also on the site are my custom Ardunio libraries, you will need two, both on the files page- ARDUNIO LIBRARIES

To build the widget software you will also need a couple of other things to add to your Ardunio build to compile code for the Attiny 1634- See this Page

The following code uses the two libraries and is downloaded into the widget –

Ardunio Clone Code

#include <WiFlyUart.h>
#include <ServoTimer.h>

WiFlyUart wiflyuart;
ServoTimer servotimer;

uint8_t data, s1, s2, s3, s4;
uint16_t sdata;
uint8_t storedata;

void setup()
  storedata = 0;

void loop()
  // get byte from terminal, send to wifly module
  data = wiflyuart.getByte1();
  // get some data from the wifly, if any, send to terminal
  data = wiflyuart.getByte0();

     if(data == '#')  // is it a servo command?
       storedata = 1;
       case 0:
       case 1:
               storedata = 2;
       case 2:
               s1 = data;
               storedata = 3;
       case 3:
               s2 = data;
               storedata = 4;
       case 4:
               s3 = data;
               storedata = 5;
       case 5:
               s4 = data;
               storedata = 6;
       case 6:
               sdata = ((s1 & 0x0f) * 1000) + ((s2 & 0x0f) * 100) + ((s3 & 0x0f) * 10) + (s4 & 0x0f);
               servotimer.setServo(0, sdata);
               storedata = 0;

You will also need to configure your WiFly so it uses an IP of on port 2000, the instructions for doing that are in the datasheet and user guide on the SparkFun page where you order the widget- Sparkfun Wifly Module

Also important are the build setup to produce the Android application, here are the relevant links:

You can get python here-
Python 2.7

Download for Pygame, I use Python 2.7 32 bit for this (I don’t think the 64 will work for doing Android)
PyGame for Python

This is an add-on to allow you to develop android apps using Python and PyGame.
PyGame for Android Subset

There is also a library of widgets (sliders, dropdowns, buttons, etc) for PyGame called PGU that will also work on Android, IF you make a few changes to it:
Phils Game Utilities

And this link has the changes you will need to make to PGU so it works on Android, it won’t out of the box:
PGU Modifications for Android

If you want to skip building the android app, you can download the completed apk file here:

Slider Android App in Python for PyGame

import subprocess, shlex
import pygame
from pgu import gui
import socket
from pygame.locals import *

# Import the android module. If we can't import it, set it to None - this
# lets us test it, and check to see if we want android-specific behavior.
    import android
except ImportError:
    android = None

FPS = 30
screen = pygame.display.set_mode((800,480),SWSURFACE)

 # Map the back button to the escape key.
if android:
   android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

# set the timeout to 1 second, just in case it's not there

# open a connection to the AP in the locomotive
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    print "connected to"

strs = subprocess.check_output(shlex.split('ip r l'))
gateway = strs.split('default via')[-1].split()[0]
ip  = strs.split('src')[-1].split()[0]

class screenContainer(gui.Table):
    def __init__(self,**params):

        fg = (255,255,255)"Speed: ",color=fg),align=1)
        e = gui.HSlider(0, 0, 1000, size=20, width=700, height=80, name='speed')
        e.connect(gui.CHANGE, self.adjustSliderA, (0,e)) = 0

    def adjustSliderA( self, value):
        (num, slider) = value = slider.value

    def SliderValueA( self ):

app = gui.App()
sc = screenContainer()
c = gui.Container(width=200,height=180)

pygame.time.set_timer(TIMEREVENT, 1000 / FPS)

done = False

while not done:

     for ev in pygame.event.get():
        if ev.type == TIMEREVENT:
        elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
            done = True
            sv = str(sc.SliderValueA()+ 1000 )
            if len(sv) == 1:
               sv = "000" + sv
            if len(sv) == 2:
               sv = "00" + sv
            if len(sv) == 3:
               sv = "0" + sv
            v = "#" + sv + "\r\n"

Here is the servo pulse output: