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 3Basic Code Routines

What I wanted to do was read out the ROMs from the ink carts and then use those to try and emulate the missing ink cartridge I don’t have. This means creating a library that will act as a host to read the data but can also be used to emulate an ink cartridge.
Using previous knowledge from creating software based protocols, I created a header file with these functions:
• extern void epsnCartInit(void);
• extern void epsnCartStart(unsigned char addr, unsigned char write);
• extern void epsnCartStop(void);
• extern void epsnCartWrite(unsigned char data);
• extern unsigned char epsnCartRead(void);

I also created the following definitions that help with remembering which pin was what:
For you microcontroller, you will need to modify these values to suit your application

#define _ecSCKTRIS TRISCbits.TRISC0
#define _ecSDATRIS TRISCbits.TRISC1
#define _ecRSTTRIS TRISCbits.TRISC2
#define _ecVDDTRIS TRISBbits.TRISB1

#define _ecSCKLat LATCbits.LATC0
#define _ecSDALat LATCbits.LATC1
#define _ecRSTLat LATCbits.LATC2
#define _ecVDDLat LATBbits.LATB0

#define _ecSCK PORTCbits.RC0
#define _ecSDA PORTCbits.RC1
#define _ecRST PORTCbits.RC2
#define _ecVDD PORTBbits.RB1

#define wait() DelayUS(50)


Note: I used a PIC18F and used Latches for setting the outputs, it’s just my preference in choice. You’re welcome to use any microcontroller you’re familiar with.

void epsnCartInit(){
    _epsnCartSCKTRIS = 0;
    _epsnCartSDATRIS = 0;
    _epsnCartRSTTRIS = 0;
    _epsnCartVDDTRIS = 0;

    _epsnCartSCK = 0;
    _epsnCartSDA = 0;
    _epsnCartRST = 0;
    _epsnCartVDD = 0;

    _epsnCartSCKLat = 0;
    _epsnCartSCKLat = 0;
    _epsnCartSCKLat = 0;
    _epsnCartSCKLat = 0;
}


The start function pulls VDD high, waits, then sets SDA according to the address bit as well as SCK. Waits, pulls SCK low, waits yet again and then pulls SDA high accordingly to the address. This repeats 2 more times except on the 4th time, SDA is set Low because we want to read the data in the EEPROMs not write.

void epsnCartStart(unsigned char addr,unsigned char write){
    char i = 0; // Used for counting

     char tmp = 0; // Temp storage variable

    _ecVDDLat = 1; // Set VDD High
     DelayMS(1); // Wait for the EEPROMs to get ready
     _ecRSTLat = 1; // Enable the EEPROMs for communication

     tmp = addr; // Copy the address into the temp variable
     if(write){ // If we want to write
         temp |= 0x08; //set the 4th bit high ( ‘|’ means OR )
     }  

     while(i<4){
         _ecSDALat = (tmp&0x01); // Set SDA High or Low according to the LSB

         wait(); // Wait roughly 50uS
         _ecSCKLat = 1; // Set Clock High
         wait(); // Wait another 50uS
         _ecSCKLat = 0; //Set Clock Low
         wait(); // Wait another 50uS
         tmp>>=1; //Right shift all the bits in tmp by one
         i++; // increment the counter by one
     }

}

The next function to implement is stop:
void epsnCartStop(){
     _ecRSTLat = 0; //Set RST low
    DelayMS(1); //Wait a bit
     _ecVDDLat = 0; //Turn off the EEPROMS
}


And finally the read function:
unsigned char epsnCartRead(){
     char i=0;
    char temp = 0x00;

    while(i<8){
        temp>>=1; // Right shift the temp variable by one
        _ecSCKLat = 1; //set SCK High
        wait(); //Wait roughly 50uS
        if(_ecSDA){ // If SDA is high
            temp |= 0x80; // Then set bit 7 high
        }
        _ecSCKLat = 0; // Bring SCK low again
        wait(); //wait another 50uS

        i++; // Increment the counter by 1
    }
    return temp; // Return what we have read
}


We now have the basic functions that we need to read data from the ink cartridges, lets set up our microcontroller and set the results.

« Previous StepDownload PDFView All StepsNext Step »
1 comment
Mar 28, 2011. 11:54 AMdn_nguoiban says:
hi!

I'm a student . now i am begin to do my project about 3d printing.i have very much difficult about printer head.I try to search information, how to control print head .but i don't see. fortunately, to day i written your project.I found very interesting. i hope you can shared for me about your experience,tell me more than information about your project.
and please give me some document to
tranngoclinh.cdt@gmail.com.


thanks you very much.

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 »