Created
December 17, 2018 17:44
-
-
Save danielkucera/04dccd8e0a78df31f49c4ed1da034511 to your computer and use it in GitHub Desktop.
test-bltouch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import time | |
import re | |
import statistics | |
dev = os.open("/dev/pts/0",os.O_RDWR) | |
#flush buffer | |
os.write(dev, "M105\n") | |
os.write(dev, "M105\n") | |
os.write(dev, "M105\n") | |
time.sleep(4) | |
os.read(dev, 65535) | |
data = [] | |
def send_cmd(cmd): | |
ret = "" | |
print "sending cmd:", cmd | |
os.write(dev, cmd+"\n") | |
time.sleep(1) | |
while True: | |
ret += os.read(dev, 256) | |
if "ok" in ret: | |
return ret | |
print send_cmd("G28") | |
for i in range(1, 100): | |
print "probe" | |
print send_cmd("G1 Z5") | |
val = send_cmd("PROBE") | |
m = re.match(r".*z=(-?\d+.\d+)", val) | |
data.append(float(m.group(1))) | |
print "value:",val, m.group(1) | |
print data | |
print "stdev:", statistics.stdev(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment