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

Re: interface with digital calipers

Sun Oct 18, 2015 9:35 am

What actual model of Caliper did you use Joan ?

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

Re: interface with digital calipers

Sun Oct 18, 2015 11:27 am

perfo wrote:What actual model of Caliper did you use Joan ?
I bought http://www.ebay.co.uk/itm/281773127946

150mm 15cm 6" Electronic Digital LCD Steel Vernier Caliper Gauge Micrometer SY

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

Re: interface with digital calipers

Sun Oct 18, 2015 11:55 am

Ok thanks. I have already ordered soem from hong kong and hoped they would eb the same but If I can get mine to work at least I know where to go to get one that does..
I've got two of these
http://www.ebay.co.uk/itm/271993321208? ... EBIDX%3AIT
£6.90 for two inc pnp so can't be bad if I can get them to work. I'll probably destroy them trying to link them together so I wanted the cheapest possible options....

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

Re: interface with digital calipers

Sun Oct 18, 2015 12:21 pm

The bit that does all the work looks identical to mine.

mja1962
Posts: 2
Joined: Tue Dec 01, 2015 11:28 pm

Re: interface with digital calipers

Tue Dec 01, 2015 11:40 pm

Hello,

I am interested in interfacing with digital calipers, too. I have not purchased a Pi yet - would you know if the Zero is capable of communicating with the calipers?

Thanks in advance,
Michael

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

Re: interface with digital calipers

Wed Dec 02, 2015 8:04 am

mja1962 wrote:Hello,

I am interested in interfacing with digital calipers, too. I have not purchased a Pi yet - would you know if the Zero is capable of communicating with the calipers?

Thanks in advance,
Michael
The interface is through the GPIO pins, which are the same on the Pi Zero, so probably yes.

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

Re: interface with digital calipers

Wed Dec 02, 2015 9:30 am

ame wrote:
mja1962 wrote:Hello,

I am interested in interfacing with digital calipers, too. I have not purchased a Pi yet - would you know if the Zero is capable of communicating with the calipers?

Thanks in advance,
Michael
The interface is through the GPIO pins, which are the same on the Pi Zero, so probably yes.
Definitely yes. I've just set one up on the Pi Zero.

Edited to add:

I originally connected the outputs to GPIO 14/15 but that halted the Pi (in as far as pings stopped until I removed the wires from 14/15). When I put the wires in 20/21 everything was fine. 14/15 would have been in UART mode. I wonder if the Zero is short of 3.3V ooomph.

Edited again to add:

Thinking about it a bit more the Pi Zero may have been busy trying to respond to a nonsense login from the calipers.

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

Re: interface with digital calipers

Thu Dec 03, 2015 3:04 pm

To clarify the caliper interface with the Pi.

The caliper works on 1.5V which is not high enough to be reliably seen as high by the 3.3V Pi.
IMG_3767-c.JPG
IMG_3767-c.JPG (25.93 KiB) Viewed 2077 times
The circuit shown half way into https://sites.google.com/site/marthalpr ... al-caliper was used to boost the 1.5V to 3.3V.
IMG_3770-a.JPG
IMG_3770-a.JPG (44.02 KiB) Viewed 2077 times
Green is the 3V3 rail.
Black is the ground rail.
Purple is a 1.5V input from the caliper.
Yellow is the corresponding 3.3V output to a Pi GPIO.
IMG_3773-a.JPG
IMG_3773-a.JPG (44.2 KiB) Viewed 2077 times

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

Re: interface with digital calipers

Fri Dec 04, 2015 9:30 am

I think what he means is do a check on the clock pulse ...
Ie if the clock pulse is high (or low depending on which state you are looking for) do a while loop until it changes state. Whilst in the while loop have a counter increment. At the end of the while have a look at the counter and if it is lower than a certain value then this wasn't a genuine clock pulse so ignore it.. The other way is to do it with time (as suggested) so when clock goes high count how many uS to change state and only include the ones above 50 us. Obviously setting up an accurate time measure meant would be better than my method and indeed my method would give different results depending on the loop time of the PI but I think a good pulse will be so different from a bad one a simple crud counter would do... Another consideration is whilst in the loop the pi can't do anything else unless you've set up multi threading etc which at the moment I know enough about to mention the word but that's about it..
Keep us informed of you progress please.

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

Re: interface with digital calipers

Fri Dec 04, 2015 11:02 pm

perfo wrote:I think what he means is do a check on the clock pulse ...
Ie if the clock pulse is high (or low depending on which state you are looking for) do a while loop until it changes state. Whilst in the while loop have a counter increment. At the end of the while have a look at the counter and if it is lower than a certain value then this wasn't a genuine clock pulse so ignore it.. The other way is to do it with time (as suggested) so when clock goes high count how many uS to change state and only include the ones above 50 us. Obviously setting up an accurate time measure meant would be better than my method and indeed my method would give different results depending on the loop time of the PI but I think a good pulse will be so different from a bad one a simple crud counter would do... Another consideration is whilst in the loop the pi can't do anything else unless you've set up multi threading etc which at the moment I know enough about to mention the word but that's about it..
Keep us informed of you progress please.
Since ando's post I have added a glitch filter to pigpio. From Python set_glitch_filter, from the command line pigs fg. That will filter out any edges shorter than the specified number of microseconds.

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

Re: interface with digital calipers

Sat Dec 05, 2015 9:54 am

One step even easier then...thanks..

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

Re: interface with digital calipers

Sat Dec 05, 2015 10:16 am

perfo wrote:One step even easier then...thanks..
The effect on 433MHz radio noise is dramatic.

No filter.
433MHz noise.png
433MHz noise.png (33.46 KiB) Viewed 1997 times
Filter 50µs or less edges (legal data is typically 200µs plus).
433 MHz noise 50us filter.png
433 MHz noise 50us filter.png (32.39 KiB) Viewed 1997 times

Perfo2
Posts: 1
Joined: Thu Dec 10, 2015 1:46 am

Re: interface with digital calipers

Thu Dec 10, 2015 1:48 am

wow, any changes in speed or accuracy of the final figure ?

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

Re: interface with digital calipers

Thu Dec 10, 2015 9:07 am

Perfo2 wrote:wow, any changes in speed or accuracy of the final figure ?
If you are referring to the glitch figure. No difference for my digital calipers as they don't have gitches. For people with glitches it would make the difference between a good and bad read.

For receiving radio messages it makes a little difference during the message itself. It makes an awful lot of difference outside the message. The software doesn't have to process thousands of GPIO level changes trying to detect the start of a message.

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

Re: interface with digital calipers

Thu Dec 10, 2015 5:09 pm

Ah yes makes sense..

ewanpth
Posts: 7
Joined: Tue Oct 20, 2015 3:41 pm

Re: interface with digital calipers

Thu Jan 14, 2016 2:21 pm

Hi all,

I'm trying to combine Joans script with a UI and I'm getting random glitches in the reading.
The original script Joan wrote works perfectly and never gives errors, but I have changed it to run once every second, instead of as a continuous loop. Now I get the occasional false reading which will be extremely high, usually when there is a change in value, i.e if I keep the micrometer on the same value I get no errors.

Anyone got any idea why this might be, or a better way of incorporating the script into a UI?

This is the code I've written, there are a few issues with it but I'm trying to resolve this one first.

Code: Select all

import datetime
import csv
from tkinter import *
from tkinter import messagebox
import time
import pigpio
import os

os.system("sudo pigpiod")

hold_value = 0

root = Tk()

winx = 480
winy = 320 


CLOCK=21
DATA=20

g_level=0
g_reading=0
g_bits=0

pi = pigpio.pi()


virtual_reading = StringVar()

def go():
   global cb1
   global cb2
   cb1 = pi.callback(DATA, pigpio.EITHER_EDGE, cbf)
   cb2 = pi.callback(CLOCK, pigpio.EITHER_EDGE, cbf)
   global reading_display
   root.after(1000 ,go)



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 = ""
   global virtual_reading
   virtual_reading = StringVar()
   virtual_reading.set("{} {:.3f} {}".format(sign, reading, units))
   print(virtual_reading.get())
   cb2.cancel()
   cb1.cancel()



def measure(event=None):
    todays_date = datetime.date.today()  
    try:
        get_tool_no = int(tool_no_entry.get())
        if get_tool_no <= 0:
            messagebox.showerror("Try Again","Please Enter A Number")
        else:
            with open("thickness records.csv", "a") as thicknessdb: 
                thicknessdbWriter = csv.writer(thicknessdb, dialect='excel', lineterminator='\r')
                thicknessdbWriter.writerow([get_tool_no] + [todays_date] + [virtual_reading.get()]) ###########
            thicknessdb.close()
    except:
           messagebox.showerror("Try Again","Please Enter A Number")
    tool_no_entry.delete(0, END)



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

   
go()

record_button = Button(root,width = 30,
                               height = 8,
                               text='Measure',
                               fg='black',
                               bg="light grey", command = measure)

tool_no_entry = Entry(root)

reading_display = Label(root, font=("Helvetica", 22), text = hold_value)

reading_display.place(x = 50, y =80)



root.resizable(width=FALSE, height=FALSE) 
root.geometry('%dx%d' % (winx,winy)) 
root.title("Micrometer Reader V1.0")


record_button.place(x = 340, y = 100, anchor = CENTER)


tool_no_entry.place(x = 120, y = 250, anchor=CENTER)
tool_no_entry.focus_set()


root.bind("<Return>", measure)
  

root.mainloop()

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

freisei
Posts: 2
Joined: Wed Jan 04, 2017 8:33 pm

Re: interface with digital calipers

Wed Jan 04, 2017 8:37 pm

Thanks for your good work!

I´ve another problem with an China-Calliper. Bad Clock-Timings.

Blue-Channel is the Clock, yellow is data. Because data-signal is rising AFTER the clock is ticking raspi can't dertermine the correct level of data-pin.

Any Ideas?

Greets Freisei
Attachments
badclock.png
badclock.png (36.9 KiB) Viewed 1614 times

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

Re: interface with digital calipers

Thu Jan 05, 2017 12:12 pm

Could you sample the data line on the falling clock edge rather than the rising edge?

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

Re: interface with digital calipers

Thu Jan 05, 2017 5:47 pm

In reply to ewanpth

Could it be you are either not clearing some variables or buffers and thus compounding the numbers or maybe as you are delaying things is the reading not being taken over the full (right) set of data bits ?

Did anyone have a go connecting these cheap things together to make a long one

freisei
Posts: 2
Joined: Wed Jan 04, 2017 8:33 pm

Re: interface with digital calipers

Thu Jan 05, 2017 6:01 pm

no that won´t work, because DATA is somtimes already in next state, when CLOCK is falling.

I´ve build a very ugly circuit to delay the CLOCK some microseconds. Bud i wouldn´t call it CLOCK-signal anymore. It looks more like a sharks fin. :D

I´ve bought this caliper vom PeWeTools Limited http://www.ebay.de/itm/151241771936

On the wire there are not the values displayed on LCD, instead there are fixed values per position with a funny counting. Here is the modified code to get theese values.

Code: Select all

#!/usr/bin/env python

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

## apt-get install python3-pigpio
#wget abyz.co.uk/rpi/pigpio/pigpio.zip
#unzip pigpio.zip
#cd PIGPIO
#make
#make install
#  sudo pigpiod

from __future__ import print_function
from decimal import *
import sys

import time

import pigpio

CLOCK=21
DATA=20

g_level=0
g_reading=0
g_bits=0

getcontext().prec=3

def show(bits, value):

	if value < 13000:
		reading = Decimal(value + 20534) / 100 #20371
	else:
		reading = Decimal(value - 2076618) / 100
		
	print("{} mm".format(reading), end="")
	print(" ", bin(value), "\r", end="")
	sys.stdout.flush()

def cbf(g, l, t):
   global g_level, g_reading, g_bits
   if g == DATA:
	  if l == 0:
		 g_level = 0
	  else:
		 g_level = 1
   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, 2) # 2 ms reading timeout - used to print values on clock-pause

time.sleep(120)

cb2.cancel()
cb1.cancel()
pi.stop()
Circuit for delaying CLOCK follows.

Greets Freisei
Attachments
sharkfin.png
sharkfin.png (50.13 KiB) Viewed 1542 times

neaton
Posts: 1
Joined: Tue Dec 05, 2017 8:49 pm

Re: interface with digital calipers

Tue Dec 05, 2017 8:54 pm

Thank you so much for the information in this thread. Tonight I got my cheap'n'cheerful caliper to output a signal that I could read from a program on my pi, and there is no way I could have done that without reading this.

I am currently dancing around the room, for which I thank you all.

User avatar
Gavinmc42
Posts: 2108
Joined: Wed Aug 28, 2013 3:31 am

Re: interface with digital calipers

Sat Dec 09, 2017 12:47 pm

Tried do this years ago- before Pi's.

Just noticed this sensor the other day.
Two addresses and 2 x i2c ports = 4 axis without needing to multiplex.
http://ams.com/eng/Products/Magnetic-Po ... n/NSE-5310

Plastic magnet fridge magnets have magnets arranged this way, not sure it they are 2mm
But AMS do have the mag strips too.

For really small positioning the standard DRO scales are too big.
Pocket sized CNC mill?
What is the world's smallest CNC lathe?
Going to need even more Zero's :lol:
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

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

Who is online

Users browsing this forum: TosaAtKSY and 12 guests