Mitutoyo Caliper Readout¶
This example prints a connected Caliper’s value on the push of the ready button on the instrument.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # This is a quick example how to read values from Mitutoyo Calipers.
# Assuming a Serpente board, with `req`, `clock`, `data` and `ready` connected to
# D0, D1, D2 and D3, respectively.
import time
import board
import digitalio
import mitutoyo
pin_ready = digitalio.DigitalInOut(board.D3)
pin_ready.direction = digitalio.Direction.INPUT
pin_ready.pull = digitalio.Pull.UP
print("Hello! Press the read button on the Calipers to print the value!")
meter = mitutoyo.Digimatic(req=board.D0, clock=board.D1, data=board.D2)
while True:
# wait until ready goes low
while pin_ready.value:
time.sleep(0.1)
reading = meter.read()
if reading:
print(reading)
# wait until ready goes up again to just get a single reading per press
while not pin_ready.value:
time.sleep(0.1)
|
Mitutoyo Caliper USB CAD entry¶
This example types out the reading of a connected Caliper’s value on the push of the ready button on the instrument.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # Direct CAD entry for Mitutoyo calipers via USB HID emulation.
# Assuming a Serpente board, with `req`, `clock`, `data` and `ready` connected to
# D0, D1, D2 and D3, respectively.
import time
import board
import digitalio
import mitutoyo
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
# I/O
pin_ready = digitalio.DigitalInOut(board.D3)
pin_ready.direction = digitalio.Direction.INPUT
pin_ready.pull = digitalio.Pull.UP
meter = mitutoyo.Digimatic(req=board.D0, clock=board.D1, data=board.D2)
# USB HID keyboard emulation.
time.sleep(1)
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
print("Ready.")
while True:
# wait until ready goes low
while pin_ready.value:
time.sleep(0.1)
reading = meter.read()
if reading:
print("Typing %s." % reading)
layout.write(str(reading) + "\n")
# wait until ready goes up again to just get a single reading per press
while not pin_ready.value:
time.sleep(0.1)
|