Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import serial
- import time
- def sendCommands(cmds, delay=0):
- for cmd in cmds.strip().splitlines():
- cmd = cmd.strip()
- print('Sending: ' + cmd)
- cmd = cmd + '\n'
- s.write(cmd.encode()) # Send g-code block to grbl
- if (delay != 0):
- time.sleep(delay)
- while True:
- grbl_out_raw = s.readline()
- grbl_out = grbl_out_raw.decode('utf-8').strip()
- print(grbl_out)
- if grbl_out == 'ok':
- break
- def homeDevice():
- cmd = """
- $$
- $H
- G10 P0 L20 X0 Y0 Z0
- """
- sendCommands(cmd)
- def pyramidPattern():
- cmd=''
- # Count up to 600
- for i in range(100,700,100):
- cmd += """
- G0 X{0}
- ?
- """.format(i)
- # Count down to 100
- for i in range(500,0,-100):
- cmd += """
- G0 X{0}
- ?
- """.format(i)
- sendCommands(cmd, delay=0)
- # Open grbl serial port
- s = serial.Serial('/dev/cu.usbmodem146401',115200)
- # Wake up grbl
- serialCmd = "\r\n\r\n"
- s.write(serialCmd.encode())
- time.sleep(2) # Wait for grbl to initialize
- s.flushInput() # Flush startup text in serial input
- homeDevice()
- pyramidPattern()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement