Fun with capacitive touch and low power circuit design

Recently, I built a touch activated LED toy based on the Attiny85V from Microchip (née Atmel). The schematic is shown below




I got the PCBs made from every hobbyist’s favorite PCB manufacturer OSHpark. On the surface, the project seemed pretty simple. It gave me an opportunity to work on touch sensors and learn their functioning and implementation. I decided to go with an external touch sense solution(MTCH102 from Microchip as well), as I had plenty of board space to spare and, the it wouldn’t add much cost to the BOM. Also it would save me a lot of development time as implementing a robust power efficient capacitive touch library could be an interesting project in itself!

when starting with the project I set the following constraints:

  1. Cost < $12 (for qty < 10)
  2. Power (powered from a CR2032, the battery should last at least a month)

The cost target was an easy one, the most expensive component was the Attiny itself at around $2.25, other components were virtually “free” .

Meeting the power target though was a bit challenging. This post is mostly about how I was able to reduce the power consumption, mostly through firmware modifications.

  1. Utilizing the sleep mode was an obvious choice since that could improve the standby time of the device literally by orders of magnitude. I used the following setup to measure sleep current. Vd was the vdrop across the rather large shunt. This rather large shunt worked for me since I was only concerned about the sleep/standby current and the voltage drop across the shunt would be pretty minuscule across the resistor at such low currents (<1 mA).I used a Vichy VC99 DMM and my Rigol Ds1054z (this scope is amazing value for the money!, mine doesn’t play well with USB thumb drives though :( ) to measure and analyse the current draw.


2. on initial measurement through the DMM the current draw seemed be varying quite a bit, this took me down another rabbit hole of how the touch sensor actually functioned. the MTCH102 has a pretty interesting power down mode, and the datasheet doesn’t do it enough justice. I was using the aptly named Low-power mode in my implementation. which basically involved tying down the MTPM, low-power mode selection pin to ground


3. down the rabbit hole we go! It seems that the chip implements a pretty intersting psuedo-random algorithm to scan during the burst mode. the datasheet just calls it the burst scan. The chip sends out random length of pulses to the sense pad. The pulses are always in multiples of 16. And always between one and 10 sets of these 16 pulses are sent out.


one set of pulses

varying pulse lengths
varying pulse lengths


4. This reflected on the current draw was  as well, when the chip would be in burst scan mode the power consumption was up to 1.2mA. the scope capture below shows the Vd (across the 100Ohm shunt) when two sets of pulses were sent out through the sense pin.


5. the only work around for this was to use the smart scheduling mode. This way I could control when the burst scan occurred, instead of every 256 ms i could set it occur say every second or so. I could go this route cut down the power consumption significantly! but then I would have to respin the board :(


6. but wait… the base line power consumption when the MTCH102 in sleep was still kinda high. about 300uA.  a google search later, is stumbled upon this app note about reducing power consumption on the AVR. one of the first things that they had mentioned was to enable the internal pull ups  on un used GPIOs to prevent power drain due to floating gates.  I had three unused GPIOs that were essentially floating, made changes to the code and viola! I was able to shave off ~100uA


7. with sleep mode and implementing the internal  pull ups and disabling the  unused modules I was able to get the average current consumption to under 200uA. a typical CR2032 cell is rated for 240mAh. this would give me an estimated standby time of about 1200 hours (or 50 days). Also the internal resistance of the cell increases as its charge depletes. Also considering the device consumes ~20mA when awake for about two seconds. Assuming the device wakes up once a day, we should theoretically still have enough charge for a run time of over 30 days(240mAh – 0.03mAh- 144mAh = 95.97mAh leftover).

To conclude I think this project was an overall success and met its primary goals. There is some room for optimization and I think the power consumption can still be reduced further, but for now I think I should move on to the next project!

Hiking: Visit to Alamere Falls

Yesterday I visited Alamere Falls, near Bolinas,CA.

We started at the Palomarin Trailhead (there’s plenty of parking there, it being peak season though we had a hard time finding parking)

It’s a rather long hike (8 mi+)but large sections of trail have good tree cover and it was very foggy when we visited. do remember to pack as much water as you can and some energy bars.Note that there’s no clear sign or marking indicating the trail that leads to the waterfall. I suspect that this might be due to the fact that trail is quite dangerous and steep, and the authorities don’t want people to go there. I used the offline maps feature in here maps to find my way.

The way to get there from the trail head is as follows, Follow along the signs for coast trail, then take the Alamere falls trail, the trail length is around ~4.4mi from the trail head to the waterfall.

There are a few lakes on the trail as well, so pack some gear along if you plan on taking a dip.

Location on google maps for Alamere Falls.

Also if you’re driving from the south (through Stinson Beach)there a few scenic spots along the Bolinas lagoon waterfront.

Here are a few pictures from the trip.

Coast trail
Pelican Lake
Coast Trail
Alamere Falls
Bolinas lagoon waterfront.

Pasta sauce hack: How to make creamy tomato pasta the easy way.

It was a lazy Sunday afternoon, and I was craving something that’s tasty, but not too difficult to make and pasta sounded like a good idea. I really love creamy Alfredo sauce, but i had no parmesan cheese on hand. I also like tomato pasta sauce, but when made fresh. I really hate the taste of store bought pasta sauces, they are way too sour and leave a weird aftertaste. But these sauces are super convenient, so I always have them in stock.

So, the only stuff I had on hand was tomato (with garlic and basil) pasta sauce, heavy whipping cream and penne pasta. I cooked the pasta as per the instructions on the box, then drained the pasta. Heated some butter in the pan, added the tomato pasta sauce and while it was about to heat up added some of the heavy cream, garlic powder, dried basil leaves, and Voila!. the result was this awesome creamy, rich bright reddish orange pasta sauce, that was easy to make and tasted awesome(and looked beautiful too). I added some finely chopped cilantro to the sauce too, since I really love the taste of fresh cilantro.


Working on a “secret” project, and fighting feature creep!

I started work on a new design, I have long had a desire to create a “product” from scratch using minimal off-the-shelf stuff. This design should help me achieve that goal, and help me learn project management(albeit on a micro scale! :P). Last year I spent some time on an esp8266 based design, new ideas got added to the design midway and a couple iterations later, i have OSHpark purple “art”. FEATURE CREEP,  as it’s called, its very hard to fight off.

This time i decided to start simple. The design has tight constraints (ultra low power consumption, dimesions) but fewer variables that might get affected by feature creep. I feel, I have mostly been successful to fight it off this time. I wouldn’t tell what the project is just yet, and i haven’t committed it to a public git repo yet(of course, it’ll be OSH). I shall make it public soon :) . I think it’ll be fun, and hopefully I teach myself a few lessons in project management, and how to be persistent and finish my hobby projects!

In the mean time here’s a sneak peek of the schematic! 😀



Quick post: Logitech Mx MASTER Fix

Saw this post on hackaday and decided to work on fixing my own Mx Master which had the infamous scroll wheel issue. I could not toggle between the scroll modes of the mouse. The feature stopped working the very next day i started using the mouse. It seems to be a design issue on logitech’s part. But its a quick and simple fix, check the hackaday post above for more info.



Electronics Inside a Philips Sonicare Electric toothbrush

Today a coworker of mine gave me his old Philips Sonicare toothbrush. He said it had stopped charging and would no longer work. That was a good opportunity for a tear down 😉

Lets see what makes this baby chooch….(As the great man himself said


There’s very little to this device. it seems like there’s just a micro controller running the show, like every other product. (there’s more horsepower in a toothbrush these days than an a 50 year old Supercomputer!) it probably does the following tasks( my guesstimate)

  1. Running the motors
  2. Reading user input via the two push buttons (I accidentally De-soldered one Push button, while trying to De-solder the battery)
  3. Battery charging and discharging
  4. LEDs and Blinkenlights (Coz humans love ’em )



Quick hardware analysis

A quick analysis of the PCB shows a micro controller(PIC16F726 to be precise) . Q1 seems to be a dual P channel MOSFET ( marked as ISC 6981D ). Q2 is marked AO8808A a dual N Channel MOSFET. The MOSFETs formed an H bridge which drives the “Ultrasonic motor” which I plan to get to run soon. then there’s a few sundry(read boring/uninteresting) components which probably are there for over voltage protection, an LDO, Li-Ion battery charger Etc. (High Res Image of the PCB ).

Then there seems to be 6 test Points which are conveniently labelled for easy debugging( or hacking I guess!) I’ll probe those and see what they do probably try out a few common baud rates and see what the Micro spits out. There are plenty of test points on the PCB that should include the programming pins for the micro as well.

That’s pretty much it for the electronics side of things.

Then there are other things like the Motor, A AA size Li-Ion battery, a charging coil. The coil probably forms an air core transformer with the charging dock, but I;m still not clear on how it is rectified back in to DC for charging the battery, with so few components and no bulky capacitors on the PCB.

I’ll probably power up the micro controller and see whats being sent out over the UART. Next on my To-do list would be to get the motor running and after that i would like to check out how the charging subsystem works with the weird air core coil arrangement. The weekend is fast approaching, so this guy should keep me busy for a good part of the weekend.


Special Thanks to Alex for donation :)


Murli’s blog has a new home

Last weekend over thanksgiving, I finally found some time to move over my blog to a custom hosted solution over from the old one. I now have a custom WordPress install(this might change soon, as I’m looking at other options, which are more efficient like jekyll ).  The blog should now be snappier, also i’m planning to add a few bells and whistles on the backend (git server, host some files etc). On the hardware front, I am currently working on the ESP8266 on adding an Epaper display and a few custom sensors. I’m using a rather interesting and firmware framework called SMING, which is an interesting hybrid between the Arduino framework and native GCC. Sming I feel is still rather nascent, but the developers are working hard on refining it. I plan to finish the e paper display interface this week, and then I can go ahead with finishing the project, something that looks more like a product than a quick hack. I’ve had a few stumbling blocks along the way, which i have put them aside for now.

Its been a long time dream of mine to build some thing that look more like a store-bought product than something hacked together. This is proving to be a much tougher and more resource intensive than I expected, but I’m being persistent and have been working on and off on it for a while now. Hopefully I will have something cool to show off soon, and will be richer with interesting experiences on developing a product from scratch. 

Also my Rpi Zero came in this weekend. I played around with it a bit, I’m waiting on some cables to come so I can have a stable setup, the cables from my previous Rpi hack are kinda dodgy and dont seem to work very well, I will post a detailed review on the Zero soon.

Raspberry Pi laptop

Recently, I got a used Atrix 4g lapdock for 30 bucks off of craigslist. It was a really good deal for a device that packs a USB hub, a 10+ inch LCD a keyboard, a trackpad and also a 10000mAh battery. Supply it with a processor and it can be a full fledged laptop computer. My atrix 2 worked fine with the lapdock. I used it a lot for watching youtube videos and for PDFs.

The good thing about the lapdock is that it has everything that is needed to setup a raspberry pi. I had one of the earliest revisions of the raspberry pi which up until now I used as my media file server. And the only was i would interact with it was over SSH since i really hated the mess of wires that would come with setting up the monitor and keyboard for the Pi. The lapdock was a very elegant solution to this problem. it was just a matter of splicing some wires together and some soldering before i would get my very own Rpi Laptop. Here’s the finished product.


If you are looking to make one below are some resources.

Here’s the instructional video from Adafruit that i referred to make this project. do check it out.

Here’s another blogpost which i think managed to do away with the soldering altogether but you might end up spending some extra money. but is more rugged and sturdy than the home-made cable solution.

Here are the cables and stuff that you will need for this project.

1.      Micro USB B Male Female M/F Extension Charging Cable

2.     HDMI 1.4 D type Micro HDMI Male to Micro HDMI Female M/F

3.     HDMI Male to Micro HDMI Female Adapter/Converter

4.     Micro USB cable

You will also need Soldering iron and some heat shrink tubing for the project. So keep that handy.

Do let me know how it goes.

Questions?? Fell free to post them in the comments below!


Teardown of a 13 year old canon digital camera.


canon camera teardown, a set on Flickr.

A couple weeks ago, at work I found a digital camera that was thrown away in the recycle bin, it had a broken LCD and everything else seems to be in good shape. It was a 2.1 Megapixel Shooter so i figured it must really old. On googling I found that it was launched in 2001 and one of the smallest digital cameras of its time. and cost like $600 US! these days you can get a decent DSLR for that price. Check out the review of this device here!

Enough chit-chat, lets get to the real deal. I wanted to take the sucker apart and see the innards and understand its working. The camera is enclosed in a metal enclosure and could easily take a drop or two without taking much damage. Dissaembly was easy as the entire case was held together by philips head screws. The canon engineers were able to cram in a lot of stuff into a relatively tiny case,about the size of a pack of cards. It even had its own Li-Ion battery with a seperate external charger.

I have posted the photos of the teardown on my Flickr account. The pictures have elaborate descriptions feel free to browse through them. Feel free to ask any questions in the comments below! Enjoy!

Restoring the Windows Boot Partition…..

I have a Dual Boot boot system Running Ubuntu 12.04(LTS) and Windows & Home Premium(x64).

The other day i was booted into ubuntu and had to use gparted to partition and format a flash drive to use with my Pogoplug-B01. And i by-mistake formatted the windows boot partition . Oops. I restarted my system and could not  boot into windows! For me Windows is like a necessary Evil . Its where all my games reside! All for the other programming related stuff i use ubuntu. So i needed to get the windows partition up and running.

Also before you go ahead i would recommend you take a backup just in case anything goes wrong by booting into the system by a ubuntu live CD.

This can only be used to repair a system where the boot partition is either formatted or is corrupted. This would not work if the main system partition containing the OS itself is damaged.

Starting Windows Vista Microsoft made the boot partition a separate partition (generally 100MB)from the partition containing the actual OS files.

Step 1 Get the appropriate WIN 7 recovery Image from here.

Step 2 Create the CD/DVD or the USB stick(Skip to Method 2 in this Link )

Step 3 Without the boot sector When you turn on your computer u will get a ‘no Operating system Found’ error . So you will need to set your boot drive to the DVD or the USB drive Depending upon whta media you are using.

Step 4 Once you Boot into the Repair Disk Hit Startup Repair. If that fixes the issue. you are all set! But for me that was not so Easy. I Selected the Command Prompt Option the type in the following commands and hit enter after each command


list disk

select disk (followed by the number of the OS disk; most likely 0)

list partition

select partition (followed by the number of the Boot partition; most likely the 100-200Mb partition)



Step 5 Now again type


list disk

select disk(followed by the number of the OS disk; most likely 0)

list partition

make Sure there’s a star(*) against the selected boot partition

then type format and hit enter. This will format the boot partition to NTFS.

Step 6 Now to repair the boot partition make the boot partition active by repeating the STEP 4

next enter following commands and hit enter after each command.

bootrec /fixmbr

bootrec /fixboot

bootrec /rebuildbcd

Step 7 Now restart the computer with the recovery media plugged in.

now in the recovery options select the ‘Startup Repair’ option. It should b able to fix any other issue with the boot sector and restore it to the optimal state.

Now Restart the computer and this time remember to unplug the media when the system shuts down.

Have Fun.

Let me know how i goes in the comments below! :)

Best of Luck!

These Posts Were really helpful:





select partition (followed by the number of the OS partition; most likely the largest partition)