MetalworkingFun Forum
Reading Digital caliper with Arduino - Printable Version

+- MetalworkingFun Forum (http://www.metalworkingfun.com)
+-- Forum: Machining (http://www.metalworkingfun.com/forum-5.html)
+--- Forum: Metrology (http://www.metalworkingfun.com/forum-33.html)
+--- Thread: Reading Digital caliper with Arduino (/thread-2564.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16


RE: Reading Digital caliper with Arduino - EdK - 03-08-2015

Chuck,

What's the model number of your HF digital caliper that your working with? I have a HF digital caliper also and have an Aruino Uno board on the way from Digi-Key. I'll hook it up to my oscilloscope and see what's going on.

Ed


RE: Reading Digital caliper with Arduino - chucketn - 03-09-2015

No model # listed. Brand name is Pittsburg, 4". Purchased at HF on sale last year.

Chuck


RE: Reading Digital caliper with Arduino - chucketn - 03-09-2015

(03-08-2015, 04:23 PM)arvidj Wrote:
(03-08-2015, 07:40 AM)chucketn Wrote: I'm using a HF cheap scale and an Arduino Uno. I am trying to get a display on the Serial Monitor of the Arduino IDE.
I am using the hookup and schematic from here:
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/

The sketch displays only one 0, but the caliper is powered and working using the led and resistor circuit shown there. I think the code listed there is for a different protocol.

I am not, nor do I pretend to be, a programmer and I did not stay at a Holiday Inn last night...

Chuck

Looking at these two pages ...

http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/step3/The-Data-Protocol/

http://www.yuriystoys.com/2013/07/chinese-caliper-data-format.html

suggest that the instructables code is expecting to see the information protocol Yuri found coming from his HF calipers.

This leads me to believe that either (a) the level shifting bodge [his definition, not mine] from the instructables is not "level shifting" the inputs enough for your Arduino to read them or (b) the protocol being sent by your HF calipers is different than that sent by the instructables and Yuri's calipers.

To test (a) I would look thru the instructables code and see if the inputs are changing. Something like this might do it ... [note that I have note validated that this will even compile ... just that it looks nice :-}]

// Pin Declarations

int dataIn = 11;
int clockIn = 12;

void setup() {
  // Pin Set Up
  pinMode(dataIn, INPUT);     
  pinMode(clockIn, INPUT);  

  Serial.begin(115200);
  Serial.println("Ready: ");
}

void loop(){

  Serial.print("clockInValue = ");
  Serial.println(digitalRead(clockIn));
  Serial.print("dataInValue = ");
  Serial.print(digitalRead(dataIn));
}

After you validate that the inputs are changing ... or not ... we can look at the next steps.

Arvid

Arvid, the code you posted gives all 1's for both outputs, suggesting the level shift is needed.

Chuck


RE: Reading Digital caliper with Arduino - chucketn - 03-09-2015

I ran Arvid's code for a few minutes, and an occasional zero shows up in each output, but no discernible pattern.

Chuck


RE: Reading Digital caliper with Arduino - arvidj - 03-09-2015

(03-09-2015, 06:00 AM)chucketn Wrote: I ran Arvid's code for a few minutes, and an occasional zero shows up in each output, but no discernible pattern.

Chuck

That suggests to me that the inputs are not changing. I would expect a random pattern of ones and zeros, especially on the clock line which appears to be high ... or 1 ... for relatively long periods of time ... possibly a full millisecond or more ... and will then go low ... or 0 ... for parts of a millisecond 24 times ... then go high again for a relatively long period.

When you say "occasional", I am assuming that is a zero no more than once or twice a second, which I would attribute to noise.

Another test would be to add the highlighted line of code to the original program: 

if (lastClock == 1 && clock == 0){
    out = digitalRead(dataIn)+digitalRead(dataIn)+digitalRead(dataIn); // Tripple sampling to remove glitches
    Serial.println(micros());



his will tell you how often the program detects a usable clock transition and therefore how often it is trying to read the information that is on the data line.

It should follow the patter presented earlier and is shown in the clock diagram at the top of ... http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/step3/The-Data-Protocol/ ...

Arvid


RE: Reading Digital caliper with Arduino - chucketn - 03-09-2015

I think part of my problem is not using a data level converter on the clock and data inputs to the Arduino.
Where should I put the code, in the loop?

Chuck


RE: Reading Digital caliper with Arduino - chucketn - 03-09-2015

I get a compile error adding that bit of code...

Chuck


RE: Reading Digital caliper with Arduino - arvidj - 03-09-2015

(03-09-2015, 10:52 AM)chucketn Wrote: I get a compile error adding that bit of code...

Chuck

The recommendation was "to add the highlighted line of code to the original program", not "this is the entire program". Sorry about the confusion.

This would be the original program with the line added ...

//Simple Digital Calliper Reader

//See http://j44industries.blogspot.com/

// Pin Declarations
int dataIn = 11;
int clockIn = 12;

// Variables
int clock = 1;
int lastClock = 1;
unsigned long time = 0;
unsigned long timeStart = 0;
int out = 0;


void setup() {
  // Pin Set Up
  pinMode(dataIn, INPUT);     
  pinMode(clockIn, INPUT);  


  Serial.begin(115200);
  Serial.println("Ready: ");
}


void loop(){

  lastClock = clock;
  clock = digitalRead(clockIn);

  if (lastClock == 1 && clock == 0){
    out = digitalRead(dataIn)+digitalRead(dataIn)+digitalRead(dataIn); // Tripple sampling to remove glitches
    Serial.println(micros());

    if((micros() - time) > 800){
      Serial.println(" ");
    }
    else if((micros() - time) > 400){
      Serial.print("  ");
    }

    if (out > 1){
      Serial.print("1");
    }
    else{
      Serial.print("0");
    }
    Serial.print(",");
    time = micros();
  }
}

Give it another try and see what comes happens.

And I do agree with your assessment of the existing "level converter" as even the author of the instructable says "it is a bit of a bodge". I would not think that it would be a good long term solution ... may not even be a short term solution, depending on the individual IC that is being used ... and would seem to be very susceptible to noise in all cases.

  


RE: Reading Digital caliper with Arduino - chucketn - 03-09-2015

I have tried adding a level shifting circuit to the data and clock lines. Output per above code went to all zeros.


RE: Reading Digital caliper with Arduino - arvidj - 03-09-2015

Much better level shifter.

Now run the modified original code and lets see what kind of timing we get on the clock transitions.

Note also that we can take this off-line if this debugging session is bothering others.