Output byte data to another Octopi serial port


Hi. I'm trying to connect a 2nd Arduino to another serial port of the same Octopi.
I'm unable to find solutions others have shared before. Hence I would like to ask for help in this platform.

The plan
I need my Arduino robot arm to extract my completed print. I tried the concept using another computer to host the arm and the result is fascinating. The arm runs on a separate protocol which recognises specific byte commands. Now to fully automate this concept, I need to connect the arm to Octopi to have it send gcodes to the printer and byte data to the arm in precise order.

The approach
Every print job has specific end gcodes added. In between several of the end gcodes, I need OctoPi to send a specific byte command via a 2nd serial port to the arm.

Example of sequence in every job's end-gcode and byte output
M104 S0
M140 S0
G1 E-1 F300
G1 Z+0.5 E-5 X-20 Y-20 F9000
G28 X0
G1 Y170 F1000
M42 P6 S255
G4 S900
M42 P6 S0
//output b'001\r' to port2
//output b'002\r' to port2
//output b'003\r' to port2
G28 Y0
//output b'004\r to port2
//output b'005\r to port2

Appreciate if anyone has a good idea to tackle this. Grateful if you can tell me where to slide my codes in to be executed at the right time. Thank you very much.

I am not a professional developer, I am a hobbyist maker and improve my python by working on multiple projects. I have been using pyserial library via terminal on mac to communicate with my arm. I have trouble understanding the source code of octoprint due to the complexity beyond my level.

I'd hope if anyone is kind enough to help! Thanks very much.


I found myself a solution. gcode command to run python script on port2 with serial. thanks :slight_smile: