CALIPER INTERFACE

)
+++++++++CALIPER DATA INTERFACE++++++++
-----FOOT SWITCH USED TO CAPTURE SINGLE MEASUREMENTS--------
-----LM339 VOLTAGE COMPARATOR FOR ACCURATE TTL---------------
-----CALIPER REGULATED VOLTAGE----------------------------------------
-----NO WEIRD LIBRARIES OR IDE'S TO DOWNLOAD----------------------
-----ALL FUNCTIONS ARE 100% VERIFIED----------------------------------
-----COMPLETE CODE AND SCHEMATIC ARE BELOW---------------------

** Schematic at: Schematic 05212013 Rev B1 | CALIPER DATA INTERFACE supertech… | Flickr**
======= HERE THEY ARE!!! ===========
(Cleaned up and Modified/Tested 05-27-2013)

/*
Caliper Data Output: Updated 05/27/2013
Code and Circuit Compiled by: J. Poston

Special Thanks To:
Forrest M. Mimms III Engineer's Notebook 1st Edition (pg 106)

David Cook's Website on Caliper Data
http://www.robotroom.com/Caliper-Digital-Data-Port-2.html

Rob Tillaart for code cleanup and insight (from the Arduino Forum)
*/


int dataIn = 4;
int clockIn = 2;
const int buttonPin = 5;   
int buttonState =0;        
const int i=10;  
int isin=0;
int isfs=0; 
int index;
unsigned long xData,oData;
long previousMillis = 0;
long interval = 500; 
long previousGetMillis = 0; 
long Timeout = 8; 

void setup()
{
  pinMode(buttonPin, INPUT);     
  digitalWrite(dataIn, 1);
  digitalWrite( clockIn, 1);
  pinMode(dataIn, INPUT); 
  Serial.begin(9600);
  delay(500);
  attachInterrupt(0,getBit,RISING); 
  index =0;
  xData=0;
  oData=999;

 Print_Header();
}
void loop()
{
  buttonState = digitalRead(buttonPin);
  delay(5);
  if (buttonState == HIGH) {     
    if ((index !=0) && (millis() - previousGetMillis > Timeout) ) {
      index=0;
      xData=0;
    };
    if (index >23) {
      if (oData !=xData) {
      
if (isin == 1) //Inches
{ 
  float val = xData * 0.5 /1000;
 if (isfs == 1) 
{val = -val; } 
  
  Serial.println(val, 4);}

else // mm
{  float val = xData / 100.0;
  
  if (isfs == 1) 
{val = -val;}
  Serial.println(val, 2);  
}}
      oData =xData;
      index=0;
      delay(5);
      xData=0;
    }
    if (millis() - previousMillis > interval) {
      previousMillis = millis();
    }}}
    
void getBit(){
  previousGetMillis=millis();
  if(index < 20){
    if(digitalRead(dataIn)==1){
      xData|= 1<<index;
    }}
    
  else {
    if (index==20) 
      isfs=digitalRead(dataIn);
    if (index==23) 
      isin=digitalRead(dataIn);
  };
  index++;  
}

void Print_Header()
{ Serial.println("****************************************************************");
  Serial.println("     Program: Digital Caliper Data SPC  (Running)               ");
  Serial.println("****************************************************************");
}

Capitals is shouting on a forum!, please don't, it is not appreciated by most members.

That said, the code is interesting, especially if you could wrap its core functionality in a library so it can be easy incorporated in another sketch.

which calipers it is tested on?

I shrunk the font so it would not burst your eyeballs when you read it...

Thanks, I can put off my sunglasses :wink:

Any ideas where I can better post the schematic?

Playground, interfacing with hardware (don't know the exact name)

A youtube movie would be great to see it working.

         xData *=5;
          Serial.print(xData/10000);
          Serial.print('.');
          if ((xData % 10000)<1000){
            if ((xData % 10000)<100){
              if ((xData % 10000)<10){
                Serial.print('0');
              };
              Serial.print('0');
            };
            Serial.print('0');
          };
          Serial.println(xData % 10000);

can be simplified by using a float.

float val = xData * 5.0 / 10000;
Serial.print(val, 4);  // means 4 decimals

The setup of your sketch has a minor flaw. You first setup the interrupt and then you initialize the xData, if an interrupt comes in between the two -> gotcha :wink:

I would create a setupCaliper() function that does what the name says. It makes the main setup much easier to read and maintain.
Other functions can be created to. This is how the high level setup/loop could look like if you use functions more extensively.

void setup()
{
  Serial.begin(9600);
  printHeader();

  setupCaliper(datapin);
  setupLed();
  setupButton();
  delay(500);
}

void loop()
{
  if (buttonPressed)
  {
      readCaliper();
      printCaliper();
  }
}

Next step is to make a class Caliper() that have methods like setup() read() and print()

should be something like this.

if (isfs == 1) 
{
  xData = -xData;  // sign
}

if (isin == 1) // is Inch
{ 
  float val = xData * 0.5 /10000;
  Serial.println(val, 4);  // 4 decimal places
}
else // mm
{
  float val = xData / 100;
  Serial.print(val, 2);  // 2 decimal places
}

there is a bug in my code, for mm .
it should be

float val = xData / 100.0; // force a conversion to float.

Thanks... I tried the new code, but it will send out chaotic numbers occasionally.

If there is noise on the line and a bit flips you will always get strange values.

Do you have a pull up resistor on the data/clock lines?

aauutch my ears hurt!

Please adjust this screaming font

There isn't anyone smart enough to code leonardo to interface with calipers.

Think the "biggest problem" is that most people don't have an incentive to do so, although I recall a post of someone who did make it work on an UNO.

If you make it a challenge with a good price there will be enough, I'm sure there will be people smart enough.

check this - http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/ -

what do you think? (please don't shout unless of joy :wink:

Hey supertechqc.

Do you have any pictures of the connections from [+, -, data, clock] to the [arduino] and also [foot switch] to [arduino]. Your schematics are great, its just that I do not have any electrical background and cannot make sense of what goes where. I'd appreciate any pictures that might help dumb it down for me.

Cheers

Sean