Hello.
I am a beginner at Arduino. and I am trying to interface Arduino with a digital caliper. according to some tutorials available over the internet, I've gathered information to initiate the project.
Digital calipers are having 2 data outputs as SCL and SDA.
The logic level of vernier 1.5V is not the same as the Arduino 5V logic level. To compensate for that I've used logic level shifter as a mediator. And to eliminate the battery of the Arduino I've used DC to DC buck converter set at 1.5V directly connected to vernier Vin and GND pins.
Low Voltage side pins are connected to the caliper side pins and high voltage pins are connected to the Arduino side pins. Here, is my code
#define CLOCK_PIN 5
#define DATA_PIN 6
// define USEHW in above header for hw I2C version
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Ready");
pinMode(CLOCK_PIN, INPUT);
pinMode(DATA_PIN, INPUT);
}
char buf[20];
unsigned long tmpTime;
int sign;
int inches;
long value;
float result;
bool mm = true; //define mm to false if you want inces values
void loop()
{
while(digitalRead(CLOCK_PIN)==LOW) {}
tmpTime=micros();
while(digitalRead(CLOCK_PIN)==HIGH) {}
if((micros()-tmpTime)<500) return;
readCaliper();
Serial.println(result);
delay(1000);
}
void readCaliper()
{
sign=1;
value=0;
inches=0;
for(int i=0;i<24;i++) {
while(digitalRead(CLOCK_PIN)==LOW) {}
while(digitalRead(CLOCK_PIN)==HIGH) {}
if(digitalRead(DATA_PIN)==HIGH) {
if(i<20) value|=(1<<i);
if(i==20) sign=-1;
if(i==23) inches=1; // doesn't work with my caliper, always returns inches
}
}
if(mm)
{
result=(value*sign)/100.0;
}
else
{
result=(value*sign)/(inches?2000.0:100.0); //We map the values for inches, define mm to false if you want inces values
}
}
Nothing appears on the serial monitor while Arduino power pins are connected to the TTL shifter but when I disconnect the pins it shows any random values but not on time and real. Help me to correct my steps.
Welcome! From your schematic, oops not there. I will take a SWAG: Per the I2C specification the SCL and SDA are open drain (collector) outputs and require a pull up resistor. Try something in the 3.5K range as pull ups to the 1.5V, which is also connected to the low voltage side of the level converter. Be sure the grounds are connected and give it a try.
Hello.
I am a beginner at Arduino. and I am trying to interface Arduino with a digital caliper. according to some tutorials available over the internet, I've gathered information to initiate the project.
Digital calipers are having 2 data outputs as SCL and SDA.
And this is the internal PCB of the caliper I have.
The logic level of vernier 1.5V is not the same as the Arduino 5V logic level. To compensate for that I've used logic level shifter as a mediator. And to eliminate the battery of the Arduino I've used DC to DC buck converter set at 1.5V directly connected to vernier Vin and GND pins.
Low Voltage side pins are connected to the caliper side pins and high voltage pins are connected to the Arduino side pins. Here, is my code
#define CLOCK_PIN 5
#define DATA_PIN 6
// define USEHW in above header for hw I2C version
void setup()
{
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Ready");
pinMode(CLOCK_PIN, INPUT);
pinMode(DATA_PIN, INPUT);
}
char buf[20];
unsigned long tmpTime;
int sign;
int inches;
long value;
float result;
bool mm = true; //define mm to false if you want inces values
void loop()
{
while(digitalRead(CLOCK_PIN)==LOW) {}
tmpTime=micros();
while(digitalRead(CLOCK_PIN)==HIGH) {}
if((micros()-tmpTime)<500) return;
readCaliper();
Serial.println(result);
delay(1000);
}
void readCaliper()
{
sign=1;
value=0;
inches=0;
for(int i=0;i<24;i++) {
while(digitalRead(CLOCK_PIN)==LOW) {}
while(digitalRead(CLOCK_PIN)==HIGH) {}
if(digitalRead(DATA_PIN)==HIGH) {
if(i<20) value|=(1<<i);
if(i==20) sign=-1;
if(i==23) inches=1; // doesn't work with my caliper, always returns inches
}
}
if(mm)
{
result=(value*sign)/100.0;
}
else
{
result=(value*sign)/(inches?2000.0:100.0); //We map the values for inches, define mm to false if you want inces values
}
}
Nothing appears on the serial monitor while Arduino power pins are connected to the TTL shifter but when I disconnect the pins it shows any random values but not on time and real. Help me to correct my steps.