Working with my friend Pablo Castro, we managed to hack together 8 Indio Picaros and the pumps from PartyRobotics into a machine that serves drinks in a unique way. We presented at the Santiago Mini Maker Faire and it was a hit. We had lots of people asking us to rent or buy the machine. We keep a separate blog for that project and we were written up in Make Magazine.

Use the Force little Indio


Last weekend a friend came over all excited about his new Leap Motion that he just got. We had just two hours, but wanted to do a mini hackathon to get to know his new device. For those of you that don’t know, the Leap Motion is a new cheap human machine interface. It can detect the position of your hands and fingers simply by holding them over the device. It can recognize gestures done merely in the air, not touching anything. It makes possible the sorts of interfaces that you’ve perhaps seen in the movie Minority Report.  It didn’t take too long to come up with a very entertaining if not useless implementation for the brand new toy. I have been (slowly) working on another project which I’ll write about in the future when it’s done. In short, it involves little wooden dolls that they sell in Chile that have a special surprise when you lift them up. They are called Indio Picaros and are probably one of the most politically incorrect things you could think of, but usually get a good laugh. They are hand made by hand in Chile by artisans and each one is different in minor details though having a similar structure.  I have a few of these things mechanized for this other project I am working on, so we thought it would be a doable goal to get the little doll to follow your finger. left, right, up and down.

Major Components

This works by stringing together a bunch of components and it’s glued together with python code. It really was a hack job if I’d ever seen one, but it’s just for fun. I really enjoy doing hacks like this every now and then as it frees me from thinking about future maintainability, testability, readability, proper architecture, and on and on as my day job demands. The Indio doll is mechanically connected to two servo motors via some linkages I put together from various parts I could find at the local hobby store. These are connected to a Pololu servo controller module, which is then interfaced with some buffer transistors to a Raspberry Pi. The buffers were necessary to adapt the 3.3v logic levels of the Raspberry Pi to the 5.0v logic levels used by the Pololu device.  The Raspberry Pi was connected to my local network router as was the laptop we were working on. Unfortunately, we couldn’t find an example of the Leap Motion working plugged directly into the USB ports of a Raspberry Pi, and since we only had two hours, decided to work around that by reading the Leap Motion on a laptop and sending commands to the Raspberry Pi over the network.  I had to adapt the code I had written to control the movements of the Indios to send the command via ethernet instead of directly to the Pololu controller. Fortunately, my years of software experience usually follow me even when doing personal projects, and I had designed the classes that control the Indios with Dependency Injection and an abstraction layer for the Pololu module. Thus, it was fairly easy to write a quick adapter module that allowed the Indio to be used on the laptop and the Raspberry Pi to proxy the the commands to the Pololu controller.

Using Raspberry Pi Serial and GPIO

The Pololu had to be connected to the Raspberry Pi’s serial port pins on the header on the Pi. The Pololu also has some quirk where it won’t work if you don’t open the serial port BEFORE powering it up. I discovered that you could also bring the RST pin low after the serial port was opened and it would work – so I had to make use of a GPIO pin on the Pi’s header and then in software, bring the pin high for a few milliseconds after the serial port had been opened. Another useful thing to know is that the serial port on the Pi is not really usable for talking to external devices out of the box (at least on Wheezy). You need to make a few modifications as outlined here to use it to interface with external components.

On my next trip to the US, I am going to buy some more advanced Pololu products that work via USB to avoid having to use the headers on the Pi and the buffer circuits.

Here is the overall layout along with the pinout of the Pi’s header connector.



I don’t have much code to share about this yet, because the majority of the code is for this other project and I’m not ready to open source it quite yet. It’s all Python which is quickly becoming my favorite language to hack in, partly because it’s got a huge user base, and  there are libraries for doing almost anything you like, including interfacing with the Leap Motion.





Can you tell me temperature brother?

I just had a baby recently, and one of the things that my wife was a bit obsessed with was maintaining the room the correct temperature for the newborn. There are of course some digital thermometers out there made for baby’s room, but they mostly have small digital readouts (nothing that you could see from across the room at a glance or via a baby monitor) and tend be pretty ugly. I thought it would be cool to represent the temperature of the room as a color that could be seen from anywhere in the room, fit with the modern decor of the home and would make a cool conversation piece. I decided that since I had an RGB LED lying around, that I could easy represent 5 grades of temperature without having to pulse width modulate each LED individually; I could just use the Red, Green Blue and the two colors in-between those three that occur when activating any two LEDs simultaneously (Red and Green is Yellow and Green and Blue is Teal).


What would each color mean? Here is what I worked out:


<18C = Baby has icicles dripping from nose : Blue

>=18V < 22C = On the cool side : Teal

>=22C < 26C = Just right : Green

>=26C < 30C = On the toasty side: Yellow

>=30C = Baby’s brain is frying: Red

For the temperature sensor, I had a TMP36. I wrote up a quick test program using Arduino to prove the concept, and it worked well. I didn’t stay with Arduino because it’s big and way over powered for this application. This application called for something cheap and small, but with enough oomph to do some cool effects if I wanted to. I decided on the 12F675 from Microchip. This little 8 pin DIP chip is powerful and even comes with an on board 10 bit A/D converter, which I was going to need to measure the output from the TMP36. It also has a 4Mhz internal oscillator which is useful for reducing part count when you want to keep things small and don’t need precise timing or clock signals.

It took a little bit of hacking for the 33 word instruction set to come back to me (I used PIC 12508 about 15 years ago for a smart light switch I invented), but once it did I was able to get it all working without having to resort to programming in C. Once I got the basic thing working, I thought it looked pretty boring just sitting there with a fixed color, so I wanted to add some fading effects. This meant having to somehow PWM the LEDs to give the effect of lower light output. Unfortunately, these small cheap PICs don’t do hardware PWM. After doing some research, I discovered a technique called BAM (Bit Angle Modulation). Essentially, it modulates the on/off state of the LED according to which bits are turned on in a duty cycle register. I’ll spare the details here, since there are already some good write-ups on this topic and you can see how I implemented it in the code. (I’ve since built another project where I used BAM to modulate the three LEDs independently to create a cool ever color changing lamp).

Once I had it all working like I wanted, I needed a good housing for it. I found a diffused transparent ball meant for a floor lamp and used this as the housing. All of the electronics fit inside this ball, and it has just a thin white cord (iPhone USB charger cable) visible from the outside.

Here are some videos where you can see the ThermoLamp in action:




Here is the schematic for the circuit:


And the finished circuits mounted on a PCB:



You’ll notice two RGB LEDs, I added a second one after the fact to make it brighter during the day, unfortunately  I could only find non-diffused LEDs, so I had to hack the LED a little by covering it with a piece of translucent plastic. If  didn’t cover it, it would have projected 3 colored spots fro inside the white globe instead of making the globe glow nicely.


You can get the code from my github repository. The files are for MPLAB IDE 8 however, you may want to try with the new MPLABX which I will try on my next project that involves a PIC.

Lessons Learned and Room For Improvement

1) Use a diffused RGB LED, otherwise it projects spots on the globe which is suppose to glow.

2) There is an inherent problem with using BAM for linear fading effects – when you cross a duty cycle of 128 on on fade up or fade down, a barely perceptible flicker is produced. This discussion talks all about it, but I didn’t actually bother fixing this since making the fade/up down rate fast enough smooths over the problem.

3) The TMP36 is less than the perfect sensor for this project since it has a wide range (thereby offering a lower precision (10mv per one degree Celsius) and a strange .5V offset that I can’t figure out why exists.The TMP37 does not have this voltage offset and has a narrower range in temperature, representing each degree Celsius with 20mv which means the reading as the A/D converter is less sensitive (roughly 9 steps per degree instead of 5). Unfortunately, I can’t seem to find these sensors where I live, so I stuck with the more widely available TMP36. If you want to build something similar and can get the TMP37, use it and adjust the code accordingly.

4) Use a Voltage regulator or the VREF. I used a power supply with exactly 5V output (iPhone charger), but I tried several other iPhone chargers and some of them output slightly more or less than 5V. This becomes a problem if you don’t use VREF (which I didn’t for simplicity). Though I did not show it on the schematic, you should use a 5V linear regulator if your power supply is not spot on 5V (or you can adjust the ranges for each color to fit your supply). The A/D converter uses VDD as VREF if you don’t turn on VREF, this means that different input voltages (even 10mv plus or minus) will throw off the readings. The other option is to enable VREF and use a 5V Zener diode connected to the VREF pin. You could also use a Zener with a lower value to give you much more sensitivity, for example, the TMP36 will give you 1.5v (500mv (offset) + 1000mv (10mv * 100C)) for 100C. If you use a Zener of 1.5v then you get much more accuracy of the reading (1.5v / 1024) =  0.00146484375 vs (5v/ 1024) = 0.0048828125. Just keep in mind, that if you do any of this, that you will need to adjust the thresholds on each color.

5) Due to not using VREF, I noticed some fluttering back and forth between colors when the tempera rue was on the border of two colors. I suspect that most of this would have disappeared if I would have used TMP37 and a VREF of 2V (for 0-100C). But, since getting the exact parts I need is a challenge here, I had to work around the issue in software. My work around was to sample the temperature only every 30 fade up/down cycles, in hopes the temperate would have stabilized on one side of the other before the next sample. It’s not perfect, but it’s good enough for me to be satisfied with it.

How Inspiration Finds You

I’ve had this blog for a couple of years, but had some difficulty deciding on what topic I wanted to spend the precious little spare time I have writing about. I’ve been buried in enterprise software for the last couple of years after selling my startup, and I find this type of software less than inspiring to write about, not to mention that there are a myriad of blogs already out there on the topic of software in this domain. After several years (maybe even a decade) of being estranged from my childhood love of hacking electronics because of being immersed in exciting/consuming software projects and a couple years of traveling the world, I recently started a new project. A friend of mine needed help making a prototype for an invention he wants to patent, and I thought it sounded like a fun project – these days ‘fun’ has a much higher weighting than lucre. Interestingly, working on this one project rekindled the passion I had for electronics and lead to a bunch of new project ideas, many of which, I have already executed or am currently working on. Since this stuff is fun and really stimulates me, I have decided to start writing about my projects and sharing those that I can with the world. Where else am I going to get to show off my assembly language skills?


Perhaps it’s correct to say that the best way to find inspiration is to do rather than to wait for inspiration to find you. May you also find inspiration and maybe even a head start on your own projects in this blog.

Ye shall know them by their works

HI there, I’m Nathan or N8 for short. I’m a software architect who loves hacking electronics and being outdoors doing cool things like hiking, snowboarding and kitesurfing. My contact information can be found here.

– N8