An increasing number of readers have been asking me to add support for other encoders to my Digital Readout application, especially the “standard” Chinese scales and cheap calipers. Although I’ve been experimenting with the idea for some time but never got around to getting it done. Last weekend, while working on step-by-step build instructions for the MSP430 Launchpad DRO controller, I realized that I was much closer to the solution than I previously realized. The MSP430G2553 microcontroller that ships with the newer version of the Launchpad kit is a very capable chip that should be able to read three or four different scales with no problems. After digging through my and my father’s garages, and a trip to Harbor Freight I was able to round up six different-looking calipers and a BG Micro “Digital Indicator”, so I was ready to start experimenting.
Digital Caliper Basics
|Inner workings of a standard|
Harbor Freight caliper
Before going much further, let’s cover some basics to make sure that everyone is on the same page. Almost all digital calipers and scales use an incremental capacitive transducer to determine their position. In most cases the main scale covers a circuit board that has a special pattern etched on it; inside the main body there is another circuit board with a set of etched strips. By rapidly measuring the capacitance between each strip and the frame PCB, the controller inside the caliper can precisely measure its movement. By knowing how far the transducer has moved from the reference point the scale can then calculate its precise position and display it to the user or send over the wire [to the Launchpad in our case]. There are differences in how the position is encoded and sent over the wire but almost universally these scales use a variant of a synchronous serial protocol. In case iGaging Remote Digital Readout scales the display unit provides the clock; all of the others that I had a chance to test provide their own clock.
From the get-go I realized that making a separate firmware for each type of scale didn’t make sense. Instead, the firmware would need to be able to read different kinds of scales. I considered letting the user configure each input port using jumpers but quickly dropped the idea. If possible, the controller will need to auto-detect the protocol. Alternatively I can write a small app that can configure the inputs from the Android device. It would also be nice to have the ability to use a mix of scales/calipers. In other words the firmware would need to detect the data protocol for each axis individually. Additionally, since the Launchpad has a green and red LED, it would be great to use them for providing some basic feedback to the user. Finally the project should be easy to put together for a person with little or no electronics experience and use readily available components.
|Basic circuit that converts|
1.5V signal from scales
to 3.3V needed for MSP430
The first order of business was to connect the scales to the microcontroller and make sure that it can read the signal. To run at 16MHz, MSP430 Launchpad requires 3.3V power supply. The datasheet states that input threshold voltage min/max is 1.35V and 2.25V respectively at 3V supply. In other words the 1.5V signal coming from the calipers will likely not read as “high”. I first tried powering one of the calipers from 2.5V supply but it promptly let the magic smoke out and died. This was only a minor setback, though, since a voltage level shifter is a basic, easy to build circuit. The idea is to connect the caliper output through a resistor to a NPN transistor as shown in the schematic. This shift the voltage level to 3.3V but will invert the input as well, which can be easily handled in the firmware.
|4-Axis adapter board prototype|
Each scale will require two of such level shifters (input buffers) - one for the clock line and one for the data line. A 4-axis adapter board can be easily build for a few dollars using some parts readily available from any store that carries electronic components. I built mine using eight MP2222A transistors, eight 220 Ohm resistors, and a proto board from Radio Shack.
Any resistor value between about 200 Ohm and a 1/2 KOhm should work. Similarly, any NPN transistor would work as well, since MSP430 maximum input current draw is on the order of 2mA. Please keep in mind that some transistors (such as 3904, for example) have the pins reversed so make sure to connect them in the correct direction. Alternatively the whole board can be replaced with a single “Octal Line Driver” IC or two Op Amps.
|Former USB cable connected to|
a Harbor Freight caliper's main board
Second the scales have to be connected to the adapter board. Initially I tried using the proprietary cables [that came with the BG Micro Digital Indicators] but the connection was horribly unreliable on all but Harbor Freight caliper. After a few hours of wiggling the cable I decided to simply solder four vires to the pads and call it good. To access the pads the calipers had to be taken apart but it proved to be fairly easy. There are four bolts hiding under the label on the backside that can be undone using a miniature Philips screwdriver. Once the front sub-assembly is off, there are four more tiny screws inside, holding the main board to the case. The buttons and LCD display will do their best to scatter around so be prepared to catch them. To keep things consistent with the connections used with iGaging scales in the previous versions of the controller I used a sacrificial USB cable. This way all of my scales use Red-White-Green-Black sequence for Vcc, Data, Clock and Ground respectively.
Finally it was time to connect the adapter board to the Launchpad. To keep the hardware compatible with the current version of the firmware (to make things easier for people using only iGaging scales) I decided to leave the existing pin functions unchanged. Fortunately there were enough unused pins, so this didn’t pose any issues. Since there were two more unused Port 2 pins (market XIN and XOUT), it made sense to use them for the fourth axis. P1.7 would be used to provide the clock to the iGaging scales, so they can be treated by the input pins just like the rest of the scales that provide their own clock. Finally this leaves P1.5 and P1.6 for tachometer, which I’m planning to add in the near future.
With the hardware taken care of it was time to deal with the data protocol, which I will discuss in the next post.