Want to run Klipper on your Anycubic-i3-Mega? And still want to be able to use your Anycubic-i3-Mega TFT touch screen?
Take a look at this python service.
Forked from joakimtoe/KlipperLCD and based on the work of Marlin anycubic_i3mega_TFT.cpp
Thank you for your Work!!!
Running together with Klipper3d and Moonraker!
Warning
I haven't yet had a chance to test the display and all the functions down to the last detail. However, most of them should work. Nevertheless, some functions cannot be implemented due to the functional scope of the display and the communication protocol. This is a work in progress. There is no guarantee. Be careful, watch your printer, double check things. Use it as is. I am not responsible for any damages or consequences of any kind.
- Get every currently function completely tested and verified
- Verify Mega X Display wiring / compatibility
- Reset print status page on Emergency stop
- Resume print after power-outage
- Support for the anycubic_chiron?
- Figure the missing J-Commands out
- Ensure that the controller responds appropriately to requests from the display with J commands
- Possibly, improve the file/directory traversing in the file explorer? -> Needs a press on the UP-Arrow or Refresh button after changing directories
- Improve Error Handling of the code and in case of edge cases
- Use types for vars?
- Use ENV vars to configure UART-Port and moonraker address and configure the service via systemd-service /
/etc/defaults - Maybe a context manager for the uart port
- Use the special menu for Stuff like bed leveling
- Use systemd as logger for the service
- A Anycubic-i3-Mega TFT Screen (any from THIS list should work).
- A Raspberry Pi or similar SBC to run Klipper. I suggest using the Klipper Installation And Update Helper (KIAUH) to setup and install Klipper, Moonraker and the web user interface of choice (Fluidd/Mainsail).
- Some re-wiring of the TFT screen to connect it to one of the UARTs availible on your Raspberry Pi / SBC or through a USB to UART converter.
- Then you can follow this guide to enable your Anycubic-i3-Mega touch screen again!
When wiring your screen, you can either wire it directly to one of your Raspberry Pi / SBC availible UARTs or you can wire it through a USB to UART converter. Both options are described below, pick the option that suits your needs.
-
Remove the back-cover of the TFT by unscrewing the four screws.
-
Connect the TFT to the Raspberry Pi UART according to the table below:
Raspberry Pi TFT Pin 4 (5V) 5V (Red wire) Pin 6 (GND) GND (Black wire) GPIO 14 (TXD) RX (Green wire) GPIO 15 (RXD) TX (Yellow wire)
Quite simple, just remember to cross RX and TX on the TFT and the USB/UART HW.
| USB <-> UART HW | TFT |
|---|---|
| 5V | 5V (Red wire) |
| GND | GND (Black wire) |
| TXD | RX (Green wire) |
| RXD | TX (Yellow wire) |
Note: You can safely skip this section if you wired the display through a USB to UART converter
By default, the primary UART is assigned to the Linux console. If you wish to use the primary UART for other purposes, you must reconfigure Raspberry Pi OS. This can be done by using raspi-config:
- Start raspi-config:
sudo raspi-config. - Select option 3 - Interface Options.
- Select option P6 - Serial Port.
- At the prompt Would you like a login shell to be accessible over serial? answer 'No'
- At the prompt Would you like the serial port hardware to be enabled? answer 'Yes'
- Exit raspi-config and reboot the Pi for changes to take effect.
For full instructions on how to use Device Tree overlays see this page.
In brief, add a line to the /boot/config.txt file to apply a Device Tree overlay.
dtoverlay=disable-bt
- Either login via SSH and head to the
/bootdirectory and edit thearmbianEnv.txtor plug the SD-Card into your PC (if you have the non eMMC variant) and edit thearmbianEnv.txtfrom there. - Adjust the
consoleparameter toconsole=serial
The default value is console=display, This means that the UART0 of CB1/CB2 is used as the debugging port by default.
- Reboot
Now you can use /dev/ttyS0 in KlipperTFT
- SSH into your Raspberry Pi
-
Make sure Klipper's API socket is enabled by reading the Klipper arguments.
Command:
cat ~/printer_data/systemd/klipper.envResponse:
KLIPPER_ARGS="/home/pi/klipper/klippy/klippy.py /home/pi/printer_data/config/printer.cfg -I /home/pi/printer_data/comms/klippy.serial -l /home/pi/printer_data/logs/klippy.log -a /home/pi/printer_data/comms/klippy.sock"The KLIPPER_ARGS should include
-a /home/pi/printer_data/comms/klippy.sock. If not add it to the klipper.env file!
sudo apt install python3-requests python3-serial git
cd ~
git clone https://github.com/judokan9/KlipperTFT_UART.git
cd KlipperTFT_UART
- Open
main.pyand find theclass KlipperTFTdeclaration:
class KlipperTFT ():
def __init__(self):
...
TFT("/dev/ttyAMA0", callback=self.lcd_callback)
...-
If your UART is something other than the default
ttyAMA0, replace the string"/dev/ttyAMA0"to match your UART selection (i.e./dev/ttyS0for CB1/CB2).Note: If using a USB to UART converter to connect your screen to Klipper, the converter usually shows up in Linux as
"/dev/ttyUSB0".
Once the TFT touch screen is wired to the Raspberry Pi, Klipper socket API is enabled and the KlipperTFT class is configured according to your wiring you can fire up the code!
python3 main.py
Congratulations! You can now use the touch screen!
If the path of main.py is something else than /home/pi/KlipperTFT/main.py or your user is not pi. Open and edit KlipperTFT.service to fit your needs.
Enable the service to automatically start at boot:
sudo chmod +x main.py
sudo ln -s ~/KlipperTFT_UART/KlipperTFT.service /etc/systemd/system/KlipperTFT.service
sudo systemctl daemon-reload
sudo systemctl enable --now KlipperTFT.service
sudo reboot
I developed everything on my local computer with a USB to UART converter and ran Klipper on the Raspberry PI. To do this, I had to forward the klipper socket to my local computer via SSH and configure the address of the Moonraker API:
Tip
Adjust the local path here /tmp/local_klippy.sock to your needs and the klipper path to wherever your klipper socket is created. (See Klipper socket API to find your socket path)
ssh -L /tmp/local_klippy.sock:/home/pi/printer_data/comms/klippy.sock pi@your.host.comThe protocol between the display and the Python program is partly controlled by commands, which I call J-Commands. These cause events on the display or are needed to confirm states. Here is a list of commands I was able to find:
J Commands: Documentation of all observed J-Commands
A Commands: Documentation of all observed A-Commands
Take a look at Sequence Diagrams for Visual representation of the communication. I have done my best to represent the communication between display and controller as a sequence diagram.
All diagrams are generated with sequencediagram.org
If you like, buy me a coffee





