interrupts and tft

Hello

i am using the adafruit ili9341 libary with my display and have a switch connected to a pin on the arduino to interrupt the arduino of drawing bitmaps.
Now am i continously writting bitmaps to the display and it needs to check the button for presses and when pressed do fillscreen.
It takes 3 seconds to draw a bitmap.
But after each bitmap is drawd on the display it checks for button press.
So when i press the button when a bitmap isnt completly drawed on the display it doesnt do fillscreen.
So i think when i use interrupts to interrupt the bitmap drawing to fill the screen that it should work.
But i dont know exactly how to do it and if it is possible.
i tried to do this in setup

attachinterrupt(2, do_fill, LOW);

And make a function for it

void do_fill()
{
tft.fillscreen(ili9341_blue);
}

but it doesnt work.
when i try it gives white screen.
and when i remove the attachinterupt function it starts drawing bitmaps but the button doesnt work.
can any help my?
Or is there another way to do what i want?

Thanks

You misunderstand what "interrupts" are. Common "newbie" mistake.

Interrupts are not a mechanism to change the operation of your currently executing function, in fact, they are specifically designed in order not to affect the current process.

You need to write a version of the function - in this case tft.fillscreen() - which breaks the operation up into smaller steps, and in between each of these smaller steps, performs the check to see whether the operation is to be aborted, and if it is aborted, the new function needs to return a value indicating that this has happened so that the calling program can take the appropriate action.

There is no other way to make this happen.

1 Like

Paul__B:
You misunderstand what "interrupts" are. Common "newbie" mistake.

Yea, i dont know much about it.

If i correctly read your post it isnt made to stop one thing and do another.

but i think i found a way to do it.
if a var is 1 then do all the bitmap drawing.
and if it is 0 then do fillscreen.
I make a function to set the var to 0 and do in setup

attachInterrupt(2, function_to_set_var_to_0, LOW);

Should this work?

?

Well, you don't need an interrupt.

Just read the switch at the point in the main code where you need to make the decision.

How much easier could it be?

But if a function takes 7 seconds to complete?
than if i press the button at the begin of that function i need to press it 7 seconds
And i dont want that.

so will what i said in this pos work?:

leds_are_cool:
Yea, i dont know much about it.

If i correctly read your post it isnt made to stop one thing and do another.

but i think i found a way to do it.
if a var is 1 then do all the bitmap drawing.
and if it is 0 then do fillscreen.
I make a function to set the var to 0 and do in setup

attachInterrupt(2, function_to_set_var_to_0, LOW);

Should this work?

leds_are_cool:
But if a function takes 7 seconds to complete?

Rewrite it properly.

But CAN i use interrupts for it?
Will it work?

How do you draw your bitmap? Post the sketch.

Btw. your 3 seconds to draw an image are a bit on the long side. I can draw a fullscreen image in 1 second with my lib (SdFatTftBitmap example sketch).

I draw my bitmaps with the function from the example draw bitmap sketch from the ili9341 lib.

I haven't seen it in a while but I presume there is a loop where bytes/pixel color are read into a buffer from SD card and then pushed to TFT (IIRC it's the pushColors function). So in that loop add a check for a variable like "buttonPressed" and if it's set to 1 then exit the loop. When the button is pressed set buttonPressed to 1 in the interrupt handler. Drawing of the image will be interrupted and you will be back in your main loop() function where you can again check for buttonPressed, if it's 1 then fill the screen and set buttonPressed to 0.
So again, at the beginning buttonPressed is 0. Your image starts to draw, you press the button, interrupt handler will set it to 1, pixel drawing loop which draws the image is exited and you're back in the main loop() where you check for buttonPressed which is still set to 1 and so you fill the screen and set buttonPressed to 0.

Yea i can use that but i later wanna add some other functions.
but i dont want to edit all that functions.
so can i do the thing i said in this post:?

leds_are_cool:
but i think i found a way to do it.
if a var is 1 then do all the bitmap drawing.
and if it is 0 then do fillscreen.
I make a function to set the var to 0 and do in setup

attachInterrupt(2, function_to_set_var_to_0, LOW);

Should this work?

It is pretty irrelevant whether you use an interrupt or not if you want an immediate result. Yes, if you use an interrupt to "remember" that a button was pressed whilst an un-stoppable process executes, then you can do something else later, once that process is completely finished.

But if you want a "real time" response, you must use only processes which do or can be made to execute in such fractions of a second which then also allow you to poll your button in between steps. If there are other functions you wish to add, then either you implement the same discipline for all, or you will be most disappointed in the long run.

leds_are_cool:
Hello

i am using the adafruit ili9341 libary with my display and have a switch connected to a pin on the arduino to interrupt the arduino of drawing bitmaps.
Now am i continously writting bitmaps to the display and it needs to check the button for presses and when pressed do fillscreen.
It takes 3 seconds to draw a bitmap.
But after each bitmap is drawd on the display it checks for button press.
So when i press the button when a bitmap isnt completly drawed on the display it doesnt do fillscreen.
So i think when i use interrupts to interrupt the bitmap drawing to fill the screen that it should work.
But i dont know exactly how to do it and if it is possible.
i tried to do this in setup

attachinterrupt(2, do_fill, LOW);

And make a function for it

void do_fill()

{
tft.fillscreen(ili9341_blue);
}



but it doesnt work.
when i try it gives white screen.
and when i remove the attachinterupt function it starts drawing bitmaps but the button doesnt work.
can any help my?
Or is there another way to do what i want?

Thanks

If you are using Uno - the attachInterrupt interrupt assignment parameters are 0 and 1 , NOT pin numbers.

I would check the fiilscreen itself to find out if in fact it is the software and not the hardware ( TFT controller) which is blocking YOUR code flow.
Maybe you could make the fillscreeen read the button ( input ) if it is blocking.

But if i make the fillscreen read the button then it again checks only when that function is called and still cant press a button when a function is doing somthing becouse it only checks when fillscreen is called.
Now my idea was to use interupts.
so can i use a interrupt for it?

and somthing i realy wanna know is when i do attachinterrupt to check for the button and press the button and then for example it will turn a led on will after it has done that will it continue with what it was doing?

And another strange thing is that my tft keeps white when do attachinterrupt.
when i remove attachinterrupt the screen works.
and i am curruntly using arduino due and so far i know it can do intrrrupts on all pins.

and my software is blocking becouse i need to read a file from sd what contains about 3000 lines!!!!!
and it needs to print it in serial.
that is one of the things that is blocking.

and fillscreen isnt blocking but other functions.
fillscreen may take its time to complete but for other fuctions i think i need interrupts.

leds_are_cool:
But if i make the fillscreen read the button then it again checks only when that function is called and still cant press a button when a function is doing somthing becouse it only checks when fillscreen is called.
Now my idea was to use interupts.
so can i use a interrupt for it?

and somthing i realy wanna know is when i do attachinterrupt to check for the button and press the button and then for example it will turn a led on will after it has done that will it continue with what it was doing?

And another strange thing is that my tft keeps white when do attachinterrupt.
when i remove attachinterrupt the screen works.
and i am curruntly using arduino due and so far i know it can do intrrrupts on all pins.

and my software is blocking becouse i need to read a file from sd what contains about 3000 lines!!!!!
and it needs to print it in serial.
that is one of the things that is blocking.

and fillscreen isnt blocking but other functions.
fillscreen may take its time to complete but for other fuctions i think i need interrupts.

So you are OK using PIN 2 as interrupt on Due.
Let's clarify "serial" - Serial class or SPI /I2W , assuming you read from SD using SPI /I2W 3000 lines (to write bitmap ?) of code should not take 3 seconds - just wild guess.

How do you write to TFT ( fillScreen) - parallel data or SPI/ I2W?

Does fillScreen return value?

Your code indicate it does not or you are not using it - bad practice when hardware is involved.

I'll check the fillScreen myself soon to see where is the timing bottleneck.

If the timing is in software you could use interurrpt, in hardware - very unlikely.

PS My TFT has " T_IRQ" signal but I have not checked what it is for , not yet.
Probably touch interrupt which would probably work as good as your button as long as you / we can figure out how to interrupt the bitmap paint process.

I write to screen via spi.

Fillscreen doesnt return anything if i look in the libary code.

The timing is in software becouse i see 2 times a for loop.
or do i misunderstand you?

My tft also have a pjn called t_irq it is for touch.

fillscreen function from lib:

void Adafruit_ILI9341::fillScreen(uint16_t color) {
 fillRect(0, 0, _width, _height, color);
}

As you see it just does fillrect.

Link to the fillscreen and fillrect functions:(the .c file from libary)
https://raw.githubusercontent.com/adafruit/Adafruit_ILI9341/master/Adafruit_ILI9341.cpp

So can i use interrupts?
becouse if it is possible most of my problems are solved.
And i want to add much more functions so i think it is the best option.

leds_are_cool:
I write to screen via spi.

Fillscreen doesnt return anything if i look in the libary code.

The timing is in software becouse i see 2 times a for loop.
or do i misunderstand you?

My tft also have a pjn called t_irq it is for touch.

fillscreen function from lib:

void Adafruit_ILI9341::fillScreen(uint16_t color) {

fillRect(0, 0, _width, _height, color);
}



As you see it just does fillrect.

Link to the fillscreen and fillrect functions:(the .c file from libary)
https://raw.githubusercontent.com/adafruit/Adafruit_ILI9341/master/Adafruit_ILI9341.cpp

So can i use interrupts?
becouse if it is possible most of my problems are solved.
And i want to add much more functions so i think it is the best option.

leds_are_cool:
I write to screen via spi.

Fillscreen doesnt return anything if i look in the libary code.

The timing is in software becouse i see 2 times a for loop.
or do i misunderstand you?

My tft also have a pjn called t_irq it is for touch.

fillscreen function from lib:

void Adafruit_ILI9341::fillScreen(uint16_t color) {

fillRect(0, 0, _width, _height, color);
}



As you see it just does fillrect.

Link to the fillscreen and fillrect functions:(the .c file from libary)
https://raw.githubusercontent.com/adafruit/Adafruit_ILI9341/master/Adafruit_ILI9341.cpp

So can i use interrupts?
becouse if it is possible most of my problems are solved.
And i want to add much more functions so i think it is the best option.

So can i use interrupts?

Still do not have a clue what can be interrupted.
I'll need to check the function fillrect

Can you humor me and try this?

get current time
run fillScreen
get end time
what is the elapsed time ?

Filscreen takes 0.7 seconds to complete.
but why? Do you need this?

leds_are_cool:
Filscreen takes 0.7 seconds to complete.
but why? Do you need this?

leds_are_cool:
Filscreen takes 0.7 seconds to complete.
but why? Do you need this?

For two reasons - I want to know where does the 3 seconds (delay) writing to LCD came from.
So far interrupting .7 seconds does not seem to be worth the effort.
Can you time some other "writing" process - we are still missing over 2 seconds somewhere.
But in the meantime lets assume we will interrupt filllScreen.

I which I could help you more , but I am still waiting for some hardware to get my TFT going.
Stand by.