Okay so I have been pulling out my hair with this project.
I have done some more scratching around on the internet and tried understanding the code, but nothing I try works. I found a code on instructables.com that someone used to get the data output from their digital caliper.
I used this code and I am getting a output of 11 bits?? Could this be right?? also The values I am getting is very inconsistent jumping around even though the caliper is set to 0 and not doing anything.
At the moment I am using the caliper with a battery and everything is grounded together. Also I am using the logic step up circuit I posted earlier
WHAT AM I DOING WRONG???
See attached picture of the data I am getting from the digital calipers
This is the code I am using to get the data output from the calipers.
//Simple Digital Calliper Reader
//See http://j44industries.blogspot.com/
// Pin Declarations
int dataIn = 2;
int clockIn = 3;
// 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
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();
}
}