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 enter image description here

#!/usr/bin/env python

# SPC.py
# 2016-12-04
# Public Domain

import time
import pigpio


# 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:
               in_data = False

pi = pigpio.pi()
if not pi.connected:

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)



  • Check to see the actual data with abyz.me.uk/rpi/pigpio/piscope.html
    – joan
    Jan 12 '20 at 17:07
  • Checked the data, then used a sample program that turns morse code into signals to check if the piscope works and it does. When I run the actual program, all the pins get set to 1 and then it just waits for 300s and quits. Jan 12 '20 at 18:29
  • We would be guessing about what is wrong. You will have to experiment as the software can't produce a reading while there is no data. Clear photo(s) of the connections between the Pi and the sensor may help.
    – joan
    Jan 12 '20 at 18:34
  • link Here are the pictures, nothing too complex. Jan 12 '20 at 18:58
  • You need to add any additional information to your question.
    – joan
    Jan 12 '20 at 20:00

Welcome, Tilen. I can't see that nibble will ever be >12 - don't forget you're starting from zero and reading 13 bits... This might explain why you're not getting any output...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.