Secret Spyno: How to customize your Spyno page layout

Spyno Agents appear in columns, like a newspaper. The number of columns you see depends on the width of your screen. Agents are drawn left to right until the edge of the screen. Then they continue on the left in the next row, like a typewriter.


1 | 2 | 3 | 4
5 | 6 | 7 | 8
9 |

To control the order in which your Agents are drawn, edit the Layout in the options page. Layout takes 2 formats:

1) a list

2) a list of tabs

Make your own Spyno page

This is what the tabs layout above gives

Tip: Spacers

Sometimes you’ll find that some columns end up longer than others. You may add “Spacer” agents to skip long columns. Just add a “spacer” in the layout like I did in the tabs example above.

Next: How to view your public Spyno page from anywhere

Secret Spyno: How to add a new agent

Your Spyno Agents do all the work, so you don’t have to. Train agents for each website you want to gather information from. You tell each agent what information to grab, as well as how to present the information to you. Here’s how…

  1. Visit in Chrome’s address bar
  2. Click

    Open the options page

  3. You'll see this Spyno options page

    You’ll see this Spyno options page

  4. Scroll to the bottom and click in the box for "Add New Agent"

    Scroll to the bottom and click in the box for “Add New Agent”

Agent example (options explained below):

Line 2 name: unique name for your Spyno agent (required)
Line 4 periodInMinutes: how often you would like Spyno to fetch from the source URL
Line 6 url: the source URL that has the info you want Spyno to fetch
Line 7 extract: this section tells Spyno what info to grab and how you want it presented
Line 8 root: JSONPath to the list of records you’re interested in
Line 9 fields: JSONPath to the fields you’re interested in, and what name you want to give them
Line 14 template: Handlebars template to tell Spyno how to draw the info you fetched. Spyno automatically packages your info into a list of “rows”, so your template should always have

You may include any html in your template, including ‹style›. E.g.,

Next: How to design a layout for your Spyno page

Arduino Vader “Force Grip” remote car (a.k.a. smartphone virtual wheel)

The 3-wheel car is built with the Makeblock Robot Starter Kit. (Plus some Legos for style.) It has a Bluetooth module. It is controlled by the phone’s gyros via Bluetooth. You drive it like a steering wheel with two hands, or like Darth Vader with one hand.

1. Code for the smartphone below. I saved this as and transferred it to my phone (LG Optimus Dynamic). Then I execute/run it using SL4A from the phone itself:

If you use the code above, the part that you’ll need to tweak for your own build is the DroidGyroJoystick class. Particularly, the pitch/roll numbers my phone gives lying on one edge may be different from yours. The other things you might want to change are the tuning parameters. For example, I configured a “deadzone” with accelZero and turnZero so that small motions near “centered” position won’t count as joystick inputs.

(If you’re new to SL4A, I show how to get set up, as well as where the in “import android” above comes from, here.)

2. Arduino sketch for the robot car below. Sorry it’s unnecessarily complicated. It’s because it’s code for a 2-in-1 IR or Bluetooth + obstacle-avoidance car. If you connect only an IR sensor to Port 6, it will be IR-controlled. If you connect only a Bluetooth module to Port 7, it will be Bluetooth-controlled. Why did I do such a thing? Because I wanted to be able to switch remotes for my kids just by swapping modules, without uploading sketches.

Anyway, what’s important here is that in Bluetooth mode, it recognizes my silly custom command set (fwd, left, right, bwd, etc). These command strings are how the SL4A Python script on the phone instructs the car what to do, over Bluetooth. The other useful thing is that the Bluetooth commands let me specify the speed, in addition to direction. So the more you push your joystick forward, the faster it’ll go.

P.S. I just installed the WordPress “Crayon Syntax Highlighter” plugin. It prettifies blocks of code within ‹pre› tags, like above. I like it so far.

Teaser: Makeblock Robot Starter Kit Cellbot + Sensors + shxtty Path Tracking

Well this was fun. Ingredients:

  • Makeblock Bluetooth module
    To execute instructions from smartphone.

  • LG Optimus Dynamic
    Strapped on robot for sensors. WiFi to talk with Mission Control. Bluetooth to control robot.

  • Tornado server
    Runs on PC. Connects to phone via SL4A. Talks with web UI using websockets.

  • Websockets
    To stream sensor data from phone to web UI. Also relays commands from web UI to robot.

  • Web UI
    Basic webpage with Javascript to handle keyboard events and draw things

  • D3.js
    For rendering the accelerometer G-meter (not shown in video)

  • HTML Canvas
    I just used a 2-D grid and rectangles (fillRect) to draw the robot’s snail trail.

  • Physics
    v = d/t; d = v*t
    Estimate distance traveled by robot using motor “velocity” and time.

  • Ye Olde Trigonometry
    To convert bearing + distance traveled to x-y position in room.

You know, this could make a good school project. Lots of applied basic science, math and programming.

I promise to put up details and code in a later post 🙂

(If I forget, please email and I’ll share everything with you.)

How to fix SL4A webCamFacade exception

On some phones, if you try starting the webcam using SL4A, you will get the following exception:

java.lang.RuntimeException: setParameters failed


Thankfully, the fix is simple. I found Paola Garcia‘s solution everywhere I looked on the internet. She was cheerfully answering everyone’s questions all over the place. She said she fixed the problem by changing the preview format from JPEG to NV21:


Thanks Paola!

But while the fix is simple, the hard part is you have to build a new SL4A app (APK) with the fix. Good news! It’s not really that hard because someone was kind enough to leave instructions. It was a good learning experience for me.

First, follow the first 2/3rds of this post:
Do only the “compile” steps. The last “how to package your app” part doesn’t really apply to you, since you just want to build SL4A.

I’m writing this post because I ran into some problems using the instructions above. I’m sharing my solutions in case anyone else runs into them too. I think most of the problems are because the post was written in 2011, and the latest libraries and SDKs in 2014 don’t play as nicely together.

The step you’ll want to substitute is when you Import your project source code. Instead of the “official” SL4A, Use hg to clone the SL4A repository from Paola Garcia‘s branch:

hg clone

(FYI: I used Tortoise Hg on Windows.)

Now here are the problems I ran into and how I fixed them. (Just in case anyone else runs into them too.)

  1. Missing Android SDK files when compiling
    SL4A needs APIs from the older Android SDK platforms. Check C:\Users\yourname\AppData\Local\Android\sdk\platforms. If you’re missing the directories android-3, android-4, android-7, android-8, you need to download/install them.

    In Eclipse: Window -> Android SDK Manager. Select all the Android SDKs til API Level 8 (Android 2.2).

    Download & install

    Download & install

  2. conversion to dalvik format failed with error 1
    I got this when trying to export the APK after compiling. I couldn’t figure out what the problem was for a while because stupid Eclipse just gave me the error message with no console logs. I finally found the problem when I did “Project -> Run As…” It gave me a helpful error message I could debug. Something about the JDK libraries was conflicting. I made two changes:

    Download JDK 1.6.0_26 and select it here

    Download JDK 1.6.0_26 and select it here

    Drop the Java compiler to 1.6

    Drop the Java compiler to 1.6

  3. Export APK
    I’m an Android noob so this step tripped me up too.
    Export signed package

    Export a signed package. Create a new keystore. I filled in blanks with B.S. and set passwords to “android”.

Finally, out pops your fresh APK with WebCamFacade fixed. Transfer the APK to your phone, uninstall the old SL4A app and install this new one.

Happy hacking! If these instructions were helpful, leave a comment below. Let us know what silly things you used your camera for. I know I have my eye on OpenCV 🙂

How to build a Makeblock Bluetooth/WiFi Cellbot car

– LG Optimus Dynamic
– PC game controller (joystick)
– pygame for joystick input
– python script runs on PC to translate joystick input to movement commands
– SL4A to send movement commands from PC to smartphone over WiFi
– smartphone sends movement commands to Arduino via Bluetooth (also SL4A)
– Arduino translates commands to movement

First, we taught Bao to listen with Bluetooth

That was using pyserial, connecting directly from PC to Arduino via COM17.

I used that to build a basic instruction set to control movement. E.g.,:
!fwd 10
!bwd 5
!left 3
!right 10
!fwdleft 10 5
!bwdright 6 6

Those instructions are parsed and executed on the Arduino. The numbers tell how much the joystick was deflected.

But it wasn’t very interesting to connect directly from PC to robot via Bluetooth. I wanted to strap my smartphone on to add that extra layer of sensors and computing power. So my scheme was for my PC to talk to my smartphone and for the smartphone to be like the Jewel Wasp, controlling the robot via Bluetooth.

This was the main Python code running on my PC:

And this was what I had on the Arduino:

The main changes were to handle commands sent via Bluetooth. Bytes were read one at a time and accumulated into a buffer. The buffer was parsed for commands and the commands were executed. I had to tune the vectors a little to take advantage of the analog joystick input and to smooth out transitions to/from any direction.

I rigged the smartphone onto the robot with Legos. Then I downloaded and streamed the robot’s POV using the “IP Webcam” app because why not?

It’s ALIVE! Robot POV

Pilot POV

It worked better than I expected. The controller lag was not too bad, even with the inefficient command string processing scheme.

Tee hee

When I was done playing I restored it back to the old IR + Ultrasonic setup. I still haven’t figured out what’s the best next step from IR to Bluetooth for a kid.

LG Optimus Dynamic – perfect cellbot phone?

It is the cheapest, full-featured Android phone that I’ve found. Only $20 on Amazon NEW. It feels like finding hidden treasure because the only reason it’s so cheap is that the phone is targeted for the bottom market. And, normal people who buy the phone later add minutes to use it as a phone. But not us! If everyone did what we want to do with the phone, they’d lose money because there’s no way this package can be produced and sold for a profit at $20. So shhhh… let’s just keep this between you and me.

Here’s what you do after you get it:

  1. (optional) Root it. That link takes you to a super simple one-click script and all you need is a PC and the USB cable that came with the phone. I don’t know why I rooted mine, but it’s Android and you can, so why not? You could install this custom ROM too if you want (I didn’t). And if you screw something up like I did, you always go back to “stock” with this.
  2. Install SL4A — the Scripting Layer for Android. This lets you interface with Android and everything your phone’s hardware allows… from a Python script.
    * Install the APK
    * Menu > view > interpreters
    * Menu > add > Python
    * Install the Python APK > OPEN the Python app > Install Python (+ whatever modules you want, like pySerial + pyBluez)

  3. In SL4A, go to Menu > view > interpreters > Menu > start server
    (Note the IP address and port, e.g.

  4. From your PC, write a simple Python script called to talk to the server on your phone:

  5. Notice the “import android” above. That’s from here. Download and put it next to above.
  6. python
  7. CHEER

The hardware isn’t great and it’s still on Gingerbread, but I’m pretty sure it’s still more powerful than NASA’s Lunar Lander. It’s just a steal at $20 for the nice package. Battery life is super and everything works fine. It even has an external micro SD slot! Oh one thing you might want to upgrade for our example above is the Text-to-Speech voice. Gingerbread is old so you don’t get Google’s latest TTS software. So I downloaded IVONA. It’s free, it works for Gingerbread and I like Amy’s UK English voice.

By the way, the SL4A website taught me that I’m not the first brilliant person to think of using smartphones for robots. And, the term for robots that use smartphones is Cellbots. But it still makes me wonder why people still want to mess with things like a $30 XBee WiFi module. Especially when phones like the Optimus Dynamic gives you WiFi (plus everything else) for $20. Who knows.

Happy Hacking!

Robot Kit – Day 7

Our new ultrasonic car + IR code seems to work well, even in the living room. You only wanted to switch to MAX SPEED to watch it go nuts:

We made an interesting discovery: mama’s fuzzy bunny slippers are invisible to the ultrasonic sensor. I tried to demonstrate why by bouncing some balls off different surfaces. But I’m not sure if you got it.

PC to android smartphone recipe

Bao has been taking a break. I think having a robot that moves on its own stresses you out. You’ve been running to flip the off switch after playing with Bao a little. Maybe it’s too much for a 3 year old to deal with. On the plus side, now you know the deal with batteries and recharging, and how Bao gets slow when he’s low on energy. The “energy” and “battery” concept is handy for explaining why you have to eat and sleep.

Anyway, while Bao has been resting, we’ve moved on to the next phase of Bao’s evolution. After some research, I’ve found the perfect recipe. But first, check out the ingredients to see if you can guess what we’re making:

1) LG Optimus Dynamic
This is a $20 prepaid smartphone. Prepaid meaning you can actually buy minutes to use it as a smartphone (e.g. if you need a spare phone for family visiting from out of town). And this one’s nice because it has “triple minutes” for life. So you can buy 200 minutes and the phone will give you 600 minutes magically. But what I’m really buying this for is the hardware and software. It comes packed with the usual sensors: GPS, accelerometer, compass, light sensor; and communication interfaces: Bluetooth, WiFi, PLUS a camera, video recorder, audio recorder, a 1GHz processor, some RAM and 4GB of storage space, AND whatever apps you want and the Android OS to tie it all together. All for $20! In the robot world, each of these devices would cost $20 or more by themselves. But thanks to the economics of smartphones, you can get them ALL for $20. What a wonderful time we live in. I really feel that smartphone tech will accelerate many more industries. (Example: Oculus Rift.) So instead of buying loosey goosey electronics for your robo, the only thing you need is Bluetooth… to pair with a smartphone.

2) Scripting Layer for Android (SL4A)
This is what you install on your Android phone. SL4A lets you tap into every function on your phone from your favorite scripting language (e.g., Python). SL4A can either run a script stored on the phone, or you can connect to SL4A to run a script from your PC. E.g., check this out:

From your PC:

This tells your phone at to, "Capture what I say, then say it back to me." How crazy is that? (Browse the API to see what else it can do.) You can tell it to take a picture, make a phone call, or even drive a robot... (hint hint)

3) web2py
This is what I used to make a toddler-proof web interface or "app" or GUI. The front-end (View) is HTML/Javascript, and the backend (Controller) is Python -- perfect for hooking up with SL4A. Right now, it doesn't do much. But it still has you rolling on the floor laughing, because I send the words you type to the phone and the phone says them (using SL4A). You've been having fun typing different words to see how the text-to-speech voice screws it up. Anyway, this bomb-proof custom toddler web UI works much better than VI, which we were using earlier...

Oh, and here's my latest IR + Ultrasonic car code. It's tuned for the 3-wheel car and my kitchen:

Robot Kit – Day Six

Oh the wonderful things a robot can do

It can go CHOO CHOO

It can go BEEP BEEP

I’m going to resist making any more mods until you suggest them. I also want to give mama a chance to tinker. Because she said, “But I wanted to do the BEEP!”

One thing we might have to do soon is give Bao a bumper. The ultrasonic sensor takes a beating from all the crashes. Anyway, with the new 3-wheel configuration, we haven’t had to recharge it for 3 days. The 4-wheel tank ran empty in just one day. But then again, we’ve only been in IR mode. Maybe the Ultrasonic processing is a power hog too.

And finally, it was time for new batteries. I strapped some Legos to the frame. You put "one door for going in, and one door for going out."

And finally, it was time for new batteries. Just for fun, I strapped some Legos to the frame. You made “one door for going in, and one door for going out.”