rickseiden
Posts: 420
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 1:35 am

Hello,

I am trying to find any information on using a ili9341 TFT display with a Pi Zero W that is not about using the display as a "monitor" and not about using Python.

I am working on a project where the display will be used to show a menu system controlled with a rotary encoder (like on the Prusa i3 MK3). I would normally just use an LCD display for that, but I also need to be able to display a "preview" of the Pi Camera, which is why I need to use the TFT display. (The project won't have room for both the LCD and TFT displays, unfortunately.) So you can see I don't want to use it to display the desktop or the console. Almost every tutorial I've found online has been about using it as the main display for the desktop/console.

I used Adafruit's tutorials on setting up their display with Python, and that worked, but it took about a second for each change to show on the display. So the user would be turning the rotary encoder one click, then waiting a second before turning another click. This just won't work. That's why I am looking for some sort of C library. I know the SPI bus slows things down, but the tutorials about using the TFT display as the main display of the Pi do talk about refresh rates upwards of 60 fps, much higher than I need for my project. Everything I can find online that isn't a tutorial about using it as the main display is about using it with Python and most of them are about using it with Adafruit's library.

I have nothing against Python, and if there's a tutorial out there about using Python where it doesn't take a second to draw a rectangle on the screen, I'd be open to using that instead of C. I'm not really a Python programmer, and the only C type language I've used is in the Arduino IDE, so I'm going to be struggling either way, to be honest.

If anyone can point me in the direction of some resources I can use, I'd very much appreciate it.

Thanks!
There are 10 types of people in this world. Those that understand binary, and those that don't.

aBUGSworstnightmare
Posts: 2779
Joined: Tue Jun 30, 2015 1:35 pm

Re: ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 5:28 am

So this is connected via SPI, right?
Search the forum for 'Ilitek KMS'. There is some overlay + driver for some Ilitek based SPI displays which allows you to use it as a monitor.
viewtopic.php?f=63&t=306624&p=1834648&h ... 1#p1834648

Sorry, never bothered myself with SPI displays, so can't be of more help here.

rickseiden
Posts: 420
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 11:35 am

Thanks for your reply.

I can't believe I didn't mention that it was connected via SPI! Yes, it is connected via SPI.

That link you sent me to appears to be how to use the display as a second monitor. I don't want to use it as a monitor, I want to use it as a display, much in the way you would use a 16x2 LCD to display some text. I want to build a menuing system to display on there that could be displayed using a 16x2 or 16x4 LCD display, but I also want to be able to display images on it as well.
There are 10 types of people in this world. Those that understand binary, and those that don't.

aBUGSworstnightmare
Posts: 2779
Joined: Tue Jun 30, 2015 1:35 pm

Re: ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 11:47 am

rickseiden wrote:
Wed Apr 21, 2021 11:35 am
Thanks for your reply.

I can't believe I didn't mention that it was connected via SPI! Yes, it is connected via SPI.

That link you sent me to appears to be how to use the display as a second monitor. I don't want to use it as a monitor, I want to use it as a display, much in the way you would use a 16x2 LCD to display some text. I want to build a menuing system to display on there that could be displayed using a 16x2 or 16x4 LCD display, but I also want to be able to display images on it as well.
sorry, but I don't understand what prevents you from showing a console on that 'monitor'. Anyhow, good luck with your project.

rickseiden
Posts: 420
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 11:57 am

aBUGSworstnightmare wrote:
Wed Apr 21, 2021 11:47 am
rickseiden wrote:
Wed Apr 21, 2021 11:35 am
Thanks for your reply.

I can't believe I didn't mention that it was connected via SPI! Yes, it is connected via SPI.

That link you sent me to appears to be how to use the display as a second monitor. I don't want to use it as a monitor, I want to use it as a display, much in the way you would use a 16x2 LCD to display some text. I want to build a menuing system to display on there that could be displayed using a 16x2 or 16x4 LCD display, but I also want to be able to display images on it as well.
sorry, but I don't understand what prevents you from showing a console on that 'monitor'. Anyhow, good luck with your project.
There are two things that are stopping me for using it as a monitor and displaying the interface there. First, my Pi is setup in a headless configuration. That, of course, is easily fixable, and not really a reason not to do it that way. Second, if I use it as a monitor and not just some sort of little display, I have to build the interface that uses "normal" graphical programing techniques. Like creating a window, filling it with text, displaying radio buttons or checkboxes or buttons. All of that adds complexity to it that I'm trying to avoid. By using the TFT as a small display that I put text on similar to the way a 16x2 LCD is used, I'm avoiding all of the programming that comes with building a GUI based application.
There are 10 types of people in this world. Those that understand binary, and those that don't.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11018
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 12:19 pm

So what are you expecting to have the relevant character set in order for you to just feed your display with ASCII text?

An ILI9341 display is just an array of (typically) 240x320 pixels, so something has to write to that as video - it has no character set to render ASCII.

If you can arrange for it, then ncurses may allow you to program your menu system as simple ASCII text that it then renders to whatever terminal you need it displayed on.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

rickseiden
Posts: 420
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 3:06 pm

6by9 wrote:
Wed Apr 21, 2021 12:19 pm
So what are you expecting to have the relevant character set in order for you to just feed your display with ASCII text?

An ILI9341 display is just an array of (typically) 240x320 pixels, so something has to write to that as video - it has no character set to render ASCII.

If you can arrange for it, then ncurses may allow you to program your menu system as simple ASCII text that it then renders to whatever terminal you need it displayed on.
Thanks for your reply. I understand the display is just an array of pixels and I know I can't just send it ASCII text to the display. I'm hoping there is a library that out there that controls the display. I'm imaging a "Display" object. It might have functions like "begin", "drawRectangle" and "drawText". You'd pass parameters about the physical setup of the screen to the begin function, then use the drawRectangle and drawText functions to draw those things on the screen.
There are 10 types of people in this world. Those that understand binary, and those that don't.

rickseiden
Posts: 420
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: ili9341 TFT Display NOT used instead of HDMI in C

Wed Apr 21, 2021 6:08 pm

I found this in github: https://github.com/nopnop2002/Raspberry-ili9340spi

It looks promising, but I can't get it to work. I'm going to update this thread with my progress, if any, in case someone else comes along wanting to do the same thing.
There are 10 types of people in this world. Those that understand binary, and those that don't.

rickseiden
Posts: 420
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: ili9341 TFT Display NOT used instead of HDMI in C

Thu Apr 22, 2021 7:18 pm

I figured out what was wrong with that library. You have to run the compiled program using sudo. When I run it that way, I had no problems.

I suspect there's some permission I can grant to the pi user, or some group I can put the pi user in, but since this is a project only ever intended for me with no connection to the internet, I don't have a problem running it as sudo.
There are 10 types of people in this world. Those that understand binary, and those that don't.

Return to “HATs and other add-ons”