Interfacing a Digital Micrometer to a Arduino & VGA Monitor

96,049

54

33

Introduction: Interfacing a Digital Micrometer to a Arduino & VGA Monitor

About: Professionally, I'm an IT Engineer (Executive Level) and Electronics Tech. I'm a Amateur Radio Operator (KK4HFJ). I lived off grid, with Solar (PV), Wind, and veggie oil fueled diesel generator power for 6 yea…

Update: Igaging Origin Series use a Mitutoyo cable and output the Mitutoyo 52 bit datastream. The code and schematics below work with SPC Digimatic Calipers, Micrometers, Dial indicators, and Scales from both companies.

Discuss a variety of manufacturer's data formats and interfacing for all microcontrollers and SPC enabled measuring systems, like scales, micrometers, calipers, dial indicators, and more.

https://groups.yahoo.com/neo/groups/spc_dro/

We had a project that required connection to a digital micrometer with a data output jack. The idea was to connect a microcontroller to the micrometer, to read the measurements and make decisions based on the readings. The micrometers that we used are made by Mitutoyo, and have a funky 52 character data stream in reverse bit order. The microcontroller we chose is the Arduino, and we used a 4D systems uVGA-II to take serial output from the Arduino and display it on a VGA monitor.

Breadboard

male shrouded header to fit mitutoyo cable - https://amzn.to/2SIIeSL

PN2222A - https://amzn.to/2Mk8XEf

(2) 10k Ohm Resistors - https://amzn.to/2YnbCU7

6 pin male header (wires to Arduino) - https://amzn.to/32VdaEf

optional momentary push-button switch - https://amzn.to/2JWBeyS



Major Components:

Mitutoyo 293-335 Coolant Proof LCD Micrometer, Friction Thimble, 0-1"/0-25.4mm Range, 0.001mm/0.00005" Graduation, +/-0.00005" Accuracy, SPC Output

and

Mitutoyo 05CZA662, Digimatic Cable, 40", With Data Switch for Coolant Proof Micrometers

OR

Mitutoyo Absolute LCD Digimatic Indicator ID-C, Calculation Type, Inch, #4-48 UNF Thread, 0.375" Stem Diameter

OR

Mitutoyo 500-171-30 Advanced Onsite Sensor Absolute Scale Digital Caliper, 0-6" Range

OR

Mitutoyo 572-211-20, Horizontal Digimatic Scale Unit, 0 -6" X .0005"/0.01mm, With Output



µVGA-II(SGC) PICASO QVGA/VGA/WVGA Graphics Controller

Arduino Mega or compatible

Protoshield recommended

2 PN2222A transistors
four 10k Ohm resistors
2x5 shrouded header
one momentary pushbutton

Step 1: Mitutoyo Cable Schematic

This is a diagram showing how the Mitutoyo cable is wired. There is a red "data" button on the micrometer end of the cable that we were not using in this application, so we decided to use it as a "menu" button.

Step 2: Connecting the Cable to the Arduino

The Arduino connects to the Mitutoyo cable with a few components. A 2x5 shrouded header that mates to the female plug on the cable, a PN2222A transistor, and two 10k Ohm resistors. One resistor is used with the PN2222A to protect the micrometer (or caliper) from excessive voltage, the other to bias the "menu" button to +5vdc.

I've included datasheets for the PN2222A and drivers for the CH340 based Arduino Nano that we now use.

Step 3: Reading the Mitutoyo Output

The heavy lifting part of the code (thanks to Mark Burmistrak for his modifications from my original), that reads the data stream, reassembles it in correct order and prints a measurement is as follows:

int req = 5; //mic REQ line goes to pin 5 through q1 (arduino high pulls request line low)
int dat = 2; //mic Data line goes to pin 2
int clk = 3; //mic Clock line goes to pin 3
int i = 0;
int j = 0;
int k = 0;
int signCh = 8;
int sign = 0;
int decimal;
float dpp;
int units;

byte mydata[14];
String value_str;
long value_int; //was an int, could not measure over 32mm
float value;

void setup() {

Serial.begin(9600);

pinMode(req, OUTPUT);

pinMode(clk, INPUT_PULLUP);

pinMode(dat, INPUT_PULLUP);

digitalWrite(req,LOW); // set request at high

}

void loop() {

digitalWrite(req, HIGH); // generate set request
for( i = 0; i < 13; i++ ) {
k = 0;
for (j = 0; j < 4; j++) {
while( digitalRead(clk) == LOW) {
} // hold until clock is high
while( digitalRead(clk) == HIGH) {
} // hold until clock is low
bitWrite(k, j, (digitalRead(dat) & 0x1));
}

mydata[i] = k;

}
sign = mydata[4];
value_str = String(mydata[5]) + String(mydata[6]) + String(mydata[7]) + String(mydata[8] + String(mydata[9] + String(mydata[10]))) ;
decimal = mydata[11];
units = mydata[12];

value_int = value_str.toInt();
if (decimal == 0) dpp = 1.0;
if (decimal == 1) dpp = 10.0;
if (decimal == 2) dpp = 100.0;
if (decimal == 3) dpp = 1000.0;
if (decimal == 4) dpp = 10000.0;
if (decimal == 5) dpp = 100000.0;

value = value_int / dpp;

if (sign == 0) {
Serial.println(value,decimal);
}
if (sign == 8) {
Serial.print("-"); Serial.println(value,decimal);
}

digitalWrite(req,LOW);
delay(100);
}

Step 4: A Few More Auxiliary Schematics

There are a couple more external connections that we added. First, a pair of "sample" buttons (foot and finger) for taking sample measurements of 3 points of a gear before averageing and using the final average number (and rejecting if the samples are too far apart). Second, a reset circuit for the uVGA Card.

Step 5: Output to VGA

We used a uVGA-II (SGC) module from 4D to take the serial output of our Arduino, and display it on a typical vga monitor. The code to do this can be seen in the final step of this instructable. A special thanks to Rei Vilo for his assistance in this section - https://github.com/rei-vilo and http://reivilohobbies.weebly.com/

This has been replaced with the uVGA-III.

In your Arduino sketch, when you want to send data to the uvga module, use a statement like this:

uvga("N", value);

where N is the name of the variable on the uvga, and value is a variable containing the value you want passed.

At the end of your sketch (after the closing bracket of void loop) you have the following function:

int uvga(char* x, int y){
delay(50);

Serial3.print("$");

Serial3.print(x);

Serial3.println(y, DEC);

}

I'm using Serial3 on a Mega 2560, but you can use softserial and a UNO.

The code running on the uvga accepts that serial "packet", and puts the value passed into the variable that was passed, where it can then be displayed on the screen. Example code for the uvga is attached. It's a plain text file. You will need 4D's Workshop software and a USB to TTL cable to upload code to the uvga.

Step 6: Complete Code With Measurement Sampling and Vga Output

If you would like to see how we applied this particular solution, we are using it to generate bin numbers for gear sets, based on measurements. Attached is our completed code, which was developed with the assistance of many others from the Arduino, 4D, and Arduinohome forums.

More details are available at http://tech.groups.yahoo.com/group/arduinohome/files/Arduino%20-%20VGA%20-%20Micrometer/

And http://arduinotronics.blogspot.com/2012/03/arduino-to-vga.html

The smaller file is just the code needed to display the raw readings from the micrometer. Divide the variable "num" by 1000 to get output in mm.

Step 7: Now in GFX Mode (4DGL)

We just did a major upgrade to the project. The screen output looks the same, but all the graphics processing has been moved to the uVGA-II. We bought a programming cable from 4D systems, and uploaded the new PmmC file which switches the card from SGC mode (dumb mode) to GFX (co-processor mode). This has greatly sped up the operation of the program. We also integrated a "packet" serial transmission function which sends data to the uVGA-II in serial packets, with a start symbol, a packet ID (designating which variable on the receiving end the data is destined for), and a end of packet symbol). This makes multiple destination data passing very reliable.

Details on this phase of the project can be found at http://4d.websitetoolbox.com/post?id=5858304, and we are grateful for the input from 4DSYSFAN and others.

Make It Real Challenge

Participated in the
Make It Real Challenge

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge
    • Big and Small Contest

      Big and Small Contest

    33 Comments

    0
    RampantParanoia
    RampantParanoia

    Question 2 years ago

    Hi, I'm planning to use this as a basis to read a Mitutoyo 543-271 dial indicator with an Arduino Uno on an automated cam measuring bench. If I'm understanding your code correctly you use the data cable button to trigger a measurement, but I want to trigger a measurement with a signal from the Arduino instead and use a cable without a button (905338). Are you able to advise if the interface circuit and code would work for this or would they need modifying for what I need?

    Thanks for any help you can provide, electronics and coding aren't my strong point!

    0
    jdaniellpz
    jdaniellpz

    Question 2 years ago

    Hello!
    I have been trying to get 1 of the interface between mitutoyo equipment and an arduido but the web page is not working. Could you please let me know if you still have them for sale? If available I would like to get one overnight for testing and 3 more in a the next couple of days.

    0
    majstor76
    majstor76

    Question 3 years ago

    hi, we need 6 axes (6 digital mitutoyo dial indicators) to measure flatnes of flange, can this project do that (or at least show all 6 readouts)? Can it show tolerances? tnx

    0
    FacuR2
    FacuR2

    Question 3 years ago

    Hello! I need to do something like this, but connecting 4 mitutoyo LCD and a load cell. For getting a load - displacement curve for a concrete cylinder test specimen. Is it possible? Can you help me?

    0
    jshmush
    jshmush

    3 years ago

    Just needed to get data off my mitutoyo digimatic to print in arduino. Worked first try, no troubleshooting necessary. This is great, thank you so much.

    0
    VaclavK5
    VaclavK5

    Question 4 years ago

    Very nice, thanks. I plan to use this setup for long term measurements to be taken periodically each day/week or even month using Mitutoyo indicator. I plan to put Arduino to deep sleep between the measurements, it should be easy.

    What about the Mitutoyo indicator? Will it auto power-off or stay on forever, possibly depleting batteries quite soon? And if it does auto power-off, would it wake up once the activity on cable pins happens? Or do I need to press the ON button possibly by a small servo attached to the Arduino?

    0
    MrFixIt87
    MrFixIt87

    Answer 4 years ago

    Most Mitutoyo indicators do not power off automatically and their digimatic absolute instruments usually will run a year or more on a battery before it runs down.

    1
    NicholasE31
    NicholasE31

    5 years ago

    Hi,

    Found that there is a bug (I'm using ID-F150). When going over 32mm with dpp = 3 the output changes to -32mm and heads back down to 0. Changed the value_int to long type and fixed the problem. Int is a signed two's complement so once the leading 1 is zero the polarity flips...

    Cheers

    0
    sspence
    sspence

    Reply 5 years ago

    Excellent. Thank you!

    0
    NicholasE31
    NicholasE31

    Reply 5 years ago

    No worries. My apologies, I forgot to say great instructable!

    1
    aarontulin
    aarontulin

    6 years ago

    Based on the comments this hasn't been an issue for anyone else but the code above wouldn't read the bits correctly for my igaging caliper, mic or dial indicator. My oscilloscope showed the right data coming in but the arduino wasn't reading it correctly.

    The solution turned out to be very easy. I changed the i variable for loop to close on the line after "mydata[i] = k;" vs "value = value_int / dpp;" as it's shown above.

    0
    strider98107
    strider98107

    6 years ago

    Hello,

    Great job. I want to get "continuous" readings from my iGaging IP-54 depth gauge. I have the SPC cable from iGaging. From my noob status it looks like your void section does the measurement, so I wonder if the void section is looped, how many samples per second could I expect to get from this? (using iGaging with Arduino Uno).

    Thank you!

    Bob

    0
    sspence
    sspence

    Reply 6 years ago

    The reading is continuous (void loop be definition is looped) and real time. I have not counted the samples per second, but it's faster than the eye can see.

    0
    sspence
    sspence

    6 years ago

    If you could. greentrust@gmail.com

    0
    sspence
    sspence

    6 years ago

    do you have a spec sheet for both? The website says the new one has the SPC data output. What voltage differences do you see?

    0
    sspence
    sspence

    6 years ago

    The product specs claim it's a digimatic protocol, so it "should" work. I don't have one of those to test.

    0
    ArichardsonWP
    ArichardsonWP

    6 years ago

    Hello,

    Have you finish the code that would allow for multiple calipers to measured at once? Also do you know how to read if the caliper is either positive or negative?

    Thank You

    0
    sspence
    sspence

    Reply 6 years ago

    Yes on both counts. I'll try to get the code posted shortly.

    0
    ArichardsonWP
    ArichardsonWP

    Reply 6 years ago

    Thank you for the reply, I am looking forward to seeing it. Awesome project by the way.