— tech ramblings by konstantin gredeskoul, aka "kig".

BORAT: Bathroom Occupancy Remote Awareness Technology with Arduino

A great company where I work, Wanelo, with all of it's 35 people, recently moved to a new office which has only two single-occupancy bathrooms, each on a separate floor.

A few times a day, when the need was strong, I'd go to the downstairs bathroom only to find its door locked. I'd then run upstairs and find the other one locked too... Damn! I'd come back down only find out that someone else grabbed the first bathroom while I was upstairs. Argh!

You can likely see how this could be a frustrating and disruptive experience even just once or twice. Now multiply that by 35 employees and every work day of the year, and you end up with an actual productivity problem.

Given my foray into Arduino over the last few months, I knew I could come up with a solution. I got approved for a small budget of about $200, and started looking around.

The problem was very simple: people needed to know when each bathroom was occupied, or not. Just like on an airplane you can see bathroom light on/off, I wanted something similar for our two bathrooms. Something everyone could see.

↳ Keep reading …

Choosing The Right Arduino IDE (And The Winner… Is Eclipse!)

As a relative late comer to Arduino world, I went through the beginner tutorials and examples using the provided Arduino IDE. I faithfully downloaded it from web site, took a quick tour and was pretty unimpressed with the set of features. For one, I am very particular about the color scheme of my programming editors, and not having a choice was an immediate downer.

Arduino IDE is simple to use, and I think this was one of the key design goals for this software. It is commonly used to introduce many folks to programming electronics, and just programming, notably in C/C++. As such, this tool is pretty limited, and limiting too. Very quickly I found myself very stuck unable to browse through external symbols by clicking through them, using auto-complete features, refactor code, and so on: all the "basic" features I so got spoiled with, by tools such as JetBrain's RubyMine, AppCode, IDEA, open source (but originally IBM's) Eclipse, and not to mention Apple's XCode.

Arduino IDE

After going through several example projects using the IDE I became more and more frustrated with its limitations. Programming hardware is hard enough (pun intended), and the IDE is supposed to make life easier.

For example,

  • How do I explore the source code of the included libraries that are being used by my sketch?
  • Why does "Import Library" insert a new #include into my sketch when I already have one?
  • Why is tab indentation not maintained as you move to the next line while editing?
  • Why is the board and port selection remain global, and are not assigned to each sketch? Can't I be working on multiple boards at the same time, especially, say, when they talk to each other?
  • And of course... why can't I change the goddamn colors :)

So I became worried that my foray into electronics would die young if I didn't find a more capable programming alternative, and so I started exploring.

Arduino IDE Alternatives

First off – a tiny disclaimer: this is not a feature by feature comparison of Arduino-capable IDEs. It's a personal opinion of an experienced software engineer, who recently entered this domain. I work on Mac OSX, and so I only briefly mention the Windows options. But on a Mac I did end up trying most of the options listed here.

When I talk about software IDE, I generally do not mean a fancy text editor. While I know that plenty of great developers love and use text editors on complicated software projects, the convenience of a true IDE on a small to mid-sized software project is hard to dispute. So while I do, when appropriate, use a combination of VIM or TextMate for exploring or quickly editing, I prefer to actually write code in a true IDE. If I had to define what true IDE means for me, I would list the following features:

  • full indexing with ability to click on a symbol or use a key shortcut to go to the definition or source file where that symbol is defined
  • in-place documentation lookup for APIs
  • code auto-complete (configurable, and not automatic – key press invoked)
  • code auto-format with automatic tab positioning while editing
  • refactor (extract method, etc)
  • symbol rename (automatic renaming of functions, class names with file name change, variables, etc across many files)
  • built-in debugger
  • automated test integration
  • arguably less important are global project search, global find and replace, project-level symbol lookup.

My absolute favorite over the years have been the series of IDEs for all popular languages produced by JetBrains –– a company that singlehandedly dominated the IDE nitche for over a decade now, including winning over droves of professional java programmers away from Eclipse.

But anyway, here is the list of what's available for proper software development of the code, with Arduino as the final destination:

Arduino IDE for Visual Studio

(screenshot courtesy VisualMicro)

  • embedXCode – use XCode 4 or XCode 5 to write Arduino sketches. I tried to install this, and was able to pretty quickly compile a sketch. But to be honest, I never loved XCode to begin with. It's gotten infinitely better over the years, but something about it's Preferences screens is so incredibly daunting, that I never got really good at XCode. Perhaps someday :)

Arduino IDE for Visual Studio

(screenshot courtesy StackOverflow)

  • This brings us to the last contender: Eclipse. Eclipse has been around for a long time, and is an amazing platform for so many things, including software development. Having used Eclipse on several Java projects in the past, it seemed the most natural fit. So I downloaded the Eclipse Arduino Plugin, and that's what the rest of this post is about.

Eclipse Arduino Plugin Saves the Day

Having now used this IDE for several weeks straight, I am pretty happy with the Eclipse Arduino Plugin. The project is pretty active on GitHub, and the author is also quite nice :)

The Case for Open Source

One of the first things I bumped into, with the nightly build of the plugin and with my Arduino Esplora board, was a pretty major problem: I couldn't upload any sketches. So I posted a bug report on GitHub, and author replied with a quick note on how to get the source of the plugin, and which class to look at, so that I could fix the problem. It sounded like a challenge. Of course I took it.

For the next few hours instead of working on my Arduino sketch I was fixing the Eclipse plugin. To my surprise, it was relatively easy to get setup with the environment where I imported the entire plugin source into JetBrains IDEA (haha, sorry Eclipse! You are still number two :) and was able to diagnose and fix the issue with the timing of opening serial port and uploading the sketch. A few hours later my pull request was merged, and the nightly build of Eclipse Plugin started working for everyone with Arduino Esplora! That, my friends, is the true power of open source.

While I was at it, I also updated the README with proper markdown and (perhaps) slightly better English. And of course I couldn't stop there either, and continued going slightly crazy, massively refactoring serial communications of the plugin deep into the night, and then submitting a beautiful pull request. However, at that point the plugin author probably had gotten pretty annoyed that I was making his code look and work a bit better, and sadly rejected the PR, explaining that another rewrite of serial comms is happening. Oh well, at least I can keep using my fork on my own machine, where I get to see pretty error messages that actually explain what's going on :)

But I digress.

Installing Eclipse Plugin for Arduino

Option 1: probably the simplest way to get started is by downloading the nightly build, in my experience they've been pretty stable. The single-file download will already contain a compiled binary (called something like "" or similar), and you can just run it.

Option 2: But my preferred way to install the plugin is to first install a full version of Eclipse Luna for C/C++, and then add Arduino plugin to it via software installer.

↳ Keep reading …

Books I Am Reading

This post is about the books I am reading right now, with short reviews.


Zero to Maker: Learn (Just Enough) to make (Just About) Anything by David Lang

Something must be said about inspiration. This book is great at providing continuing inspiration in my quest for building with my hands. I am still reading this book, but I love it. The specific practical advice is not always realistic or applicable to anyone, but the back story is fantastic and I love reading how the author turned into maker so quickly and so successfully. Perhaps there is a path down the road of this hobby that offers something different.

Makers: The New Industrial Revolution by Chris Anderson

This book by the head editor of Wired magazine provides insightful and fascinating view point that we are at a brink of the new industrial revolution. If anything, this blog and my obsession is a living proof. Anderson believes that the current tools, costs and opportunity is immense for those interested in becoming inventors and entrepreneurs at the same time. He offers some convincing evidence, by artificially bringing to the market a new type of sprinkler, following his dad's footsteps decades ago. It's a thought provoking read and I highly recommend it.

Make: Electronics by Charles Platt

This is one of the best introductory books to electronics, and it takes time to get through. I am about 25% through, and I already learned so much about physics, electricity and electronics to be pretty dangerous, literally, in my office/workshop. I read enough to understand that a fuse may save me from a fire, and have since promptly purchased a buttload of 2A, 3A, 5A mini car fuses, which work great with big batteries.

Anyway, this book I highly recommend for the fundamentals.

Programming Arduino – Getting Started With Sketches, by Simon Monk

Very short, and very surface level coverage. I did not find this book overly useful, and finished it in a weekend.

Exploring Arduino – Tools and Techniques for Engineering Wizardry by Jeremy Blum

This is a fantastic book, very much in depth and with great examples. I am still reading it. Probably the best book on Arduino at the moment.

Arduino Cookbook, by Michael Margolis

This book was recommended to me at a meetup, and it's a thick heavy book. I must admit I only looked through the first third, and have not yet used the recipes in practice. But the breadth of coverage is impressive.

Making an Arduino Controlled Robot, by Michael Morgolis

This is another great book with lots of good examples, but all the code is filled with delay(). I'll discuss in later posts why this is terrible, and offer an alternative. I just started reading it, so standby for more details.

Programming the BeagleBone Black, by Simon Monk

This is a better "short" introduction than Arduino, and uses JavaScript (since BeagleBone now comes with Cloud9 + node.js). I read about a half, since I am not currently working on BeagleBone yet, I am waiting for another moment.

↳ Keep reading …

How It All Started

I've been a software engineer or technical leader for most of my career, which approaches on 20 years (I just recently hit 40 earlier this year). I started coding when I still lived in Kharkov, Ukraine, not too far from where the war is raging right now (a fact I am still finding hard to believe). I wrote my first program sometime in 1988, which was a keyboard driven version of "Paint": you could move a cursor that drew a line on your screen, and save and recall your creations. This was all before the mouse made it over there.

Just around my 40th birthday I wanted to fix a subwoofer that I intended to use for the birthday party that day. It was a Mackie powered subwoofer, about 500W (plenty loud), but it's been broken since the last Burning Man, when it quietly died in the 110'F heat. I opened it up, found some wires that seem inappropriately disconnected, and soldered loose ends to what I thought was the right receptacle with a crappy giveaway soldering iron I received at some Java conference more than a decade ago. I wasted two hours of my life aimlessly trying to "fix" the subwoofer, and while I was doing that a realization dawned on me: I have absolutely zero idea about how any of this electronics actually works... I did remember some facts about resistors and capacitors, but I surely couldn't tell what was what in front of me, how it all fit together, and more importantly: how was I going to fix this thing.

In the end I was not successful in my quest. I've assembled the subwoofer back to it's original form, and it's currently sitting in my garage waiting to be delivered someone with trained hands at JK Sound SF, someone who can actually fix it. But in the meantime, I signed up for a soldering class at the TechShop, and purchased a "pro" level soldering iron – Weller WES51 on Amazon. This is how it all began.

↳ Keep reading …

Back-Seat Driver: Autonomous Robot Maneuvering

BackSeat Driver: Autonomous Vehicle Library for Arduino

Today I am introducing the Back Seat Driver – a library for programming autonomous (or not) arduino based robots. Source Code on Github.

This library provides a convenient non-blocking command API to programmatically drive an autonomous vehicle. Current implementation is aimed at a 2-wheeled robot, with the two Servo motors setup opposite each other. Therefore to move the robot forward (or backward), two Servos need to rotate in the opposite direction (this is certainly true in the current version of the library, but may be more flexible in the future if need arises).

Library Features:

  • Intuitive and easy to read/use API
  • Non-blocking duration-based maneuvers, i.e. "go forward for half a second, then do this..."
  • Un-timed moves, such as "go backward" indefinitely
  • Turn by angle, computed based on the the wheel ratio coefficient that can be adjusted for each size of tire
  • Much more linear speed curve, when mapping from speed in % from 0 to 100, to Servo microseconds. Using arctan() function allows to flatten out uneven Servo speed response curve (see graph in the PDF for Parallax Arduino Robot Shield Kit).

Design Boundary

Imagine an autonomous robot, driving itself around, sensing and reacting to the environment around it. You can imagine yourself shouting robots command, as you see it approach a table: "Stop, turn left and see if it's any better". For any robot to be autonomous this logic must also be implemented in code. But the imagined scenario creates a clear boundary which separates an instructional algorithm that avoids obstacles and determines what the robot does next, from the robot movement library, which simply knows how to spin robot's wheels to achieve a move or a turn. This project, as you probably guessed, is about the latter part.

Non-Blocking Control

Nowhere in the library is the dreaded delay() function called (this is similar to ANSI/C sleep()), and so the program flow is never paused. . The client of the library is able to provide callback functions to be executed at the end of a given maneuver, such as a turn.

As a trade-off, the client is required to periodically call robot->isManeuvering() function, to ensure that all callbacks have a chance to execute and clear, and any maneuvers stopped. If this function is not called frequently enough, turns can go on for longer and thus be wildly inaccurate. This requires more coordination, but provides for a lot of options to execute logic while maneuvers are happening.

Neither does the library use any precious Arduino interrupts.

Hardware Requirements

For an example hardware see DIY kit called "Parallax Arduino Robot Shield" available here:

Any Arduino card with 2 Servo motors attached would work. For most Servo motors that can move the vehicle you would need a decent power supply. The robot above uses 5 x 1.5V AA batteries for a total of 7.5V and about 1Amp. A dedicated motor shield such as Adafruit Motor Shield V2, would be an excellent choice, but there are many others.

Disclaimer and Invitation to Collaborate

This project is also an eternal learning quest for the author, who only started tinkering with Arduino at the end of June 2014. Therefore please keep in mind that this library is not written by an Arduino expert, although the author does have an extensive software development background in other languages.

Any suggestions or modifications are welcome, and will be considered, discussed and decided on in the issues or pull requests.


Moving Forward, Backward

The speed value passed into the APIs provided by the library are expected to be always positive, and expressed in percent % of the total max speed of the servos.

    // puts motors into 100% speed, forward motion,
    // and immediately return from the function


   // go backwards @ 50% speed, for 1 second, and then call
   // turnAround() local function (defined elsewhere)
   robot.goBackward (50, 1000, &turnAround);


   // somewhere else in the code

   // wait for the any maneuvers to finish
   if (!robot.isManeuvering())  { ... }


Speed is always passed in a positive integer, from 0 to 100 (expressed in %).

Internal helper converts that to Servo's microseconds PWM timing. In addition we apply arctan() function to transform speed and provide more linear response between speed and RPMs, compared to when specifying microseconds directly.

Duration and Callbacks

Duratation based API calls, such as

// load specific Adapter for our motors
#include <BackSeatDriver_TwoServoAdapter.h>
// now load the main library
#include <BackSeatDriver.h>

// initialize the adapter with two pins assigned to
// the two servos
BackSeatDriver_TwoServoAdapter adapter(13, 12);
// intialize BackSeatDriver itself, passing it the driver.
BackSeatDriver robot(&adapter);
// now we can ask our robot to move...
robot.goForward(100); // move forward at 100% speed

is giving robot instructions that will stop the robot after the duration of time passes (defined in milliseconds from the start of the maneuver).

To remain within design goals of the library, the client should aim at not performing any blocking calls or delays itself, as doing so will make BackSeatDriver inaccurate, and will prohibit from effectively integrating other similar libraries. In the world where many things should be moving at once, nothing in the code path seems worthy of a dead pause of the delay, although for simple tasks it sure makes coding easy.


In this example the client uses Sonar sensor to detect objects ahead. If an object is found, the robot turns left (-)45 degrees, and then immediately checks again for distance. If the distance to the objects ahead is farther than the previous reading, it stays on this route and keeps moving. Otherwise it rotates 90 degrees, to now be at +45 degrees to the original direction. If that direction isn't better than the front, it turns for additional 135 degrees, making it a full 180' degrees from the original direction.

This example algorithm is setup in a just a few lines of code using C/C++ style function pointers used as callbacks at the end of each maneuver, but provide for a pretty effective obstacle avoidance strategy (but albeit a random direction).

// Define the two pins used by the two Servos attached to the wheels (expected to be attached
// in an opposite direction to each other
// load specific Adapter for our motors
#include <BackSeatDriver_TwoServoAdapter.h>

// now load the main library
#include <BackSeatDriver.h>

// initialize the adapter with two pins assigned to the two servos
BackSeatDriver_TwoServoAdapter adapter(13, 12);

// intialize BackSeatDriver itself, passing it the driver.
BackSeatDriver robot(&adapter);

void setup()

void loop()
    // The most important check below serves two key purposes:
    //   1. make sure that any existing maneuvering that may be happening should be
    //      finished, and if so stop the robot and execute maneuver's callbacks()
    //   2. avoids doing any instructions until the robot is out of the maneuver.
    //      This could be optional, as many things can be done during the time
    //      robot is maneuvering, perhaps with other arms or sensors.

    if (!bot.isManeuvering()) {

        // this is the default motion

        // check distance to objects ahead
        spaceAhead = detectSpaceAhead();
        if (spaceAhead < 50) { // if under < 50cm start manuevering
            // turn left 45 degrees, and when done call the checkLeft() function.
            robot.turn(-45, &checkLeft);

void checkLeft() {
    int spaceAfterTurn = spaceAhead();
    if (spaceAfterTurn < spaceAhead)
        bot.turn(90, &checkRight);

void checkRight() {
    int spaceAfterTurn = spaceAhead();
    if (spaceAfterTurn < spaceAhead)
        bot.turn(135, NULL);


↳ Keep reading …

12-Step Program for Scaling Web Applications on PostgreSQL

On Tuesday night this week Wanelo hosted a monthly meeting of SFPUG - San Francisco PostgreSQL User Group, and I gave a talk that presented a summary to date of Wanelo's performance journey to today. The presentation ended upo being much longer than I originally anticipated, and went on for an hour and a half. Whoops! With over a dozen questions near the end, it felt good to share the tips and tricks that we learned while scaling our app.

↳ Keep reading …

Detangling Business Logic in Rails Apps with PORO Events and Observers

With any Rails app that evolves along with substantial user growth and active feature development, pretty soon a moment comes when there appears to be a decent amount of tangled logic, AKA "technical debt."

↳ Keep reading …

High Read/Write Performance PostgreSQL 9.2 and Joyent Cloud

At Wanelo we are pretty ardent fans of PostgreSQL database server, but try not to be dogmatic about it. 

I have personally used PostgreSQL since version 7.4, dating back to some time in 2003 or 4. I was always impressed with how easy it was to get PostgreSQL installed on a UNIX system, how quick it was to configure (only two config files to edit), and how simple it was to create and authenticate users.

↳ Keep reading …

The Case for Vertical Sharding

Wanelo's recent surge in popularity rewarded our engineers with a healthy stream of scaling problems to solve.

Among the many performance initiatives launched over the last few weeks, vertical sharding has been the most impactful and interesting so far.

↳ Keep reading …

The Big Switch How We Rebuilt Wanelo from Scratch and Lived to Tell About It

The Wanelo you see today is a completely different website than the one that existed a few months ago. It’s been rewritten and rebuilt from the ground up, as part of a process that took about two months. We thought we’d share the details of what we did and what we learned, in case someone out there ever finds themselves in a similar situation, weighing the risks of either working with a legacy stack or going full steam ahead with a rewrite.

↳ Keep reading …