Go Down

Topic: CALIPER INTERFACE (Read 4940 times) previous topic - next topic

supertechqc

May 24, 2013, 04:57 am Last Edit: Jul 12, 2013, 04:26 am by supertechqc Reason: 1

)

+++++++++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: [Select]

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








robtillaart

#1
May 24, 2013, 10:20 am Last Edit: May 24, 2013, 10:22 am by robtillaart Reason: 1
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?

Rob Tillaart

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

robtillaart

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

Thanks, I can put off my sunglasses ;)

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: [Select]
         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: [Select]

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 ;)

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: [Select]

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()
Rob Tillaart

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

supertechqc

Here is the Youtube video of this working.

http://www.youtube.com/watch?v=nsa_jSll3UM&feature=youtube_gdata

And here is the drawing of the interface circuitry

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

robtillaart

should be something like this.

Code: [Select]

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
}

Rob Tillaart

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

supertechqc

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)!

robtillaart

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

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

Rob Tillaart

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

robtillaart

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?
Rob Tillaart

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

supertechqc

#8
Jul 12, 2013, 04:12 am Last Edit: Jul 12, 2013, 04:23 am by supertechqc Reason: 1
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

robtillaart

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.
Rob Tillaart

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

robtillaart


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 ;)
Rob Tillaart

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

supertechqc

#11
Jul 13, 2013, 03:00 am Last Edit: Jul 13, 2013, 03:09 am by supertechqc Reason: 1
  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:

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

Go Up