Skip to content

Instantly share code, notes, and snippets.

@hugs
Last active June 8, 2023 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugs/e4e4c09a6bddf490f5930bf05a00f0cd to your computer and use it in GitHub Desktop.
Save hugs/e4e4c09a6bddf490f5930bf05a00f0cd to your computer and use it in GitHub Desktop.
Tapster 3 - Demo Script - Tap "Hello, World!!"
import serial
from time import sleep
clearance_height = "Z-5"
tap_height = "Z-19"
# Open grbl serial port
# TODO: Make this a command line flag...
s = serial.Serial('/dev/cu.SLAB_USBtoUART', 115200)
def init():
# Wake up Grbl
s.write(b"\r\n\r\n")
sleep(2) # Wait for Grbl to initialize
s.flushInput() # Flush startup text in serial input
def send(command, pause=0.2):
message = str.encode(command + '\n')
s.write(message)
result = s.readline()
print(result.strip().decode('utf-8'))
sleep(pause)
def tap(position):
send("G1 " + position + " " + clearance_height)
send("G1 " + position + " " + tap_height)
send("G1 " + position + " " + clearance_height)
#Initialize
init()
# Set speed
send("G1 F8000")
# Go to home position
send("G1 X0 Y0 Z30", 2)
# Open Twitter app
send("G1 X3.25 Y-3.5 Z-20")
# Return to home position
send("G1 X3.25 Y-3.5 Z30")
# Tap "Hello, World!" on the keyboard
tap("X-23.5 Y-67") # Shift
tap("X10.5 Y-56") # H
tap("X-13.5 Y-47.5") # e
tap("X29.5 Y-58") # l
tap("X29.5 Y-58") # l
tap("X26 Y-47.5") # o
tap("X-17 Y-75") # ,
tap("X5 Y-75") # <space>
tap("X-23.5 Y-67") # Shift
tap("X-20 Y-46.5") # W
tap("X26 Y-47.5") # o
tap("X-8 Y-47") # r
tap("X29.5 Y-58") # l
tap("X-10.5 Y-56.5") # d
tap("X-25 Y-75") # Shift to extra characters screen
tap("X15 Y-63") # !
# Return to home position
send("G1 X0 Y0 Z30")

Python Sample Code

Demo Video

https://twitter.com/hugs/status/1291798092950441990

Setup

python3 -m venv env
source env/bin/activate
pip install -r requirements.txt

Run demo

  1. First, make sure the Tapster 3 robot is plugged in and running.

  2. Run demo:

python tap-hello-world.py

Deactivate enviroment

deactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment