Unable to read digital caliper data with arduino

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.

Actually this forum doesn't allowing me to post images and links as I'm very new here! Pardon me!

Read some other threads. The forum software uses time spent reading to promote you to more privilege pretty quickly.

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.

The tutorial that I had followed most Digital caliper reading with Arduino - YouTube

Other post/duplicate DELETED

Why did you post the same thing twice ?

Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you also take a few moments to [url=https://forum.arduino.cc/index.php?topic=710766.0]Learn How To Use The Forum[/url].

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

SDA is a bidirectional signal. Is your level shifter bidirectional?

Yes it is bidirectional and 3.3v to 5v TTL logic lever shifter!

But then you say

So, can it level shift a 1.5V signal ?

https://www.google.com/amp/s/pylin.com/2017/05/26/reading-digital-caliper-from-arduino/amp/

The caliper/s just dump 'data' (here it is, here it is, . . .)

Looks like, despite the 'SDA' and 'SCL' labels, that the caliper is using 24-bit synchronous serial, not I2C.

I don't suppose you have a two-channel oscilloscope handy.

What chip or components does your 'level shifter' use?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.