Get Values from Printer by I2C



i want to run an esp32 for dedicated functions. The ESP32 controlls some Relais, and buzzers, and mybe more.

I need help to implement a scripte for sending printer status values trought i2c channel to my ESP32. It is not neccessary to controll the printer over i2c. I need the communication just in one direction, values from my printer to my Esp.

I'm new in Octopi and i cant find a good solution, maybe there is a plugin i do not know/found.


Hi there. The Raspberry Pi has nice i2c support with i2c-tools. For instance, you can run i2cdetect -y 1 to see the devices that it sees.

You'll have to write your own Octoprint plugin.


Yes, that sounds good. Thank you.

I know there are differnet examples and tutorials for octopi plugin programming. Can you give me a litte help out of your Experience to have a fast start?


For Example:

  • I want to send a notification about Print start and print stop via I2C.
  • I want to send the Z Value evey new Layer via I2C.

Can you give me some abtract instructions how to get it? I just need some impulses.


Here's a good tutorial:

1 Like

Thank you. :slight_smile:

I found a an Event called: PositionUpdate.

Is it possible to use this event only for Z and send it out over i2c?


You should probably look at the ZChange event instead but the example on that events page shows how to configure calling a python script for an event. There are plenty of examples on using the i2c bus from python that can be found with a Google search. Should just be a matter of cut and pasting something that will work for you.


Reeeeaaaallly Big Thank you.

I found the Event you told me:

The printer’s Z-Height has changed (new layer) through a G0 or G1 that was sent to the printer through OctoPrint (not triggered when printing from SD!)

I only print with Octopi and dont need SD Printing. I will try, and report.


Ok, i found this, looks good:

You can use the following generic placeholders in your event hooks:

    {__currentZ}: the current Z position of the head if known, -1 if not available

But i dont understand what i have to do. :frowning:

I want to write a script which sends Z over i2c
The Script waits for an ZHeight Event (if enabled), and sends the Payload of the Event over I2C.
Sounds easy, but i need more help to get it. I have no experiences with python. Learning by Doing.


Type "raspberry pi i2c python example" into your favorite search engine in your favorite browser (leave out "python" or add your favorite programming language). Heck, add "esp32" since you said that was the device you are going to use. Start by reading at least 5 of the links in the search and then report back with your success or failure with:

  1. Installing the I2C tools and libraries on OctoPi.
  2. Installing the ESP32 and connecting the I2C bus to the Raspberry Pi.
  3. Running tools like I2cdetect to find your device.
  4. Modifying config.yaml to add the event(s) you want calling a bash script.
  5. Write the bash script that outputs the value(s) passed to a file.
  6. From all the examples you found with your search, extract a python program example that most closely matches what you are trying to do.

Thank you really much.

This helped me a lot. I report.