User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

interface with digital calipers

Sat Sep 12, 2015 10:25 pm

Hello,
I've done a fair bit of reading and researching on this but haven't really come up with a definitive answer.
I have a small lathe and would like to put DRO's on it but they are expensive. On the old google and in the walls of this forum I have read about folks connecting and reading data from cheap digital callipers. The 150mm ones can be had for as little as £3.50 so this is a very inviting idea.
However most folk seem to read them with an Arduino and thus this is do able but I haven't read about anyone using a Raspberry Pi direct.
Does anyone know if this is possible (I'm guessing it is) and if it is any info / links etc.
I would want three axis and ideally no Arduino. Not that I dislike Arduinos but it adds another level of complexity and I'm not as familiar with em as the RPI (and I'm no expert in the RPI) .

A second question would be can these digital calliper be joined somehow. A 150mm is £3 ish but a 300mm or 400mm rises steeply in costs. Would it be possible to cut the scale part off one calliper and refit it to the tail of another and thus get a 300mm for £6?
Any hints or comments ? Thanks for reading....

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: Korea

Re: interface with digital calipers

Sun Sep 13, 2015 12:02 am

If you can find a good tutorial about doing it with Arduino you should be able to make it work on a Pi.

You have to remember that the Pi GPIOs can only accept 3.3V, and you might have to rewrite the software, but it should be quite easy.

Extending the length of the sensor would be hard, the sensor must be physically the length that you want. Splicing two sensors might be possible, but they might glitch at the joint.

User avatar
Douglas6
Posts: 4371
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: interface with digital calipers

Sun Sep 13, 2015 1:00 am

If it were easy to splice two inexpensive devices to work the same as one expensive one, the manufacturer would have probably noticed.

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Sun Sep 13, 2015 1:06 am

Thanks for the reply. You've hit two problems on the head though...
"A good tutorial with the Arduino"- I haven't found one with enough details yet
"It should be easy to convert" - I agree it may indeed be easy for someone but not for me :)

The hardware is obviously very different between RPI and Arduino so I'm not even sure the RPi would be able to decode three axis on the fly and maintain timing etc etc.. I'm thinking it should be able to but as it's not really a real time thing I'm not sure...

I also often use the premise if no one has done it before, am I really that creative or is there a reason? I suspect (and often prove) the latter :)

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Sun Sep 13, 2015 1:17 am

Douglas6 wrote:If it were easy to splice two inexpensive devices to work the same as one expensive one, the manufacturer would have probably noticed.
Yep I would totally agree but still I wonder what the differences are.
If you look at these pics
https://www.flickr.com/photos/[email protected]/5227386500/

The track appears to be a simple PCB and the device has no way of knowing how long it is as it only capacitive couples with the track immediately below.
I also think you may get a glitch at the joint but if you know where that is or how to identify it then this could be factored in to the displayed readings...

ghp
Posts: 1170
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: interface with digital calipers

Sun Sep 13, 2015 6:25 am

Hello,
the tutorials about arduino and using calipers are quite good.
http://www.shumatech.com/support/chinese_scales.htm
Will be a challenge to do this with raspberry, as timing is critical. Microcontrollers are designed to handle this.
Regards,
Gerhard

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Sun Sep 13, 2015 2:16 pm

yep that's what I'm worried about but haven't enough knowledge to be definitive...

I had seen that tutorial but really I was hoping for a complete project with a software example I could try and figure out...

User avatar
scruss
Posts: 1731
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: interface with digital calipers

Sun Sep 13, 2015 4:03 pm

Complete example: Arduino reads digital caliper
Cable for most of these calipers: Cable, DRO Mini-DIN 1990 - LittleMachineShop.com

All of these calipers only return readings relative to the last zero reading. That's by design; all metrology is relative!
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Thu Sep 17, 2015 8:14 pm

Thanks for the link. I guess I'm going to have to buy a few and play then.

User avatar
joan
Posts: 13464
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: interface with digital calipers

Fri Oct 02, 2015 10:31 pm

The hardest part so far is connecting wires to the caliper edge connectors. I ended up soldering directly to the tracks.
calipers.png
calipers.png (44.39 KiB) Viewed 4359 times
The clock line is connected to sclk, data to mosi.

The signal looks clean enough. The LCD display shows 2.75 mm.

The Pi shouldn't have any problems decoding those signals. I'll probably write some code to make sure.

User avatar
joan
Posts: 13464
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: interface with digital calipers

Sat Oct 03, 2015 12:35 pm

As expected there is no problem reading the calipers.

The data format for my calipers appears to be different to others I have seen on the www. The software must have been updated.

24 bits are transmitted for each reading. The 24 bits take roughly 10 ms or about 400 µs per bit.

The readings are repeated 8 times per second.

Data is transmitted least significant bit first, bit 0 to bit 23.

If bit 23 is set the reading is inches rather than millimetres.

If bit 20 is set the reading is negative.

Bits 0-19 contain the reading.

The reading is in 2 thousandths for inches and in hundredths for millimetres.

The readings are sent continuously while the calipers are powered (even if the LCD display is off).

I boosted the data and clock lines from 1.5V to 3.3V using transistors to feed into the Pi. This resulted in the signals being inverted which is reflected in the code.
calliper.jpg
calliper.jpg (50.75 KiB) Viewed 4310 times

Code: Select all

#!/usr/bin/env python

# caliper.py
# 2015-10-03
# Public Domain

import time

import pigpio

CLOCK=21
DATA=20

g_level=0
g_reading=0
g_bits=0

def show(bits, value):

   inch = value & (1<<23)
   minus = value & (1<<20)

   value = value & 0xfffff

   if inch:
      reading = value / 2000.0
      units = "in"
   else:
      reading = value / 100.0
      units = "mm"

   if minus:
      sign = "-"
   else:
      sign = ""

   print("{} {:.3f} {}".format(sign, reading, units))

def cbf(g, l, t):
   global g_level, g_reading, g_bits
   if g == DATA:
      if l == 0:
         g_level = 1
      else:
         g_level = 0
   elif g == CLOCK:
      if l == pigpio.TIMEOUT:
         if g_bits > 10:
            show(g_bits, g_reading)
            g_reading=0
            g_bits=0
      elif l == 0:
          g_reading = g_reading | (g_level<<g_bits)
          g_bits += 1

pi = pigpio.pi()

pi.set_mode(CLOCK, pigpio.INPUT)
pi.set_mode(DATA, pigpio.INPUT)

cb1 = pi.callback(DATA, pigpio.EITHER_EDGE, cbf)
cb2 = pi.callback(CLOCK, pigpio.EITHER_EDGE, cbf)
pi.set_watchdog(CLOCK, 20) # 20 ms reading timeout

time.sleep(120)

cb2.cancel()
cb1.cancel()
pi.stop()

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Mon Oct 12, 2015 12:37 pm

Thanks for that, Perfect bit of investigation work..
I would have replied sooner and offered my thanks but somehow I got locked out of this here forum. Still I'm back and giving thanks...

Now I'll definitely have to buy some and see if I can link them together multiple 300mm ones for a couple of £ each sounds too good to be true though..

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Mon Oct 12, 2015 12:40 pm

Had another one of them thoughts. Would the PI be able to handle three axis then ?
Do the readers offer any sort of buffering ? If someone moved the scale too fast would it miss a few steps or catch up on next read ?
Thanks...

User avatar
joan
Posts: 13464
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: interface with digital calipers

Mon Oct 12, 2015 1:51 pm

perfo wrote:Had another one of them thoughts. Would the PI be able to handle three axis then ?
Do the readers offer any sort of buffering ? If someone moved the scale too fast would it miss a few steps or catch up on next read ?
Thanks...
The Pi would have no problem reading 3 sensors simultaneously. The one I used had a much slower data rate (about 10 times slower than some reported models) but even so the Pi could cope.

On my callipers I could not move to fast. The calliper software read correctly even though the output and LCD display might lag by a few fractions of a second.

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Mon Oct 12, 2015 7:42 pm

If the axis is moved quick the display on the caliper lags but then catches up ? Is that what you found? What about the PI though? If i'm understanding it right the caliper sends out a relative position from some arbitrary start point and thus even if the PI missed a load of data then it would still get the correct reading the next time it managed a correct read ?

User avatar
joan
Posts: 13464
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: interface with digital calipers

Mon Oct 12, 2015 8:08 pm

perfo wrote:If the axis is moved quick the display on the caliper lags but then catches up ? Is that what you found? What about the PI though? If i'm understanding it right the caliper sends out a relative position from some arbitrary start point and thus even if the PI missed a load of data then it would still get the correct reading the next time it managed a correct read ?
Yes, that is what happened with my device. The caliper software caught up with the caliper hardware. The caliper gets the correct reading but there is lag if you move fast. I had no bad reads, the protocol has no checksum or similar to detect bad reads, however my eyes/software saw no incorrect data.

User avatar
perfo
Posts: 65
Joined: Mon Jan 30, 2012 2:42 am

Re: interface with digital calipers

Tue Oct 13, 2015 12:55 pm

Thanks good to know....

ando
Posts: 5
Joined: Fri Oct 16, 2015 6:38 pm

Re: interface with digital calipers

Sat Oct 17, 2015 5:03 pm

Hello Joan,

I am also trying to interface with the caliper. I'm an extreme beginner with the raspberry pi and I tried running your code on python 2 - nothing seems to be happening. The program seems to be executing, but the printouts are not coming up. Are there things that I need to install for your program to work?

I've managed to replicate the wave forms that you were seeing using piscope, but that's as far as i got.

ando
Posts: 5
Joined: Fri Oct 16, 2015 6:38 pm

Re: interface with digital calipers

Sat Oct 17, 2015 11:21 pm

joan wrote:As expected there is no problem reading the calipers.

The data format for my calipers appears to be different to others I have seen on the www. The software must have been updated.

24 bits are transmitted for each reading. The 24 bits take roughly 10 ms or about 400 µs per bit.

The readings are repeated 8 times per second.

Data is transmitted least significant bit first, bit 0 to bit 23.

If bit 23 is set the reading is inches rather than millimetres.

If bit 20 is set the reading is negative.

Bits 0-19 contain the reading.

The reading is in 2 thousandths for inches and in hundredths for millimetres.

The readings are sent continuously while the calipers are powered (even if the LCD display is off).

I boosted the data and clock lines from 1.5V to 3.3V using transistors to feed into the Pi. This resulted in the signals being inverted which is reflected in the code.
calliper.jpg

Code: Select all

#!/usr/bin/env python

# caliper.py
# 2015-10-03
# Public Domain

import time

import pigpio

CLOCK=21
DATA=20

g_level=0
g_reading=0
g_bits=0

def show(bits, value):

   inch = value & (1<<23)
   minus = value & (1<<20)

   value = value & 0xfffff

   if inch:
      reading = value / 2000.0
      units = "in"
   else:
      reading = value / 100.0
      units = "mm"

   if minus:
      sign = "-"
   else:
      sign = ""

   print("{} {:.3f} {}".format(sign, reading, units))

def cbf(g, l, t):
   global g_level, g_reading, g_bits
   if g == DATA:
      if l == 0:
         g_level = 1
      else:
         g_level = 0
   elif g == CLOCK:
      if l == pigpio.TIMEOUT:
         if g_bits > 10:
            show(g_bits, g_reading)
            g_reading=0
            g_bits=0
      elif l == 0:
          g_reading = g_reading | (g_level<<g_bits)
          g_bits += 1

pi = pigpio.pi()

pi.set_mode(CLOCK, pigpio.INPUT)
pi.set_mode(DATA, pigpio.INPUT)

cb1 = pi.callback(DATA, pigpio.EITHER_EDGE, cbf)
cb2 = pi.callback(CLOCK, pigpio.EITHER_EDGE, cbf)
pi.set_watchdog(CLOCK, 20) # 20 ms reading timeout

time.sleep(120)

cb2.cancel()
cb1.cancel()
pi.stop()
Okay, I seem to have gotten somewhere. Now, when I run the program, the values won't change. It's stuck at -524.288 inches no matter what I do. Also, on piscope, my SCLK doesn't seem to work sometimes.

I've tried on both pin 10&11 and 20&21. I'm using the raspberry pi 2 model b.

I'm thinking that there is something wrong with how my SPI is setup.

User avatar
joan
Posts: 13464
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: interface with digital calipers

Sat Oct 17, 2015 11:28 pm

Could you post a waveform against the corresponding caliper reading?

I had to experiment with number of bits, clock rising/falling edge, lsb/msb first before I could read the caliper.

Try reversing the levels as a quick check.

ando
Posts: 5
Joined: Fri Oct 16, 2015 6:38 pm

Re: interface with digital calipers

Sat Oct 17, 2015 11:59 pm

joan wrote:Could you post a waveform against the corresponding caliper reading?

I had to experiment with number of bits, clock rising/falling edge, lsb/msb first before I could read the caliper.

Try reversing the levels as a quick check.
Similar to you, I amplified my signal using an npn transistor. So the signals are inverted.

What do you mean by reversing the levels?

And here are the screenshots:

For 0 mm

Image

For 64.36mm

Image

For -38.26 mm

Image




User avatar
joan
Posts: 13464
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: interface with digital calipers

Sun Oct 18, 2015 12:10 am

There are glitches (short pulses) on your traces which are not present on my caliper. Have a look at yours versus the one I posted. The integrity of the clock pulse is essential. Is there any hardware reason for the short pulses?

ando
Posts: 5
Joined: Fri Oct 16, 2015 6:38 pm

Re: interface with digital calipers

Sun Oct 18, 2015 12:15 am

joan wrote:There are glitches (short pulses) on your traces which are not present on my caliper. Have a look at yours versus the one I posted. The integrity of the clock pulse is essential. Is there any hardware reason for the short pulses?
It might be the battery coming loose and disrupting the power. I needed to cut part of the top in order to solder wires to it and in doing that, I couldn't close the door anymore to hold the battery.

Just have to put more tape, I guess.

User avatar
joan
Posts: 13464
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: interface with digital calipers

Sun Oct 18, 2015 12:21 am

The glitches seem to be microseconds. I was using the default sampling at 5µs. The signals seem good apart from that and I think the glitches could be removed in software (e.g. if edge < 50 µs ignore).

ando
Posts: 5
Joined: Fri Oct 16, 2015 6:38 pm

Re: interface with digital calipers

Sun Oct 18, 2015 12:34 am

joan wrote:The glitches seem to be microseconds. I was using the default sampling at 5µs. The signals seem good apart from that and I think the glitches could be removed in software (e.g. if edge < 50 µs ignore).
Hm, the glitches don't seem to be going away. It could be the power supply I'm using or the transistors.

How would I go about placing an ignore? I'm guessing sampling at a lower rate would also work as well. I don't have any experience in python. Only C and C++.

Thank you, by the way, for the help.

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 10 guests