3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Reverse Engineering to Emulate Ink Cartridges for a Epson Printer

Step 5Implementing Our Library

Now we want to include the library we created for interfacing the microcontroller to the ink cartridge.

At the top of the file add:
#include "epsnCart.h" // the name of the header file we created earlier

Since this microcontroller is pretending to be the host, it's controlling the SCK, SDA and RST signals. so make sure they're outputs, add this with the other TRIS registers inside main():

epsnCartInit();

The next bit of code is what I used inside of the while(1) {
It requests an address starting at 0x00 then increments by one after 32 read bytes:

void main(){
    char addr = 0, i = 0;
    char string[40];
   
    ...
    epsnCartInit(); // Initialised the pins used

    while(1){ // Loop forever!

        sprintf(string, "Reading cartridge with addr: 0x%02X\r\n",addr);
        putsUSART(string); // prints a messge like: Reading cartridge with addr: 0x03


        epsnCartStart(addr,0); // Start by sending the address in read mode
       
        i = 0;
        while(i<32){ // keep looping until i is no longer less than 32
            sprintf(string,"0x%02X,",epsnCartRead());
            putsUSART(string);
            i++;
        }

        epsnCartStop(); //brings RST back low

        putrsUSART("\r\n");

        addr++
        if(addr>7){
            addr = 0;
        }
        DelayMS(500);
    }
}


You're probably looking at the line "sprintf(string,"0x%02X,",epsnCartRead());" and going "Huh?"
sprintf is a string formatting function, much like printf except saves the formatted string into the variable string.
"0x%02X," will return a string with a readable hexadecimal value eg: 0xFE and epsnCartRead() returns a value that was read from the ink cart

This was set up with a 3.3V power supply because the ink cartridges run on 3.3Volts

I programmed this to my microcontroller, disconnected the print head from the printer to prevent interference.
I then plugged in the 3 ink cartridges I had and turned it on.

Note: At this point, if you ran this code for the first time, I would expect you have problems. Like me, I've gone over the code dozens of times, changing it here and there to make it work. It's normal if it doesn't work the first time for you. It's a great learning experience figuring out what went wrong! :P
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
5
Followers
2
Author:NZSmartie
I'm currently studying at Massey University in New Zealand. I'm doing Computer and Electrical Engineering which is a fun course and already proving my skills to professors around the campus. I enjoy ...
more »