Hacking an Inspection Microscope

Sometimes I need to be able to take photographs of very small things, and the so-called macro mode on my point-and-shoot camera just won’t cut it. And it never hurts to have an inspection scope on hand for tiny soldering jobs, either, though I prefer a simple jeweler’s loupe in one eye for most tasks. So I sent just over $40 off to my close friend Alibaba, and a few weeks later was the proud owner of a halfway usable inspection scope that records stills or video to an SD card.

Unfortunately, it’s only halfway useable because of chintzy interface design and a wobbly mount. So I spent an afternoon, took the microscope apart, and got it under microcontroller control, complete with WiFi and a scripting language. Much better! Now I can make microscope time-lapses, but much more importantly I can take blur-free photos without touching the wiggly rig. It was a fun hack, so I thought I’d share. Read on!

Out of the Box

Nice image, but don’t touch!

The scope, as it arrives, is really fun. The image is just fine and most everything works as advertised. Looking at bugs and flowers was good for a few hours at least. However, all of the small details that make for a pleasant user experience are botched.

For instance, the clearance on the SD card is so tight that you can’t insert or remove it without something thin to press it in, or having very long fingernails. Some of the buttons are hard to reach behind the big focus knob. The menu system, to turn on or off the LED ring light for instance, is horrendous. These are minor quibbles, and for the price I’m totally willing to overlook them.

But the killer, for my purposes, is that the stand is so wobbly that the act of pressing the “OK” button to take a picture blurs whatever image was there. The video mode has a “motion detection” method — it’s always on because the camera wobbles so much that it always thinks the object has just moved. The culprit is the cheesy frame that ends in a thick silicone suction cup that wiggles around like a bowl of jelly. This is not how you design tripods.

There are two possible fixes for the vibration issue. The first is to build a better frame, and that’s something I’ll probably end up doing eventually, because the inspection scope is a useful piece of gear. The other solution is simply to trigger the exposure (and other) buttons without touching the wiggly little beast. Welcome to the Internet of Microscopes!

Hack, Hack, Hack

Opening up the case, the first thing I found was a row of five test points on the key panel, so I soldered some header wires to them to see what’s up. (That was easy!) They’re labelled GND, VCC, KEY, PWR, and VBAT, which doesn’t leave much to the imagination. Four out of the five are labelled correctly.

I’m an analog hacker at heart, and I usually start off with an oscilloscope when poking around unknown signals, but I decided to start off with a logic probe this time, because surely the single KEY line was encoding the five front-panel buttons in some sort of digital code. Imagine my surprise when each button press looked identical on the logic sniffer. Burned again. Back to the trusty oscilloscope.

Five buttons, five voltages

It turns out that the five buttons are tied to five different resistors that serve as the lower half of a voltage divider, and an ADC reads this voltage out to figure out which key was pressed. That explains the five voltage levels on the yellow scope trace.

This is a classic dirty trick and I’ve been waiting for the day when I absolutely had to minimize the number of wires connected to a panel. Who knew that I’d see something hackish like this in an actual product?

The power button is separate and pulls the PWR line (in green on the scope trace, on a 5 V vertical scale) to the VBAT line. A quick test with a 3.3 V power supply convinced me that I could turn the device on and off with a microcontroller’s GPIO. I was also pretty sure that I could connect up five GPIO pins to different resistors and “press” the corresponding button. So I pulled off the panel to measure the individual resistors.

In case you want to replicate this at home, the resistors are 0 Ω, 15 kΩ, 30 kΩ, 46.6 kΩ, and 70 kΩ respectively, and doing a little math on the measured voltages, the pullup resistor on the top of the voltage divider is probably nominally 100 kΩ. Alternatively, if you have a DAC you could just send voltages of 0 V, 400 mV, 750 mV, 975 mV, or 1325 mV to the KEY pin. I soldered up the closest resistors I had in my box, verified that they all worked and called the hardware done.

But what’s up with the VCC line? Something didn’t make sense, because the buttons pulled the voltage down despite being connected to VCC, and the KEY line was pulled high by default. Testing it out, of course VCC was a dead-short to GND and the pull-up resistor was on the KEY line. There was an unpopulated resistor on the keypad panel PCB as well, suggesting that in a previous revision the buttons pulled up, but the manufacturer optimized away a single resistor by using the microcontroller’s internal pullup. It’s either laziness or deliberate sabotage that they didn’t change the test-point silkscreen to match. (Imagine how much fun it would be to connect your test equipment up to “VCC” and GND!)

The Usual Suspects

The rest of the work was just me using my favorite tools for a quick job like this. You might want to use an Arduino or a single ESP8266, but I’ve been playing around with Mecrisp-Stellaris Forth on cheap STM32F103 boards lately, so that’s where I went. I was originally thinking of making a custom remote key panel, so the many GPIO pins would have meant that I wouldn’t have to resort to the ADC-and-resistors trick.

I was already using UART serial for programming and debugging, and decided that a separate key panel was a project in its own, so I cheesed out and put the microscope on the WiFi network. I flashed an ESP8266 with the esp-link WiFi-serial bridge firmware. Voila, remote control. Powering the microcontrollers off of the microscope’s VBAT line (through a switch) makes the whole thing entirely self-contained when I have to move it around the desk.

There were many details that required trial-and-error testing to get right. Different delays are required for button presses in camera mode and in the menu system, for instance. I didn’t optimize these, but made the delay long enough that it always works. The power on and off button only works if held down for longer than 1.5 seconds. It’s quirky. This was all pretty quick to get working with an interactive debugging system like the Forth environment, although I don’t think it would be all that much worse in a compile-and-flash loop like in C or Arduino either.

More guts, just for completeness

There are two cute things that I did in the firmware that are worth mentioning. The KEY line that’s used to detect button presses is only pulled up when the microscope’s power is on, so it can be read by the microcontroller to figure out if the microscope is currently on or off. When the microscope first turns on, it is in video mode, which allows the software to keep track internally of the mode it’s currently in.

Combined, this allows for a single “shoot” command that first verifies that the microscope is on, then switches into camera mode if it’s not already there, and then finally takes a photo. Similarly a “delete” command switches over to preview mode and deletes the last photo, confirming all of the “are you sure?” dialogs automatically. The code is here if you’re interested.

Making it Usable and Then Some

The out-of-the-box menu system is horrible. It requires something like fifteen keypresses to toggle the ring light on or off. Scripting this in the microcontroller makes it a lot more pleasant. Moreover, it’s now possible to set up repetitive exposures to make time-lapses, or film a two-minute video once every ten minutes, or automate essentially anything. I might add a distance sensor to make filming automatic when a PCB is present under the lens, or something silly. I really like the idea of tying these script functionalities to external buttons: a one-press light toggle or bracketed exposure button would be nice, as would a single-button delete.

The world is now my oyster, so expect to see a lot more super-closeup footage in upcoming Hackaday articles. And if you pick up one of these microscopes, don’t hesitate to open it up, solder a handful of resistors in, and take control of it yourself. You’ll probably find it useful enough that you’ll build it a proper stand, but that’s another story.

44 thoughts on “Hacking an Inspection Microscope

  1. Wasn’t sure why you’d want a time-lapse function on the camera until I watched the video – great choice of music (not so sure about the soldering).

    Oh and subtle pop-up text :-)

    1. Brian likes to call that “superliminal advertising”. I actually have a Jolly Wrencher under glass on my bench, and caught the corner of it by accident when setting up the video. Then I thought, why not roll with it? :)

      The soldering was janky. It wasn’t small enough to warrant changing out my largest iron tip, and without solder mask on the PCB, that stuff sticks everywhere. Maybe SOT-23 was a bit of a stretch for that tip. Plus, I was doing it in mid-air to get the focus right. I need a better rig for the microscope now.

      1. I thought your soldering looked fine. I’ve been looking at these microscopes on amazon. Looks like I’ll have to pick one up. The Chinese stuff is usually the most hackable when it’s as cheap as possible. I might try to get something that’s a little more user-friendly out of the box, though. The less I have to hack [i]on[/i] the microscope, the more time I have to hack other things [i]under[/i] the microscope. Thanks for the nice write up.

    1. Meh! You get what you pay for.

      I would expect better if I were subscribing to a magazine. But.. I lived through those days. Live information from the internet is soooo much better than any monthly rag could hope to provide. But… you have to look past the warts.

      1. Re-reading that sounds kind of anglo-centric. By ‘warts’ really only meant the mixing of languages (since a person who reads one might not read the other), not any specific language.

  2. Has anyone ever had a good experience with a suction cup mounted tool?

    I have a Panavice clone with a suction cup base. I bought it when I was in college because at that point in my life I lived in an apartment, moved every year or two and had no place to permanently mount a workbench let alone a bench to mount a vice to.

    Anyway.. this was not a cheap clone, it is a very sturdily built tool that I bought in a brick and motor store years before we had cheap Chinese shops pedaling their goods on the internet. It isn’t exactly a suction cup either, it has a rubber base with a lever that causes the center of the base to collapse upwards to create the suction. Anyway.. even on the best surfaces (not what one generally uses for soldering) it only holds if I wet it and then it only holds strong for a short time before the water dries out.

    One tool is not a trend of course but over the years I have also bought several car accessories which claim to mount to a dashboard or windshield via suction cup. Some were cheap, some were not. None have been acceptably reliable and yes, I’ve tried them in several cars. I would love for such a thing to work as I hate scarring a dashboard with drill holes, glue or even double sticky pads which after years in a hot car will probably never completely release from the plastic, not without something abrasive or caustic enough to take the coloring with it.

    And yet.. there is so much stuff out there being sold with suction cups!

    Thus my original question. has anybody had any GOOD experiences with suction cups???

    1. Tool? Nope. We have a suction-cup hook in the kitchen that keeps dropping our metal colander in the middle of the night. Sounds like people breaking in. When they actually do, we won’t think twice.

      The suction cup that came with GoPros is good. I’ve driven hundreds of miles with one on the hood of a car.

      But for tools? Lead weights, magnets, or bolted down.

  3. Thanks for sharing you experience about the G600.
    Apart from the fun of playing with STM32, is there any specific reason why you did not hookup all the stuff directly to he Wemos ?

    1. Not really. Five GPIOs that can source an arbitrary amount of current? But it looks like the keys are pulled up with a 100k resistor, so that’s well within the ESP8266’s (limited) current-handling capacity.

      Honestly, I added the ESP as an afterthought.

      I would bet that an ESP module could handle it alone. If you build one, send us an email to tips@hackaday.com. It’ll be cuter and smaller than mine!

  4. How is the latency on this setup? Is this thing fast enough for using it to solder in real time while zoomed in?

    I’ve played with a few cheap USB microscopes in the past and they generally had too little working room were so laggy that it gave me a migraine trying to solder with it. If those two things aren’t issues here, this is a truly intriguing hack that I may need to copy!

      1. I don’t notice any lag. It’s straight from the camera to the LCD — no USB or WiFi in the middle. But now that I’m wiggling stuff around on my desk, you’ve made me unsure. It’s certainly reasonably fast, but I don’t know if it’s “instantaneous”. I can’t think of a good measurement rig either…. Maybe and LED strobe and LDR taped to the screen? The lag hasn’t bothered me — yet.

        With these simple gadgets, the magnification depends entirely on the distance to the target, and vice-versa. If you’re going for the claimed “600x” magnification, you’re going to be something like 2 cm from whatever you’re inspecting — not very comfy for soldering. If you’re going for 4x-10x, you get a better working distance, but the little ring light might not cut it anymore.

        There’s definitely an ergonomic issue with having the screen tied to the lens — better would be a remote monitor, but then you’d need a VGA/HDMI/whatever out. (They must make a version like that?)

        I noticed that some versions of the product have a better stand, for 2X the price. I’m going to cobble a stand together, but I’m starting to think the $40 stand would have been money well spent. YMMV.

        1. A lot of those inspection microscopes work as USB cameras, so yo get remote monitor you just need a computer (for most there is no need for drivers in Win10). As such it can be used in timelapses, as the computer decides what and when to save.

        2. It sounds like it actually passes the migraine latency test so it’s probably good enough. I wonder how involved of a project it would be to convert the LCD signals to LVDS, extend them on some twisted pair cable, and convert back to parallel or SPI? This would potentially allow the LCD to be mounted in a more convenient location, instead of stuck where it is.

          Thanks for pointing this little microscope out! It looks like I need to buy one of these and try it out.

      2. I get similar magnification on a Nikon D5300 with some random $20 lens and some extension tubes. I use a 13 inch full HD laptop screen with an HDMI adapter for live output. The latency is not perfect but acceptable. You can see the results on my channel.

    1. Are webcams / digital microscopes really useful for soldering? I wonder because you don’t have a stereo view like with an optical dual microscope (not sure about the name) and so you can’t really see/estimate distances etc. Good optical dual microscopes are sadly not avaible for $40…

      1. Are they good for soldering? Depends. I’ve been using a loupe for the past (fifteen?) years, and so I’m used to no stereo vision, and to burning my eyebrows. I still like the loupe.

        It’s sold as an inspection microscope, and that’s probably about right. But the loupe doesn’t take photos or videos, which is what I really needed — I mostly need this for documentation. And for this very article, I needed an excuse to shoot a time-lapse video. :)

      1. I wouldn’t be too surprised if the processor inside this thing has some video output but it’s disabled in software. I suppose U9 is some form of memory (can’t read whats written on) containing the firmware so dumping would be easy, but without any documentation no chances to analyze/hack…
        (I did not search for this processor but from my experience no chances to get documentation for AppoTech chips, see comment below.)

          1. If you enter 640×480 as the video size in the VLC capture device window then it is a lot happier about it. I’ve tried other various standard resolutions but it only seems to want to do 160×120 or 640×480. Not sure how to convince it to stream the full resolution of the camera.

  5. I have an old CRT TV with ‘analog’ front panel buttons like that, which I use for my various old machines and consoles. Its remote died a long time ago, and the front panel is driving me nuts sometimes – when you try to press one button, it randomly “pushes” an adjancent one instead! So when I try to lower the volume, I end up switching inputs all over the place, and when I try to do that, I end up opening up the setup menu, which stops any further switching unless you go through all of its 6-7 pages :(
    I tried to remove the keypad board and cleaning it, putting small ceramic caps on the output signal, and both (esp. cleaning, first time I opened it I couldn’t see traces through the dusty gray crust) helped for quite a while, but it always comes back. I wonder if the unshielded crappy long wire, that is coming from the keypad to the mainboard across the entire CRT might have to something with it…

  6. Nice article, this thing might be useful one day, especially after the improvements you shared. Thank you!

    Btw, in case anybody wonders, the main IC you can see on the picture is from a company called “AppoTech”. http://www.appotech.com/dp/ Don’t expect to find any datasheet however, i searched for a long time a few months ago for one of their ICs located inside a cheap “action cam”…

  7. I have macro-focused video cameras to to do this. Unscrew the lens part way or otherwise move it out a little more than 1mm. Zoom in and modify to macro and end up with a nice distance to work under. I am very near-sighted so I don’t need any mag till it’s10x.
    One easy to way to figure out how much delay there is is to aim the camera at the monitor if possible. With several frames of feedback you will see delay more or less.

  8. “Who knew that I’d see something hackish like this in an actual product?”

    My Westinghouse dishwasher uses this technique on the cycle selector knob, I think it’s more common that we know.

  9. I recently bought an Adonstar ADSM201 off Ali and I can say its a great bang for your buck scope at $199. Its direct to HDMI (I connect to a PC monitor) = virtually no latency. Its based on a dashcam as far as I can tell so you get video recording, photos etc. The GUI could be better, but I’m really glad I got it. Makes SMD inspection a breeze.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s