Skip to content

ESP32-S3 automatic printer head cleaner for Canon G3010. Sends maintenance print job via WiFi Direct every 3 days to prevent ink clogging. Built with Claude AI.

Notifications You must be signed in to change notification settings

msh2050/PrinterMonitorCleaner

Repository files navigation

Printer Monitor Cleaner - ESP32-S3

Automatic printer head maintenance system for Canon G3010 printer using ESP32-S3.

This application connects to a Canon G3010 printer via WiFi Direct and sends a maintenance print job every 3 days to prevent printhead clogging by printing 4x4cm color squares (Black, Yellow, Cyan, Magenta).

Features

  • WiFi Direct Connection: Connects directly to printer's WiFi Direct network
  • Raw TCP Printing: Sends print jobs via port 9100 (RAW protocol)
  • Deep Sleep: Sleeps for 3 days between print cycles to conserve power
  • SPIFFS Storage: Stores 825KB print file on internal flash
  • Boot Counter: Tracks total maintenance cycles in RTC memory

Hardware Requirements

  • ESP32-S3 development board
  • Canon G3010 (or similar G-series) printer with WiFi Direct enabled
  • USB cable for programming

Configuration

  1. Copy the config template:

    cp main/config.h.example main/config.h
  2. Edit main/config.h with your printer's WiFi Direct settings:

    • SSID: Found in printer's WiFi Direct settings
    • Password: Found in printer's WiFi Direct settings
    • IP Address: Usually 192.168.114.1 for Canon WiFi Direct
    • Port: 9100 (RAW TCP printing)

Note: Find your printer's WiFi Direct credentials by printing a network configuration page from your printer menu.

Project Structure

PrinterMonitorCleaner/
├── CMakeLists.txt                  # Main project config
├── partitions.csv                  # Custom partition table
├── sdkconfig.defaults              # Default configuration
├── README.md                       # This file
├── clean.prn                       # Print file (user provides)
└── main/
    ├── CMakeLists.txt              # Component config
    ├── config.h.example            # Config template (copy to config.h)
    ├── config.h                    # Your private config (gitignored)
    └── printer_cleaner_main.c      # Main application

Build Instructions

1. Prerequisites

Install ESP-IDF v5.0 or later:

# Follow official ESP-IDF installation guide
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/

2. Configure the Project

cd PrinterMonitorCleaner
idf.py set-target esp32s3
idf.py menuconfig

Verify in menuconfig:

  • Component config → ESP32S3-Specific → Check flash size matches your board
  • Partition Table → Should show "Custom partition table CSV"

3. Build the Project

idf.py build

4. Create SPIFFS Image with clean.prn File

The print file must be uploaded to the SPIFFS partition. Here's how:

Option A: Using spiffsgen.py (Recommended)

# Create a directory for SPIFFS contents
mkdir spiffs_data
copy clean.prn spiffs_data\

# Generate SPIFFS image (size: 0x1B0000 = 1769472 bytes)
python %IDF_PATH%\components\spiffs\spiffsgen.py 1769472 spiffs_data spiffs_image.bin --page-size 256 --block-size 4096

Option B: Manual file preparation

If you have the clean.prn file in the project root:

# Windows PowerShell
mkdir spiffs_data
copy clean.prn spiffs_data\
python $env:IDF_PATH\components\spiffs\spiffsgen.py 1769472 spiffs_data spiffs_image.bin --page-size 256 --block-size 4096

5. Flash Everything to ESP32-S3

Replace COMX with your ESP32-S3's COM port (e.g., COM3, COM4):

# Flash firmware, partition table, and SPIFFS in one command
idf.py -p COMX flash

# Flash SPIFFS partition separately
python %IDF_PATH%\components\esptool_py\esptool\esptool.py --chip esp32s3 --port COMX --baud 460800 write_flash 0x150000 spiffs_image.bin

Or use individual commands:

# Flash application and partitions
idf.py -p COMX flash

# Flash SPIFFS image to storage partition (offset 0x150000)
esptool.py --chip esp32s3 --port COMX --baud 460800 write_flash 0x150000 spiffs_image.bin

6. Monitor Serial Output

idf.py -p COMX monitor

Expected output:

I (xxx) PrinterCleaner: ========================================
I (xxx) PrinterCleaner: Printer Cleaner - Boot count: 1
I (xxx) PrinterCleaner: ========================================
I (xxx) PrinterCleaner: Wakeup was not caused by deep sleep (first boot or reset)
I (xxx) PrinterCleaner: Initializing SPIFFS
I (xxx) PrinterCleaner: Partition size: total: 1769472, used: 845824
I (xxx) PrinterCleaner: Print file found: /spiffs/clean.prn (size: 825436 bytes)
I (xxx) PrinterCleaner: Connecting to printer WiFi Direct...
I (xxx) PrinterCleaner: Connected to AP SSID:YOUR_PRINTER_SSID
I (xxx) PrinterCleaner: Got IP:192.168.114.xxx
I (xxx) PrinterCleaner: Sending print job to printer...
I (xxx) PrinterCleaner: Socket created, connecting to 192.168.114.1:9100
I (xxx) PrinterCleaner: Successfully connected to printer
I (xxx) PrinterCleaner: Print file size: 825436 bytes
I (xxx) PrinterCleaner: Sent 825436/825436 bytes
I (xxx) PrinterCleaner: Print job sent successfully! Total: 825436 bytes
I (xxx) PrinterCleaner: ✓ Print job completed successfully!
I (xxx) PrinterCleaner: Total maintenance cycles: 1
I (xxx) PrinterCleaner: Entering deep sleep for 259200 seconds (3 days)
I (xxx) PrinterCleaner: Going to sleep now...

How It Works

  1. Boot & Initialize: ESP32 wakes up (timer or first boot), initializes NVS and SPIFFS
  2. WiFi Connection: Connects to printer's WiFi Direct network
  3. TCP Connection: Opens socket to printer's port 9100
  4. File Transfer: Streams clean.prn file (825KB) in 4KB chunks
  5. Deep Sleep: Enters deep sleep for 3 days (259,200 seconds)
  6. Repeat: Wakes up after 3 days and repeats the cycle

Customization

Change Print Interval

Edit in main/printer_cleaner_main.c:

#define SLEEP_TIME_SECONDS      (3 * 24 * 60 * 60)  // 3 days

Examples:

  • 1 day: (1 * 24 * 60 * 60)
  • 1 week: (7 * 24 * 60 * 60)
  • 12 hours (testing): (12 * 60 * 60)

Change WiFi Credentials

Edit main/config.h (copy from config.h.example first):

#define WIFI_SSID               "YOUR_PRINTER_SSID"
#define WIFI_PASS               "YOUR_PRINTER_PASSWORD"
#define PRINTER_IP              "192.168.114.1"
#define PRINTER_PORT            9100

Use Different Print File

  1. Create your print file using Windows:

    • Design your page in Word/Paint
    • Print → Select Canon G3010
    • Choose "Print to File"
    • Save as clean.prn
  2. Verify file size:

    (Get-Item "clean.prn").Length / 1KB
  3. If larger than 1.5MB, increase SPIFFS partition in partitions.csv

Troubleshooting

SPIFFS Mount Failed

E (xxx) PrinterCleaner: Failed to mount or format filesystem

Solution: Make sure you flashed the SPIFFS image to 0x150000

Print File Not Found

E (xxx) PrinterCleaner: Print file not found: /spiffs/clean.prn

Solution:

  1. Create spiffs_data folder with clean.prn
  2. Generate SPIFFS image
  3. Flash to offset 0x150000

WiFi Connection Failed

E (xxx) PrinterCleaner: Failed to connect to SSID:YOUR_PRINTER_SSID

Solution:

  1. Verify printer WiFi Direct is enabled
  2. Check SSID and password are correct
  3. Make sure you're within range of printer

Socket Connection Failed

E (xxx) PrinterCleaner: Socket unable to connect: errno 113

Solution:

  1. Verify printer IP address (usually 192.168.114.1 for WiFi Direct)
  2. Test from PC first:
    Test-NetConnection -ComputerName 192.168.114.1 -Port 9100

Print Job Not Printing

Solution:

  1. Verify the print file works from PC:
    $bytes = [System.IO.File]::ReadAllBytes("C:\clean.prn")
    $client = [System.Net.Sockets.TcpClient]::new("192.168.114.1", 9100)
    $client.GetStream().Write($bytes, 0, $bytes.Length)
    $client.Close()
  2. Check printer has paper and ink
  3. Check printer display for errors

Power Consumption

  • Active (printing): ~80mA @ 3.3V for 20-30 seconds
  • Deep Sleep: ~10µA @ 3.3V
  • Average over 3 days: ~11µA (extremely low)

With a 1000mAh battery, the system can run for approximately 10+ years!

Testing

For quick testing, change sleep time to 1 minute:

#define SLEEP_TIME_SECONDS      60  // 1 minute for testing

Rebuild and flash to test the cycle without waiting 3 days.

License

MIT License - Free to use and modify

References

Support

For issues with:

  • ESP-IDF: ESP32 Forum
  • This project: Create an issue in your repository

Created for Canon G3010 printer head maintenance ⚙️🖨️

About

ESP32-S3 automatic printer head cleaner for Canon G3010. Sends maintenance print job via WiFi Direct every 3 days to prevent ink clogging. Built with Claude AI.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published