Go Down

### Topic: Mitutoyo Digimatic SPC (Read 35061 times)previous topic - next topic

#### GoForSmoke

#120
##### Dec 06, 2011, 03:03 pm
What will you do if the measurement is 1.25 or 1.5?
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

#### wildbill

#121
##### Dec 06, 2011, 03:15 pm
Glad to hear it's working. All that business with v1, v2 etc is crying out for arrays, which in fact you already have. Consider replacing my fragment with this:
Code: [Select]
`long num;char buf[7];for(int lp=0;lp<6;lp++)  buf[lp]=mydata[lp+5]+'0';buf[6]=0;num=atol(buf);`
Then you can get rid of the v<n> variables entirely.

#### sspence65

#122
##### Dec 06, 2011, 05:11 pm
GoForSmoke, I'm using round in my formula, and typecasting float to int. I ended up having to use floats for some formulas, but the project is finished and working as expected. It takes a micrometer reading off a set of gears, and generates a part number so the gear matching people can create gear sets.

Thank you one and all for all your help.

grumpy_mike
wildbill
GoForSmoke
giantsfan3
awol
and others who weighed in on this project!

Code: [Select]
`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 2int clk = 3; //mic Clock line goes to pin 3int i = 0; int j = 0; int k = 0;int sign = 0;int decimal;int units;int error = 0;   int staticl;    float mm;   int maxl = 47;    float maxmm = 5.097;   float range = .003;   float jump = .004;byte mydata[14];void setup(){  Serial.begin(19200);  pinMode(req, OUTPUT);  pinMode(clk, INPUT);  pinMode(dat, INPUT);  digitalWrite(clk, HIGH); // enable internal pull ups  digitalWrite(dat, HIGH); // enable internal pull ups  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)); // read data bits, and reverse order )      }      mydata[i] = k;      sign = mydata[4];       decimal = mydata[11];      units = mydata[12];                          }long num;char buf[7];for(int lp=0;lp<6;lp++)  buf[lp]=mydata[lp+5]+'0';buf[6]=0;num=atol(buf);if (units != 0) error=1; if (sign != 0) error=2; if (decimal != 3) error=3; mm = (float)num/1000;float formula = round((((maxmm-(range/2.000))-mm)/jump));int f;f = (int)formula;staticl = maxl-f;if (error != 0){  Serial.print ("error ");  Serial.println (error);}else{    Serial.println(staticl);}    digitalWrite(req,LOW);    error=0;    delay(100); }`
Steve Spence - ET/AT/R&D KK4HFJ

#### GoForSmoke

#123
##### Dec 06, 2011, 09:34 pm
It's okay, as long as it works! May all your bids get the contracts!
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

#### sspence65

#124
##### Dec 06, 2011, 09:44 pm
If you want to see the actual measurement output in mm:

change:

Code: [Select]
`else{    Serial.println(staticl);}`

to

Code: [Select]
`else{    Serial.println(mm, 3);}`

and dump the

Code: [Select]
`float formula = round((((maxmm-(range/2.000))-mm)/jump));int f;f = (int)formula;staticl = maxl-f;`
Steve Spence - ET/AT/R&D KK4HFJ

#### sspence65

#125
##### Dec 06, 2011, 09:48 pm
This is working with my µVGA-II(SGC) - from 4D Systems, and my Speakjet with TTS256, text to speech shield I built. Those are topics for another day, but a talking micrometer is pretty cool.
Steve Spence - ET/AT/R&D KK4HFJ

#### giants_fan3

#126
##### Dec 07, 2011, 03:35 am
@Steve Spence: Congrats for persisting through all the difficulties and getting it finished. I'm interested in testing your code myself when I get a chance in the next couple of weeks.
Since you already have your working code ready in the post above, perhaps you should put it together along with an image of your basic circuit hookup and put it in the Exhibition/Gallery section, or on the Playground.

#### sspence65

#127
##### Dec 07, 2011, 04:54 am
Great idea, thanks.
Steve Spence - ET/AT/R&D KK4HFJ

#### wildbill

#128
##### Dec 07, 2011, 02:51 pm
Before you do, consider cleaning it up a bit - the IDE's autoformat (ctrl T) would help, as would getting rid of some of the surplus blank lines - it'll make it easier for future readers, including yourself.

Personally, I'd also move some of the functionality inside loop into separate functions, such as all of Grumpy Mike's work that does the actual reading of the micrometer.

Finally, you're not that short on space - for the error outputs, how about some more user friendly messages in addition to the codes.

#### sspence65

#129
##### Dec 07, 2011, 03:58 pm
I've made some of those improvements already, and added some more application specific functionality, like printing the gear family on the screen based of size range measured. feature creep ....
Steve Spence - ET/AT/R&D KK4HFJ

#### tlbruns

#130
##### Sep 26, 2014, 08:58 pm
I know this is a really old thread, but since this was the first link I found on the topic. I'm posting this here in case there are any others that would like to use this in the future.

I stripped down the code to the bare essentials and compiled it into a library. Now the user simply has to initialize the interface and then use a single fetch() command to receive data. It's actually my first library (and I'm a mechanical engineer) so I'm sure not everything is done by best practices, but it works and should make it quick and easy for others to use.

https://github.com/tlbruns/Digimatic

#### sspence65

#131
##### Sep 26, 2014, 09:38 pm
First gander at it looks awesome, can't wait to test it. Great job!
Steve Spence - ET/AT/R&D KK4HFJ

#### schluerfrank

#132
##### Jan 07, 2015, 03:43 pm
Hi Steve ,

i am trying to get around the world in 1000+1 (not working) forums, etc. ...
all entries are old and nobody seems to be alive ?!?!?
@ this moment i think about why i am writing this few letters ;-(((

So maybe in 2015 is anybody "on earth" and knows how / where to get
(working) mitutoyo caliper interface stuff ....

Thanks for any living signs ...

Frank

#### jamesklyne

#133
##### Jul 09, 2015, 08:16 pmLast Edit: Jul 09, 2015, 08:30 pm by jamesklyne Reason: fixed pic links
I actually have been testing this with my Arduino Mega 2560 R3 and a Mitutoyo 575-123 guage.  I even managed to find where someone had packaged this into a library with modifications (github).

Unfortunately, neither worked correctly for me right off the bat.  So I had to tinker and modify the code while watching a serial print out of the bits.  I managed to make the library get readings from the gauge, but I had to remove the timeout, which means the program gets stuck in a loop if you turn the gauge off while it's running.

I'll post up what I have.  Hopefully someone can help implement waiting for the clock on a small timer to avoid getting stuck in a loop.

Pics:

https://drive.google.com/file/d/0B--LGPrqJ1QzM1VVMXBKWmdtOUU/edit?usp=docslist_api

https://drive.google.com/file/d/0B--LGPrqJ1QzN0U3T2Zua0ZITTg/edit?usp=docslist_api

#### jamesklyne

#134
##### Jul 10, 2015, 12:01 amLast Edit: Jul 10, 2015, 12:01 am by jamesklyne
Here is a link to the library I modified to work so far:

https://drive.google.com/file/d/0B--LGPrqJ1QzVmo3MFpUc2FQNW8/view?usp=sharing

Go Up