Since the Creality CR-6 SE does not have Wi-Fi or an early warning system to monitor the printer motions and status, I decided to create a device to track the printer's lateral and vertical motions while printing so as to get informed of potential malfunctions related to the printer movements:

To endow this device with the ability to track X-axis, Y-axis, and Z-axis movements, I decided to employ the HuskyLens AI camera to recognize tags (AprilTags) denoting the axis motion. Since I was trying to develop a budget-friendly IoT device, I decided to utilize Raspberry Pi Pico to obtain and transfer the detected printer movements by the HuskyLens AI camera. Although there are various methods to connect Raspberry Pi Pico to the Internet, I chose to use the Pico-compatible WIZnet Ethernet HAT utilizing W5100S Hardwired TCP/IP CHIP. Since my printer is very close to my router, I did not encounter any issues regarding connecting the Ethernet cable or positioning the device.

After connecting Raspberry Pi Pico to the Internet, I decided to utilize a Telegram bot to track the detected printer axis movements and get notified of malfunctions related to the printer motions. Since Telegram is a cross-platform cloud-based messaging service compatible with iOS and Android, the Telegram bot allows the user to monitor the printer movements and potential malfunctions on several devices. On Telegram, it is effortless to create bots with a command list unalike any other messaging application, which are special accounts that do not require an additional phone number to set up.

To be able to process the detected printer movements and send updates to the Telegram bot automatically, I developed a PHP web application. The web application obtains the printer movements from the Raspberry Pi Pico via HTTP POST requests, stores the received printer movements in the given MySQL database table, detects potential malfunctions related to the printer motions, and sends updates (also notifications) to the Telegram bot via the Telegram Bot API. After developing the web application, I employed a Raspberry Pi 3 to host a LAMP web server to run the application.

Lastly, to make the device as stylish and robust as possible while operating in my workshop, I designed a T-800 Terminator-inspired case with a removable top cover (3D printable).

🎁🎨 Huge thanks to DFRobot for sending me the HuskyLens AI Camera.

🎁🎨 Huge thanks to WIZnet for providing me with a WIZnet Ethernet HAT.

🎁🎨 Also, huge thanks to Creality3D for sponsoring a Creality CR-6 SE 3D Printer.

🎁🎨 If you want to purchase some products from Creality3D, you can use my 10% discount coupon (Aktar10) even for their new and most popular printers: CR-10 Smart,CR-30 3DPrintMill,Ender-3 Pro, and Ender-3 V2. You can also use the coupon for Creality filaments.

Step 1: Designing and printing a T-800 Terminator-inspired case

Since I wanted to place the device towards my FDM 3D printer while printing 3D models in my workshop, I decided to design a complementing metallic case to create a robust and sturdy mechanism operating flawlessly. To make device connections more accessible, I added a removable top cover to the case. Then, I got inspired by The Terminator to add a T-800 replica to the device since it aims to track the movements of the printer and detect potential malfunctions to eliminate them :)

I designed the main case and its removable top cover in Autodesk Fusion 360. You can download their STL files below.

For the T-800 replica affixed to the removable top cover, I utilized this model from Thingiverse:

Then, I sliced all 3D models (STL files) in Ultimaker Cura.

Since I wanted to create a solid structure for the metallic case with the removable top cover and emphasize the T-800 theme, I utilized this PLA filament:

Finally, I printed all parts (models) with my Creality CR-6 SE 3D Printer. Although I am a novice in 3D printing, and it is my first FDM 3D printer, I got incredible results effortlessly with the CR-6 SE :)

Step 1.1: Assembling the case and making connections & adjustments

First of all, I soldered female pin headers (11mm long legs) to the WIZnet Ethernet HAT and male pin headers to the Raspberry Pi Pico in order to connect them to the mini breadboard as shown below.

To recognize the learned tags (AprilTags) so as to track the printer motions (X-axis, Y-axis, and Z-axis), I connected the HuskyLens AI camera to the Raspberry Pi Pico by utilizing the I2C protocol. Also, I added a 10mm common anode RGB LED module (Keyes) and a buzzer to indicate the outcomes of operating functions.

Since the Raspberry Pi Pico operates at 3.3V, it is not able to power the HuskyLens AI camera and the RGB LED at the same time sufficiently. Therefore, I employed an external power source to supply the mentioned components: To elicit stable supply voltage, I connected a USB buck-boost converter board to a Xiaomi power bank.

After completing sensor connections and adjustments on mini breadboards successfully, I made the breadboard connection points rigid by utilizing a hot glue gun.

Then, after printing all 3D parts (models), I fastened all components to the main case and connected the LAN Ethernet cable from my router to the WIZnet Ethernet HAT.

Finally, I inserted the removable top cover in its slot on the main case and affixed the T-800 replica to the top of it via a hot glue gun. Also, I attached the HuskyLens AI camera to the case via a screw.

Step 2: Building a Telegram bot with BotFather

I utilized BotFather to create a Telegram bot for this project. BotFather is an official Telegram bot that lets the user create and manage bots on Telegram without any coding required.

#️⃣ First of all, open BotFather on Telegram and enter /start to view the available command list and manuals.

#️⃣ Use the /newbot command to create a new bot. Enter the name of your bot when BotFather asks you for a name. It is displayed in contact details and elsewhere.

IoT 3D Printer Movement and Status Tracker

#️⃣ Then, enter the username of your bot. Usernames are 5-32 characters long and are case insensitive but may only include Latin characters, numbers, and underscores. They must end in 'bot', e.g. 'tetris_bot' or 'TetrisBot'.

IoT_3D_printer_tracker_bot

#️⃣ After completing the steps above, BotFather generates an authorization token for your new bot. The authorization token is a string along the lines of 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 that is required to authorize the bot and send requests to the Telegram Bot API. Keep your token secure and store it safely.

#️⃣ Also, you can change your bot's profile picture by using the /setuserpic command.

#️⃣ Finally, to add a description to your bot to be displayed when the chat is initialized, use the /setdescription command.

Since I wanted to get only printer movements updates from the Raspberry Pi Pico, I did not need to establish an SSL connection to set a webhook for the Telegram Bot API to send information back to the web application.

However, I needed to obtain the chat id to be able to send updates to the Telegram bot via the Telegram Bot API directly without establishing an SSL connection or setting up a webhook.

To get the chat id, I utilized the getUpdates method, which shows incoming updates using long polling and returns an array of Update objects.

#️⃣ Navigate to this web page by using your bot's authorization token:

https://api.telegram.org/bot<_token_>/getUpdates

#️⃣ Then, send a message to your bot and refresh the page. It will display an object list, including the chat id:

chat ➡ id ➡ 1496498083

Step 3: Developing a web application in PHP to send updates to the bot via the Telegram Bot API

Inspect.

Step 4: Setting up a LAMP web server on Raspberry Pi

Since I decided to host my web application on a Raspberry Pi 3, I needed to set up a LAMP web server.

#️⃣ First of all, open a terminal window by selecting Accessories ➡ Terminal from the menu.

#️⃣ Then, install the apache2 package by typing the following command into the terminal and pressing Enter:

sudo apt-get install apache2 -y

#️⃣ After installing the apache2 package successfully, open Chromium Web Browser and navigate to localhost so as to test the web server.

#️⃣ Then, enter the command below to the terminal to obtain the Raspberry Pi's IP address:

hostname -I

#️⃣ To install the latest package versions successfully, update the Pi. Then, download the PHP package by entering these commands below to the terminal:

sudo apt-get update

sudo apt-get install php -y

#️⃣ To be able to send requests from the web server to the Telegram Bot API, install the php-curl package:

sudo apt-get install php-curl

#️⃣ Then, restart the apache server to activate the installed packages on the web server:

sudo service apache2 restart

Step 4.1: Creating a MySQL database in MariaDB

Since I needed to log previous printer movements so as to detect potential malfunctions related to the printer's lateral and vertical motions, I also set up a MariaDB server on the Raspberry Pi 3.

#️⃣ First of all, install the MariaDB (MySQL) server and PHP-MySQL packages by entering the following command into the terminal:

sudo apt-get install mariadb-server php-mysql -y

#️⃣ To create a new user, run the MySQL secure installation command in the terminal window:

sudo mysql_secure_installation

#️⃣ When requested, type the current password for the root user (enter for none). Then, press Enter.

#️⃣ Type in Y and press Enter to set the root password.

#️⃣ Type in bot at the New password: prompt, and press Enter.

#️⃣ Type in Y to remove anonymous users.

#️⃣ Type in Y to disallow root login remotely.

#️⃣ Type in Y to remove the test database and its access permissions.

#️⃣ Type in Y to reload privilege tables.

#️⃣ After successfully setting the MariaDB server, the terminal prints: All done! Thanks for using MariaDB!

#️⃣ Finally, to create a new database in the MariaDB server, run the MySQL interface in the terminal:

sudo mysql -uroot -p

#️⃣ Then, enter the recently changed root password - bot.

#️⃣ When the terminal shows the MariaDB [(none)]> prompt, create the new database (telegram3dprinter) by utilizing these commands below:

create database telegram3dprinter;GRANT ALL PRIVILEGES ON telegram3dprinter.* TO 'root'@'localhost' IDENTIFIED BY 'bot';FLUSH PRIVILEGES;

#️⃣ Press Ctrl + D to exit the MariaDB [(none)]> prompt.

Step 4.2: Setting and running the web application on Raspberry Pi

As discussed above, I set up a LAMP web server on my Raspberry Pi 3 to run the web application, but you can run it on any server as long as it is a PHP server.

#️⃣ First of all, install and extract the telegram_3D_printer_bot.zip folder.

#️⃣ Then, move the application folder (telegram_3D_printer_bot) to the Apache server (/var/www/html) by using the terminal since the Apache server is a protected location.

sudo mv /home/pi/Downloads/telegram_3D_printer_bot /var/www/html/

⭐ If the web application did not receive the printer movements from the Raspberry Pi Pico via an HTTP POST request, it prints: Waiting for new data...

⭐ Otherwise, the web application prints: Data Saved and Transferred to the Telegram Bot Successfully!

localhost/telegram_3D_printer_bot/

⭐ If the create_table parameter is set as OK, the web application creates the requested database table and inserts the default data items as the first row into the recently created table. Then, it prints:

Database Table Created Successfully!

Default Data Items Inserted Successfully!

localhost/telegram_3D_printer_bot/?create_table=OK

Step 5: Updating and setting up the HuskyLens AI Camera

HuskyLens AI camera is capable of transferring the detection results of its built-in functions via the UART (serial) or I2C protocol. I decided to utilize the I2C protocol since it is much easier to get information with the I2C protocol on the Raspberry Pi Pico.

However, before proceeding with the following steps, I needed to update the HuskyLens firmware with the latest version to get more accurate results.

#️⃣ After connecting the HuskyLens AI camera to the computer (Windows) via a micro USB cable, click the General Settings to view the version number.

#️⃣ Then, install the HuskyLens Uploader for Windows from here. If requested, you may need to install the CP2102N chip driver from here.

#️⃣ Search for the latest firmware version here, currently V0.5.3Alpha1, and download it.

#️⃣ Run the HuskyLens Uploader, a small black CMD window will pop up first, and after a while, the interface window will appear: Then, click the Select File button to upload the latest firmware file.

#️⃣ Finally, click the Upload button and wait about 5 minutes until the firmware is upgraded successfully.

After following the steps above, HuskyLens should display the upgraded version number on the settings menu.

Step 5.1: Detecting tags (AprilTags) w/ HuskyLens

After upgrading the firmware, I trained HuskyLens to learn three different AprilTags from the figure below for each printer axis (X-axis, Y-axis, and Z-axis) so as to track the printer's lateral and vertical motions.

#️⃣ First of all, switch to the Tag Recognition mode.

#️⃣ Since the default setting is to learn a single tag, long press the function button to open the parameter setting interface.

#️⃣ Then, switch to the Learn Multiple parameter and activate it.

#️⃣ Finally, save the settings and return to the Tag Recognition mode.

#️⃣ To learn a new tag (AprilTag), point the yellow + symbol to the selected tag and press the learning button. Then, release the learning button to complete learning the given tag.

#️⃣ To continue learning tags, short press the learning button before the countdown ends.

After training HuskyLens to learn tags (AprilTags) for each printer axis, I fastened each learned tag to my Creality CR-6 SE 3D printer's X-axis, Y-axis, and Z-axis without blocking its fans, sensors, or belts.

Step 6: Setting up Raspberry Pi Pico

Since I decided to program the Raspberry Pi Pico on Thonny, I needed to configure some settings and install MicroPython for Raspberry Pi Pico on Thonny.

#️⃣ First of all, download the latest Thonny IDE version, compatible with Windows, macOS, and Linux. If you are programming the Pico on Raspberry Pi, Thonny is already installed on the Raspberry Pi OS.

#️⃣ Then, find the BOOTSEL button on your Raspberry Pi Pico.

#️⃣ Press the BOOTSEL button and hold it while connecting the other end of the micro USB cable to your computer.

#️⃣ This puts the Raspberry Pi Pico into the USB mass storage device mode (Bootloader Mode).

#️⃣ Thonny should automatically open the installation screen. If not, at the bottom right-hand corner of the window, click on the Python version, choose Configure interpreter..., and select MicroPython (Raspberry Pi Pico).

#️⃣ Then, on the Interpreter Tab screen, click the Install or update firmware link.

#️⃣ When the dialog box pops up, click the Install button to copy the latest version of the MicroPython firmware to the Raspberry Pi Pico.

#️⃣ Wait for the installation to complete and click Close.

After completing the steps above, Thonny should recognize the board and firmware automatically when plugging the Raspberry Pi Pico to the computer without pressing the BOOTSEL button.

Step 6.1: Modifying CircuitPython libraries for Raspberry Pi Pico and the WIZnet Ethernet HAT

Since the WIZnet Ethernet HAT requires Adafruit CircuitPython libraries, I needed to set and configure CircuitPython on Thonny. Plausibly, Thonny has a built-in file transfer feature that makes copying files and libraries to the Raspberry Pi Pico very easy.

However, while working on this project, I encountered many bugs, errors, and incompatibilities regarding CircuitPython libraries. Therefore, I had to modify nearly all libraries and files to rectify the occurring issues and bugs.

Below, I will explain how to set CircuitPython and fix the mentioned issues and bugs step by step. But, you can download the lib.zip folder and copy the lib folder directly to your Raspberry Pi Pico without replicating the steps below.

#️⃣ First of all, download the latest versions of Blinka and PlatformDetect modules to run CircuitPython libraries on MicroPython.

#️⃣ To install the PlatformDetect module to the Raspberry Pi Pico, copy the adafruit_platformdetect folder and upload it to the Pico under the lib folder.

#️⃣ To install the Blinka module to the Raspberry Pi Pico, copy everything inside the src folder and upload those files to the Pico under the lib folder.

#️⃣ To free up some space, remove the unnecessary files under the adafruit_blinka folder before uploading modules to the Pico.

#️⃣ To run the WIZnet Ethernet HAT, download the adafruit_bus_device and adafruit_wiznet5k libraries. Then, upload these libraries to the Pico under the lib folder.

#️⃣ If Thonny throws attribute errors like below, change the monotonic function with the ticks_cpu function in all files under the adafruit_wiznet5k folder.

Traceback (most recent call last):  File "", line 49, in   File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 188, in __init__AttributeError: 'module' object has no attribute 'monotonic'Traceback (most recent call last):  File "<stdin>", line 55, in <module>  File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 199, in __init__  File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 219, in set_dhcp  File "/lib/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py", line 491, in request_dhcp_lease  File "/lib/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py", line 363, in _dhcp_state_machineAttributeError: 'module' object has no attribute 'monotonic'

#️⃣ If Thonny throws an error regarding allocation, set the MAX_PACKET bytes to 3500 or lower in the adafruit_wiznet5k.py file under the adafruit_wiznet5k folder.

Traceback (most recent call last):  File "<stdin>", line 50, in <module>  File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 176, in __init__MemoryError: memory allocation failed, allocating 4000 bytes

#️⃣ To make HTTP requests to a given web application with the WIZnet Ethernet HAT, download the adafruit_requests library. Then, upload the adafruit_requests.py file to the Pico under the lib folder.

Since the latest versions of the adafruit_requests library are not working with the adafruit_wiznet5k library, I utilized the 1.8.1 version in this project.

Also, I needed to modify the adafruit_requests.py file to disable checking for the server response since it causes timeout errors on Thonny.

After configuring module folders and modifying library files, I saved all required folders and files under the lib folder. Then, I uploaded the lib folder to the Raspberry Pi Pico via the built-in file transfer feature on Thonny.

Step 6.2: Reading results generated by HuskyLens with Raspberry Pi Pico

Since HuskyLens does not provide an official library for the Raspberry Pi Pico, I modified these functions to obtain tag recognition results from HuskyLens via the I2C protocol.

After modifying the functions, I uploaded them under the huskylib.py file to the Pico.

Then, I was able to get the learned blocks with IDs generated by HuskyLens for each detected tag (AprilTag) and process them to derive tag coordinates (tag positions).

#️⃣ When saving code files to the Raspberry Pi Pico, click the Save button and choose the Raspberry Pi Pico option on Thonny.

Step 7: Programming Raspberry Pi Pico

Inspect the code.

Modes and Features

🌐🤖 If the WIZnet Ethernet HAT connects to the router via the Ethernet interface without DHCP, the device turns the RGB LED to blue.

🌐🤖 If HuskyLens recognizes three tags (AprilTags) for each printer axis in the same frame, the device turns the RGB LED to yellow.

🌐🤖 Then, if the WIZnet Ethernet HAT transfers tag coordinates (positions) for X-axis, Y-axis, and Z-axis to the PHP web application via an HTTP POST request successfully, the device turns the RGB LED to green and activates the buzzer to notify the user.

🌐🤖 After completing the first HTTP POST request successfully, the device turns the RGB LED to magenta as the default color.

🌐🤖 When the web application receives the current printer movements (tag positions), it compares them to the previous printer movements stored in the database table to detect potential malfunctions related to the printer motions.

🌐🤖 Then, the application sends the current printer movements with a schematic describing 3D printer motions to the given Telegram bot via the Telegram Bot API.

🌐🤖 If the web application detects potential malfunctions on X-axis, Y-axis, or Z-axis, it adds notification messages to the transferred update up to two axes.

⚠️ X-Axis: Potential Malfunction Detected!

⚠️ Y-Axis: Potential Malfunction Detected!

⚠️ Z-Axis: Potential Malfunction Detected!

🌐🤖 If the web application detects malfunctions on three axes, it adds this notification message to the transferred update:

⛔ 3D Printer is not working!

🌐🤖 Also, the device prints notifications and the detected printer movements (tag positions) on the shell for debugging.

As far as my experiments go, the device works impeccably while tracking the printer movements and informing me of potential malfunctions related to the printer motions :)

Videos and Conclusion