I've been trying to interface a Mitutoyo digital caliper. I used the code from here and I think I made the right corrections according to the posters comments but as I checked he was last online in 2017.
I connected my raspberry according to the image below, with DATA going to GPIO2, CLK going to GPIO3 and REQ going to pin 4. Also I connected the GND from the cable to the ground on the raspberry (don't know if that made a difference. When I ran the code no error happened but I also got nothing to print
#!/usr/bin/env python
# SPC.py
# 2016-12-04
# Public Domain
import time
import pigpio
REQ=4
CLK=3
DATA=2
# The callback implements the Mitutoyo SPC protocol
# 13 4-bit nibbles, least significant bit first.
def cbf(gpio, level, tick):
global in_data, bit, nibble, nibbles, data_level
if gpio == REQ:
nibble = 0
bit = 0
nibbles = [0]*13
in_data = True
elif gpio == DATA:
data_level = level
else: # CLK
if in_data:
nibbles[nibble] |= (data_level << bit)
bit += 1
if bit > 3:
bit = 0
nibble += 1
if nibble > 12:
print(nibbles)
in_data = False
pi = pigpio.pi()
if not pi.connected:
exit()
in_data = False
bit = 0
nibble = 0
nibbles = [0]*13
data_level = pi.read(DATA)
pi.set_mode(REQ, pigpio.OUTPUT)
pi.write(REQ, 1)
pi.set_pull_up_down(CLK, pigpio.PUD_UP)
pi.set_pull_up_down(DATA, pigpio.PUD_UP)
cb1 = pi.callback(REQ, pigpio.FALLING_EDGE, cbf)
cb2 = pi.callback(CLK, pigpio.FALLING_EDGE, cbf)
cb3 = pi.callback(DATA, pigpio.EITHER_EDGE, cbf)
time.sleep(300)
cb1.cancel()
cb2.cancel()
cb3.cancel()
pi.stop()