Hope everyone is keeping well. Im making some progress with a raspberry Pi python GRBL sender. Right now,
- It picks a random G-Code file from a folder
- Streams the file accross the serial to the GRBL
- Closes everything - It completes one pattern and then stops.
Im looking for a little assistance if possible
Scheduling: Id like to be able to run the machine on certain days and time. It sounds like Crontab is used for this. Is it better to use a python library like datetime and control the stuff in the actual program OR use crontab to schedule to when to run the program. Can I have a while loop that keeps on running the patterns if using crontab does anyone know?
Plotting the G-Code: I’d like to have a little screen that plots the X,Y co-ordinates so students could appreciate that the sand pattern is controlled by the raspberry pi. Does anyone know of a simple python library that opens up a little window and prints out the plot.
Any chance someone more experienced in programming and python could look over the code and give me some feedback - is there any error checking we could add - any other suggestions?
Big thanks for all the help so far - If your ever in Maryland - ill buy you a pint ,
import serial import time import os, random # Open grbl serial port s = serial.Serial('/dev/ttyUSB0',115200) # Opens up a random G-Code File random_file = random.choice(os.listdir("/home/timcallinan/GCODE/")) file_path = os.path.join("/home/timcallinan/GCODE/", random_file) print(file_path) f = open(file_path,'r'); # Wake up grbl s.write("\r\n\r\n".encode()) time.sleep(2) # Wait for grbl to initialize s.flushInput() # Flush startup text in serial input # Stream g-code to grbl for line in f: l = line.strip() # Strip all EOL characters for streaming print('Sending: ' + l,) s.write((l + '\n').encode()) # Send g-code block to grbl grbl_out = s.readline() # Wait for grbl response with carriage return grbl_out_str=str(grbl_out) print(' : ' + grbl_out_str) # Close file and serial port f.close() s.close()