Go Down

Topic: [HowTo] Caliper (Wabeco) DRO (Read 101 times) previous topic - next topic

BigDo

Apr 15, 2019, 01:40 pm Last Edit: Apr 15, 2019, 06:55 pm by BigDo
Hi all,

here is my sketch for a caliper DRO. I used a caliper from Wabeco.
Most Chinese calipers should work as well.

My setup and sketch is based on martin's useless and useful creations




Code: [Select]
/* Caliper DRO based on Wabeco caliper
 *  some chinese calipers should work too
 */


#include <LedControl.h>
int i;
int sign;
long value;
float result;
int clockpin = 5; 
int datapin = 6;
unsigned long tempmicros;
LedControl lc = LedControl(4, 2, 3, 1);

void setup() {
  //Serial.begin(115200);
  pinMode(clockpin, INPUT);
  pinMode(datapin, INPUT);
  lc.shutdown(0,false); // turn off power saving, enables display
  lc.setIntensity(0,15); // sets brightness (0~15 possible values)
  lc.clearDisplay(0); // clear screen
}

void loop () {
  while (digitalRead(clockpin)==HIGH) {} //if clock is LOW wait until it turns to HIGH
  tempmicros=micros();
  while (digitalRead(clockpin)==LOW) {} //wait for the end of the HIGH pulse
  if ((micros()-tempmicros)>50) { //if the HIGH pulse was longer than 500 micros we are at the start of a new bit sequence
    decode(); //decode the bit sequence
  }
}

void decode() {
  sign=1;
  value=0;
  for (i=0;i<23;i++) {
    while (digitalRead(clockpin)==HIGH) { } //wait until clock returns to HIGH- the first bit is not needed
    while (digitalRead(clockpin)==LOW) {} //wait until clock returns to LOW
    if (digitalRead(datapin)==LOW) {
      if (i<20) {
        value|= 1<<i;
      }
      if (i==20) {
        sign=-1;
      }
    }
  }

  result=(value*sign)/100.00;   
 //Serial.println(result); //print result with 2 decimals
  static char outputBuffer[20]; // outputBuffer[] likely 2x the size it needs to be.
  dtostrf(result,6, 2, outputBuffer);
  printBuffer(outputBuffer);
   delay(100); //1000
}

void printBuffer(char *outputBuffer) {
int digits2display;
for(int x=0; x<9; x++) {
  if (outputBuffer[x] == '-') {
    digits2display =6;
  }else{
  digits2display =5;
  }
}
    if (value<9999){
    digits2display =digits2display-1;
     lc.clearDisplay(0);
    }
for(int i=0; i<9; i++) {
  if (outputBuffer[i] == '.') {
  i--;
  lc.setChar(0,digits2display-i,outputBuffer[i],1);
  i++; digits2display++;
  } else {
  lc.setChar(0,digits2display-i,outputBuffer[i],0);
}
}
}



pert

Thanks for sharing BigDo! I like the use of the 7 segment display.

Go Up