Reading Digital Callipers With An Arduino USB
Reading Digital Callipers With An Arduino USB
Table of Contents
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
Intro: Reading Digital Callipers with an Arduino / USB
How to use an Arduino to read the signal from a set of digital callipers and send the reading over USB.
Why?
This might be useful for accurate position sensing in home made / hacked computer aided manufacture systems. Adds USB functionality to your callipers.
After some experimenting with a multi meter and a jyetech oscilloscope (a very cheap basic oscilloscope that can be bought in kit form for under £40) I found the pins to
be as shown in the diagram.
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
Step 2: Voltages: Logic and Power
The Arduino uses 5V logic but the callipers output 1.5V logic. This is a bit of a bodge and may not always work, really a proper logic level conversion circuit should be
used but the flowing is a simple hack that worked well with my Arduino:
My Arduino changed between logic high and logic low at about 2.5V (this could vary a bit between boards).
Connecting the positive pin on the callipers to the 3.3V supply means when the clock and data pins are connected to the arduino their voltage seems to vary between
3.3V and 1.8V, which is the Arduino reads as logic high and low respectively.
To avoid needing a battery in the callipers the power circuit pictured can be used (remove the button cell). This method relies on using an LED to regulate the supply
voltage for the callipers.
Resistor
About 200Ohm
Capacitor
I used a 10uF which worked well, but there would be no harm in using a larger capacitance. 2V or more rating.
LED
For the LED try to find one which has as close to a 1.6V drop across it as possible.
I used a red LED with a 1.8V drop across it. Red and IR LEDs tend to have low voltage drops across them.
1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, (Screen shows 0.00 mm or 0.000 inches)
1,0,0,0, 1,0,1,1, 1,1,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, (Screen shows 10.00mm)
1,0,0,1, 0,0,1,1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,1,0,0, (Screen shows -1.00mm)
1,0,0,0, 1,1,0,0, 1,0,1,0, 1,1,1,0, 0,0,0,0, 0,0,0,0, (Screen shows 150.00mm)
Interpretation of data:
Note: make sure the callipers are set to mm the inches mode behaves very similarly except the least significant bit is used to show 1/2000ths of an inch.
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
Step 4: Arduino Code
This is a very basic Arduino code that should be compatible with several calliper data protocols.
There are commas in between each value to make it easy to use .CSV files to import the data into spreadsheets.
The main requirement of this code is that the data is read on the falling edge of a clock pulse.
Hopefully this code should mean when you connect your Arduino to the computer and use the serial monitor at 115200 Baud you will get sensible looking binary out.
Trouble shooting:
If the length of the binary strings changes a lot you may have the clock and data pins the wrong way around.
Code:
// 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);
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
time = micros();
}
}
Related Instructables
Comments
12 comments Add Comment
I use the serial monitor part of the arduino software (button next to upload).
It does not need any commands, and even if you have go the wiring wrong you should still get the" ready" message from the code. If you are having
problems with my code try using the Graph example sketch which can be found in the communications section of the examples to test getting data from
the arduino.
J44
I learned quite a bit playing with your script, and one from another forum. My goal was to have the arduino convert the binary to a decimal value. I
could not figure a way to change your script to capture the 1 and 0 (sent via serial.print.) to a string or array. Is there a command so that you can
append a string with bits as they are read in a loop?
Anyways, I now have a script that mostly works; the binary string is truncated properly and converted. I need work and find a way to set the value to
be divided by 1000- so that is shows inchs with a decimal place rather than thousanths of a inch (it now rounds to 1 if divided by 1000). Also, I need
mod it so that it will display negative readings.
void setup(){
pinMode(dataPin, INPUT); //DATA line goes to Arduino digital pin 4
Serial.begin(9600);
delay(500);
//attachInterrupt(0,getBit,FALLING); //CLOCK line goes to Arduino digital pin 2
void loop(){
int i,time;
for(i=2;i<14;i++){ //initialize array of bits to 0
data[i]=0;
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
}
do{time = pulseIn(2, LOW);} //repeatedly get the length of LOW pulses until one is longer than 130uS
while(time < 130);
detachInterrupt(0);
count = 0;
for(i=2;i<14;i++){
gauge = 0; //the following is code for converts least significant bit first binary to decminal, units are thousandths of an inch
factor = 1;
for(i=2; i<14; i++){
gauge += data[i]*factor;
factor = factor*2;
}
Serial.print("Time (sec):");
sec = millis();
Serial.print(sec/1000);
Serial.print(" Inches:");
Serial.print(gauge);
delay(1000);
Serial.println();
}
void getBit(){
char sample = 0; //variable used for "triple sampling"
if(digitalRead(dataPin) == HIGH) //here the dataPin is checked three times for a HIGH value.
sample++;
if(digitalRead(dataPin) == HIGH)
sample++;
if(digitalRead(dataPin) == HIGH)
sample++;
if(sample > 1) //if the pin was HIGH at least twice, a 1 is recorded
data[count] = 1;
count++; //increment count so main() knows when the entire string of bits is ready
}
int dataIn = 3;
int clockIn = 2;
void setup(){
digitalWrite(dataIn, 1);
digitalWrite( clockIn, 1);
pinMode(dataIn, INPUT); //DATA line goes to Arduino digital pin 4
pinMode(clockIn, INPUT);
Serial.begin(9600);
delay(500);
attachInterrupt(0,getBit,RISING); //CLOCK line goes to Arduino digital pin 2 ?????
index =0;
xData=0;
oData=999;
}
void loop(){
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
//????
if ((index !=0) && (millis() - previousGetMillis > Timeout) ) {
index=0;
xData=0;
};
//??
if (index >23) {
if (oData !=xData) {
if (isfs==1)
Serial.print('-');
Serial.print(xData/100);
Serial.print('.');
if ((xData % 100)<10) //?0
Serial.print('0');
Serial.println(xData % 100);
};
}; //if ???
oData =xData;
index=0;
xData=0;
};
void getBit(){
previousGetMillis=millis();
if(index < 20){
if(digitalRead(dataIn)==1){
xData|= 1<<index;
};
} else {
if (index==20) //?21????? -
isfs=digitalRead(dataIn);
};
index++;
}
Sadly I do not have my arduinos at hand, but when I do I will try this code out.
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
dp says: Nov 22, 2010. 11:07 PM REPLY
I'm seeing this as the basics of a linear encoder setup for motion control; i.e. x,y,z machines. Possible?
int dataIn = 3;
int clockIn = 2;
void setup(){
digitalWrite(dataIn, 1);
digitalWrite( clockIn, 1);
pinMode(dataIn, INPUT); //DATA line goes to Arduino digital pin 4
pinMode(clockIn, INPUT);
Serial.begin(9600);
delay(500);
attachInterrupt(0,getBit,RISING); //CLOCK line goes to Arduino digital pin 2 ?????
index =0;
xData=0;
oData=999;
}
void loop(){
//????
if ((index !=0) && (millis() - previousGetMillis > Timeout) ) {
index=0;
xData=0;
};
//??
if (index >23) {
if (oData !=xData) {
if (isfs==1)
Serial.print('-');
Serial.print(xData/100);
Serial.print('.');
if ((xData % 100)<10) //?0
Serial.print('0');
Serial.println(xData % 100);
};
}; //if ???
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/
oData =xData;
index=0;
xData=0;
};
void getBit(){
previousGetMillis=millis();
if(index < 20){
if(digitalRead(dataIn)==1){
xData|= 1<
};
} else {
if (index==20) //?21????? -
isfs=digitalRead(dataIn);
};
index++;
}
http://www.instructables.com/id/Reading-Digital-Callipers-with-an-Arduino-USB/