Dot Matrix Pen Write Screen

Dot Matrix Pen Write Screen

In the current market where capacitive touch screens, resistive touch screens, TFT displays are flooding, DIY enthusiasts have been rarely used dot matrix screens. Here we use 5mm 8 * 8 dot matrix screen and phototransistor to achieve a pen write function. Sounds fun? But how to specifically make it? Can we achieve a larger area pen write? Just read on to know.

Dot Matrix, Pen Write Screen, LED

I. Target

To realize pen write on dot matrix.

II. Hardware

LED matrix, UNO, flowerpad, 74ls138, PNP transistor, LM358, photosensitive triode, resistors (22K, 1K), pins

III. Circuit

The project is mainly composed of three parts: row scan circuit, column scan circuit, the pen’s circuit. The principle block is as shown below. It has a photosensitive sensor in the pen, we use this pen to get the states of LED. circuit, MCU, row scan circuit, column scan circuit, the pen’s circuit 


1. Row scan 

Make decoder’s Y0, Y1…effective in turn, but 74ls138 output low level on corresponding pin if have a effective input, because our dot matrix is common anode, we need an inverter, we use PNP transistor to constitute a inverter. Every eight times column scanning on a row scan.

2. Column scan

Make decoder’s Y0, Y1…effective in turn, and input PWM on OE1, if OE1 is high level, Y0~Y7 are high level,if OE1 is low level, ABC pin decide decoder’s output. When enable some line, we make decoder’s Y0, Y1…effective in turn, and we can control every LED’s brightness by OE1.

3. Pen

Set the reference voltage at the inverting input of comparator at a certain value, and in-phase input voltage will be less than this value when the pen receives light, vice versa. The current through R3 is very small if light is insufficient, so in-phase input voltage will be closer to the power supply voltage, and comparator outputs high level. The current through R3 will increase if light intensity increases, and the voltage of R3 will increase, so in-phase input voltage will decrease, then comparator outputs low level. MCU can catch this change and then does the corresponding processing.

IV. Program Analysis

To detect state of the points on the dot matrix we must light LED, and make it in the dim state, when the pen gets close to some point, we set the point highlight. But how do we know the coordinates of this point? The principle is: let LED light up one by one,the first of the first line, then the second of the first line…, until the last of the first line. Turn again the first of the second line, light up LED in turn in a loop. Every LED has state value: 0 stands for the dim state, 1 stands for highlight state. When the pen gets close to some point but it’s not the point’s turn to light up, because the pen did not detect light,it maintains a high level at the output of the comparator. When it’s turn to light up this point, comparator outputs a low level, MCU executes interrupt program when it detect a level change, and gets value of current row and column, then set state that find the point by value of row and column of 1, and set it to highlight state when it’s lighted up next time. We see the whole dot matrix light up when increasing scanning speed, rather than one by one.

V. Reference Program

#include <interrupt.h>

#define COL 1

#define ROW 2

int col = 0;                   //mark current column

int row = 0;                  //mark current row

int ledState[8][8];         //mark current led’s state


haveUpdate used to eliminate jitter of input, it will update data when obtains extern interrupt program, 
and set haveUpdate to 1 stand for we have updated data already, 
then open timer and  ignore extern interrupt signal or do nothing in interrupt program during this time, 
CPU set haveUpdate to 0 when time’s out in timer interrupt program.


int haveUpdate = 0;

void setup()


memset(ledState, 0, sizeof(ledState));              //clear state of all led


TCCR2A = _BV(COM2A0) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20);

TCCR2B = _BV(WGM22) | _BV(CS20);  //no divide

OCR2A = 100;

OCR2B = 99;                                             //duty is 99%

attachInterrupt(0, externInterrupt, FALLING );

cli();                                              //disable all interrupt

TCCR1A=0;                                 //we need no set TCCR1A because it is apply to pwm

TCCR1B=(1<<CS12)|(1<<CS10);       //1/ 1024 divide

TCNT1=0xFE79;                          //25ms

TIMSK1 = 0;                                 //close overflow interrupt

sei();                                             //enable interrupt


ISR(TIMER1_OVF_vect){                //timer interrupt program

TIMSK1 = 0;                                 // close overflow interrupt

haveUpdate = 0;


void loop()




void externInterrupt()


if(haveUpdate == 0){

ledState[row][col] = 1;

haveUpdate = 1;


TIMSK1 = (1<<TOIE1);



void initPort()


int i, startPin = 4;

for(i=0; i<10; i++){

pinMode(startPin+i, OUTPUT);


setData(COL, 0x00);

setData(ROW, 0x00);

pinMode(3, OUTPUT);


void setData(int flag, int data)


int i, startPin;

if(COL == flag){

startPin = 4;


startPin = 7;


for(i=0; i<3; i++){

digitalWrite(startPin+i, (data & (1<<i))? HIGH:LOW);



void scan()


for(row=0; row<8; row++){

setData(ROW, row);

for(col=0; col<8; col++){

setData(COL, col);

if(ledState[row][col] > 0)

OCR2B = 1;


OCR2B = 98;


OCR2B = 98;




VI. Problems Encountered

1. Line scan chip is 74 ls138 (decoder). It has used three IO ports. if you need a larger dot matrix, such as 16 * 16 dot matrix screen, you need four IO ports. So I hope I can use the other chip to replace it to save IO port, such as 74 ls164 (shift register). Because no matter how large dot matrix is, we only needs two IO port. And for a common anode or a common cathode dot matrix, they don't need extra circuit, for example, using 74 ls138 for a common anode dot matrix needs to increase the inverter. Do you have any good idea? Let’s research this problem together.

2. Column scan chip is also74ls138. We didn't use the decoder function, but used it as a data distributor. It can output a PWM signal to pin which is determined by the address. Thus, we can adjust every LED’s brightness. In fact, we can also use 74 ls595 (shift register) to implement, it can save a lot of IO port. If you have a better idea hope you can share with us.

3. The pen’s photosensitive sensor is photosensitive triode. Because we didn’t buy photosensitive triode before, we used photosensitive resister to have a test in the early period and later we bought photosensitive triode. And after using photosensitive to test, we found that the stability of photosensitive was not as good as photosensitive triode, and not as speed as photosensitive triode. Another reason is photosensitive can magnify current, so it’s more noticeable when lightness changes, making it better to deal with the signal. It is very important to remove interference, for example, we use two comparators to limit the input voltage, making it only useful within the specified range. When the light is too strong or too weak, it may produce interference. We output two comparators as input of an AND gate, and output AND gate as extern interrupt input of MCU. Because we did not find an AND gate chip during the test, we used triode to build an AND gate. But it was unstable, so we only have to use one comparator. We would like to ask if this method of using two comparators is workable. Also want you to give us some other methods of removing interference.

Dot Matrix Pen Write Screen, UNO, flowerpad   Dot Matrix Pen Write Screen, UNO, flowerpad   Dot Matrix Pen Write Screen, UNO, flowerpad   Dot Matrix, Pen Write Screen, LED