Pages: [1]   Go Down
Author Topic: CALIPER INTERFACE  (Read 4429 times)
0 Members and 1 Guest are viewing this topic.
Columbus, GA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Draw It, Build It, Test It, Post It
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


)

+++++++++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:  http://www.flickr.com/photos/johnsfunoutdoors/8799107095/

======= HERE THEY ARE!!!  ===========
(Cleaned up and Modified/Tested 05-27-2013)


Code:
/*
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("****************************************************************");
}







« Last Edit: July 11, 2013, 09:26:29 pm by supertechqc » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

« Last Edit: May 24, 2013, 03:22:46 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I shrunk the font so it would not burst your eyeballs when you read it...
Thanks, I can put off my sunglasses smiley-wink

Quote
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.


Code:
         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.

Code:
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 smiley-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.

Code:
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()
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Columbus, GA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Draw It, Build It, Test It, Post It
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the Youtube video of this working.



And here is the drawing of the interface circuitry

http://www.flickr.com/photos/johnsfunoutdoors/8799107095/
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

should be something like this.

Code:
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
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Columbus, GA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Draw It, Build It, Test It, Post It
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I am going build Marthal's inverted signal amplifier and test out that code for mm only.
That code is short and concise, so I hope I can get it to work.

Here is his project; you replied to it a while back.

https://sites.google.com/site/marthalprojects/home/arduino/arduino-reads-digital-caliper

Goal if it Works: Have two different functions, 1 for inches, and 1 for millimeters... Then to Leonardo for keyboard output to Excel...Then to Statistical Process Control
(Which I have already mastered)... I do measurement analysis everyday with cmm's, calipers, utm, mooney viscosity, rheometer mdr... all kinds of stuff.  Calipers are the fastest... but have to enter manually.  I can't get $600 in the budget for the Mitutoyo caliper data capture system.  $600 for a little plastic box and a wire (robbery)!
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Columbus, GA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Draw It, Build It, Test It, Post It
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There isn't anyone smart enough to code leonardo to interface with calipers.  Technology and skill levels of good coding are vacant.  I am going to go into plc... Real procs... and store all my arduino stuff into the same box as my 12 year old Parallax projects
« Last Edit: July 11, 2013, 09:23:35 pm by supertechqc » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

aauutch my ears hurt!

Please adjust this screaming font

Quote
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.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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 smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Columbus, GA
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Draw It, Build It, Test It, Post It
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

   You caught me before i took the box to the barn...         BLA BLA BLA Ha ha... scared you didn't I!

Ooooo, so,   I hook up tomorrow to my superior circuitree... try on der uno r3.... den, oof toda leonardo she go.

Bye
Bye Neander Lander smiley-eek
« Last Edit: July 12, 2013, 08:09:14 pm by supertechqc » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: