Conditions and communications between 2 printers


What is the problem?
Hi !
I didn't find if Octoprint knew manage conditions, and if yes, which one.
For my internship, I must do collaborate two printers Scar Arm 3D (with atmega 2560). I'm using Octoprint on Raspi 3.
I would like to inject conditions on the Z Axe as below in my GCode (with the gcode commands enough):

if (value on Z grows up)
wait XXXX secondes.

I decide to use delay because I didn't find a solution in order to printers communicate between us. If anyone has any idea or piece of advice.
I don't know if in atmega 2560 there is a pin saying information on Z axe. I don't have the datasheet of the board with pins, I don't find it on Internet.

Thank you.

What did you already try to solve it?
Delays work correctly.
I will do basic test with conditions.

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)
Raspberry Pi 3, Octoprint Version 1.3.6, Printer scara arm 3D with atmega 2560
FIRMWARE_NAME:Marlin V1.0.2; Sprinter/grbl mashup for gen6 FIRMWARE_URL: PROTOCOL_VERSION:1.0 MACHINE_TYPE:qingxin EXTRUDER_COUNT:1 UUID:00000000-0000-0000-0000-000000000000


@Geany I know this doesn't directly answer your question but I think that if you leave the Microsoft Windows software (you mentioned this in another thread) for controlling the two printers and go with a Raspberry Pi 3 computer (or even a pair of them) then GPIO could be your friend.

If it were me, I would setup a GPIO pin as the starting gate at a racetrack:


If, say, PIN 17 is OFF, both printers have to wait ("gated") before proceeding to the next GCODE command. When PIN 17 is ON, they are both permissioned to proceed.

In a two-Raspi setup, one of them is the master and owns the GPIO pin in question. The other Raspi is the slave and reads/writes the other Raspi's pin using "remote GPIO". In this design, the master sets the pin (turns it ON) and the slave clears it (turns it OFF). Both need to be running a plugin which waits to send a GCODE command to the RAMPS board based upon this logic.

Note that no hardware needs to be connected to the pin. Since GPIO is easy to read and write, it just makes sense to me.

You might need the master to run a short delay after setting the pin (as a "debounce").


Hi @OutsourcedGuru !
In fact, now I'm on raspberry pi 3.

Thank you for your answer. With this solution, I must and/ord I can always use Octoprint (particularly interesting for pre viewing of each layer) ?
I understand how two raspberry will communicate with each other but, each printer will be controlled by one raspberry or the rasbperry slave controls both and send different informations for each printer in function of the layer? I need to stop each printer one after the other when the common part must be printed.
Do you know a plugin which does that ? Or I must develop it ? Any idea in which language?
When you said "ramps board", it is my board with marlin firmware ?

Best regards


If it were me (and assuming your printers are named Huey and Louie:

Printer Raspi3 Mode
Huey huey.local master
Louie louie.local slave

You would, in theory, have two tabs in your browser: one for http://huey.local/ and one for http://louie.local/ as well. There are other ways but this is the simplest.

Each OctoPrint installation of the two would point to its respective printer. Each OctoPrint would need the same plugin, only one is configured as master and the other as slave. I'm not sure if the plugin actually needs to know about the other printer; the underlying shell or python script would need to know the other hostname. The shell script for the slave especially needs to know the master's hostname because its doing remote GPIO to read a remote pin and then to clear that pin as well.

Yes, a RAMPS board runs Marlin, for example, and is the one with the transistors (hardware drivers) for the motors.

The plugin (which doesn't exist) needs to "hook" into the serial communications of OctoPrint. Hopefully, the OctoPrint hook will allow you to block its functionality and continue when the GPIO pin has been set. In this way, you stop both printers until that pin is ON. When the pin turns ON both plugins then release control back to OctoPrint to send the GCODE command through the serial mechanism.

At this moment, the slave then clears the pin, turning it OFF.

When the master's serial hook gets fired off again, the plugin's code is running again. It might decide to add a 20 millisecond delay then to set the pin, turning it ON. Both plugins see the ON status and send their respective GCODE command to the RAMPS board and everything repeats.

These plugins are almost always written in Python. Gina has examples as do several of the authors here.

As I mentioned before, GPIO is fairly easy.

Toggle on PIN 17 on the local Raspberry Pi in a shell script:


echo "1" > /sys/class/gpio/gpio17/value

Similarly, a zero would clear the bit.

There are many places on the Internet where you can get more information.

GPIO pin control from the command line

How to control GPIO of another RPI

Set up a Pi and host PC for remote GPIO access using gpiozero in Python
(Note that "gpiozero" does not refer to a Raspberry Pi Zero but to the name of the library.)

import pigpio

PIN17 = 17
louie = pigpio.pi()        # accesses the local (slave) Pi's GPIO
huey = pigpio.pi('louie')  # accesses the remote (master) Pi's GPIO

print("Huey's PIN17 is {}".format( ))
huey.write(PIN17, 0)
print("Huey's PIN17 is now {}".format( ))

More info about setting up pigpio


Hi @OutsourcedGuru

It's me, again ! :stuck_out_tongue:
If I want master rpi and slave rpi, how does the connection ?
Indeed, I need to have a PC with a switch in order to two raspi communicate with each other?

Because the pin17 must be an input and an ouput because I need to read it for rpi and write it after execution of gcode command.

I think about algorithm and my solution would be:

  • pin 17 off, slave pi works, after its line code (detection with hookg queuning), pin 17 set
  • pin 17 on, master pi works, after its line code (detection with hook queuning), pin 17 clear.
    Is it realizable ?

Best regards


You don't need an ethernet switch/hub (for Ethernet cabling). As long as each Raspberry can ping the other, that's the connectivity you need to get things started.

I described earlier in this thread that both Raspis need "remote GPIO" turned on. The slave looks at the remote pin 17 on the master. The master looks at its local pin 17.

And I described the behavior above in this thread. Re-read it a little and see how all this works.



So that each Raspi can ping the other they need to be on the same Network, we are agree.
There are a lot of notions to learn and I'm confused sometimes sorry.

I was wondering, with only one Raspi can I develop the plugin I need ?

I am working to develop my owner plugin and I have only 3 weeks it is very short and I am anxious sorry.


You should try this with two Raspis, as discussed. Do you have a local mentor/teacher who can help guide you?


Ok I try with two raspi as discussed.
Yes I have but development is little unknown for him


I'm a software development instructor. At the academy, I know that I can code something in about ten minutes that takes the roomful of students an hour to do.

The point of your exercise is that you, Geany, learn how to code this. I know it's tough but think about the problem. Read what I've included in the thread above and put the work into making it happen. You can do it.