User avatar
HermannSW
Posts: 1569
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Raspberry Pi Zero and ILI9341 320x230 TFT

Thu Aug 18, 2016 10:25 pm

I wanted to get my 2.2" Serial SPI TFT Color LCD Modules (ILI9341 320x240) running on Raspberry Pi Zero.

I tried "User-space SPI TFT Python Library - ILI9341" first:
https://learn.adafruit.com/user-space-s ... w?view=all
Although I followed the described steps exactly I failed always on missing "SPI.py" ... :-(

I already new of framebuffers, and then read chapter "TFT 2.4" 320x240 – TJCTM24024-SPI" of Kolban's book. That provided all information needed. It turned out that all is available in Raspbian already and just needs to be turned on.

First the framebuffer device needs to be enabled, Kolban proposed to use rpi-display for ILI9341 displays:

Code: Select all

[email protected]:~ $ sudo modprobe fbtft_device name=rpi-display gpios=reset:23,dc:24,led:18 rotate=90
[email protected]:~ $
This gets logged:

Code: Select all

$ dmesg
...
...
[  703.864352] fbtft_device: module is from the staging directory, the quality is unknown, you have been warned.
[  703.870840] spidev spi0.1: spidev spi0.1 500kHz 8 bits mode=0x00
[  703.870917] bcm2708_fb soc:fb: soc:fb id=-1 pdata? no
[  704.184479] graphics fb1: fb_ili9341 frame buffer, 320x240, 150 KiB video memory, 16 KiB DMA buffer memory, fps=20, spi0.0 at 32 MHz
[  704.184566] fbtft_device: GPIOS used by 'rpi-display':
[  704.184581] fbtft_device: 'reset' = GPIO23
[  704.184591] fbtft_device: 'dc' = GPIO24
[  704.184599] fbtft_device: 'led' = GPIO18
[  704.184618] spidev spi0.1: spidev spi0.1 500kHz 8 bits mode=0x00
[  704.184633] fb_ili9341 spi0.0: fb_ili9341 spi0.0 32000kHz 8 bits mode=0x00
$ 
This was the result of first rudimentary playing with /dev/fb1 (create picture from nothing):

Code: Select all

$ sudo tail --bytes 153600 /var/log/messages > /dev/fb1
$ yes | head --bytes 76800 > /dev/fb1
$
Image

Next I took the giraffe.565 sample 16bit picture from my favorate Arduino Due DMA high speed ILI9341_due library SD card sample:

Code: Select all

$ tail --bytes 153600 giraffe.565 > /dev/fb1
$
Image


Next steps will be to get console displayed on 320x240 TFT, the trigger for me in trying to get TFT running with Pi Zero was this cool youtube video I found yesterday -- I have never seen a X session on a 320x240 display, wow!
https://www.youtube.com/watch?v=fPTaWHc ... e=youtu.be
Image


Oops, that is quick -- 200 frames in 5.090s is 39.3 frames per second!

Code: Select all

[email protected]:~ $ time ( for((i=0; i<100; ++i)); do tail --bytes 153600 giraffe.565 > /dev/fb1; yes | head --bytes 153600 > /dev/fb1; done )

real	0m5.090s
user	0m1.520s
sys	0m2.010s
[email protected]:~ $
A minimal delay of 0.07s is needed between the frames in order to see each frame completely a short time, which results in 9.7fps:

Code: Select all

[email protected]:~ $ time ( for((i=0; i<20; ++i)); do tail --bytes 153600 giraffe.565 > /dev/fb1; sleep 0.07; yes | head --bytes 153600 > /dev/fb1; sleep 0.07; done )

real	0m4.136s
user	0m0.390s
sys	0m0.410s
[email protected]:~ $ 
Hermann.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1569
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Raspberry Pi Zero and ILI9341 320x230 TFT

Fri Aug 19, 2016 10:20 am

Last night I found this cool "Framebuffer use" github link:
https://github.com/notro/fbtft/wiki/Framebuffer-use

It has sections "X server", "mplayer", "Image viewer", "Console", "Framebuffer mirroring" and "Watch Youtube", but it was just too late in the night.

This morning I started with "X Server" and it was easy to get a REALLY BIG raspberry show up in 320x240 X session!
Image

Next I needed to trick security in order to start eg. "xeyes", as always this can be done with (dangerous!) "sudo xhost +". Then not only xeyes could be started, but I was able to use "xdotool" to move the mouse around!

Code: Select all

$ (export DISPLAY=:0; sudo xhost +; xeyes &)>/dev/null
$ xdotool mousemove_relative -- -40 100
$ 
Here you can see TFT "before" xdotool command and "after":
Image

Need to find out how to make 0.70$ dual axis Arduino joystick work with Pi Zero 320x240 X11 ;-)
https://twitter.com/HermannSW/status/715977342888382464
(right click for details)
Image

Hermann.

P.S:
Just realized that this somehow looks like a "raspberry man" (head, eyes, hair(?), even a mouth) ...
Image

P.P.S:
Remotely opening menues with xdotool, cool ...

Code: Select all

[email protected]:~ $ xdotool mousemove 60 20
[email protected]:~ $ xdotool mousedown 1
[email protected]:~ $ xdotool mousemove 60 190
[email protected]:~ $ xdotool mousedown 1
[email protected]:~ $ 
Image

P.P.P.S:
Use "xdotool mousemove_relative 1 0" to make blank screensaver go away ("0 0" has no effect).
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1569
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Raspberry Pi Zero and ILI9341 320x230 TFT

Sat Aug 20, 2016 12:22 am

Nice, Pi Zero plays 25fps mplayer2 video on 320x240 TFT, see "mplayer" section for details:
https://github.com/notro/fbtft/wiki/Framebuffer-use

Hermann.

https://www.youtube.com/watch?v=gaD7M2C ... e=youtu.be
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1569
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Raspberry Pi Zero and ILI9341 320x230 TFT

Sat Aug 20, 2016 2:46 pm

"con2fbmap 1 1" gives 40x15 characters for Raspberry Pi Zero console, less than 32x24 I had on C64 25 years ago!
Image

I found a cool youtube video today, X Session on multi ILI9341 display!
https://www.youtube.com/watch?v=wxJpWRPKe-g
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1569
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Raspberry Pi Zero and ILI9341 320x230 TFT

Sun Aug 21, 2016 1:57 pm

Chapter "Framebuffer Mirroring" of "Framebuffer use" github link was easy:
https://github.com/notro/fbtft/wiki/Framebuffer-use

Compilation of "fbcp" worked as described, and after starting as background process "fbcp" did continuously copy complete 1440x900 framebuffer 0 (X Session) to 320x240 framebuffer 1 (ILI9341) with resizing. I used tool "fbgrab" to take "framebuffer screenshots", by default screenshot from /dev/fb0 is done:

Code: Select all

[email protected]:~ $ rpi-fbcp-master/build/fbcp &
[1] 3058
[email protected]:~ $ fbgrab fb0.png
[email protected]:~ $ fbgrab -d /dev/fb1 fb1.png
[email protected]:~ $ 
Here is 1400x900 screenshot from /dev/fb0 (includes mouse pointer):
https://stamm-wilbrandt.de/en/forum/fb0.png

And here is 320x240 screenshot from /dev/fb1:
https://stamm-wilbrandt.de/en/forum/fb1.png
Image

Hermann.

P.S:
Yesterday I learned how to easily power Pi Zero plus ILI9341 TFT from a single Lipo cell:
viewtopic.php?p=1026555#p1026555
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

rza.android
Posts: 3
Joined: Sun Oct 07, 2012 10:02 am

Re: Raspberry Pi Zero and ILI9341 320x230 TFT

Sat Dec 03, 2016 7:33 pm

Hi guys i cant get this working on my rpi zero has anyone else had problems ?
i finally got it working on Rpi model B with the smaller header i had to play with it a bit using the combination of 2 tutorials to get it working but i cannot get the zero working.
can someone help please

User avatar
HermannSW
Posts: 1569
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Raspberry Pi Zero and ILI9341 320x230 TFT

Fri Sep 22, 2017 6:36 am

Hi,

I did not see the question before, but was looking into this thread to setup a 320x240 display with a new Pi Zero.
What problems do you have?

Let me describe from scratch what I did today to get display running with new Pi Zero:

I did install latest Raspbian Stretch lite (Release date:2017-09-07):
https://www.raspberrypi.org/downloads/raspbian/

Before booting 1st time I did "touch /media/boot_/ssh" to allow for remote ssh access, then I unmounted the SD card and booted the Pi Zero. After some time I did "nmap -sn 192.168.178.1/24" to scan my home router and found Pi Zero using 192.168.178.173. After logging in I first changed the "pi" user password, ran "sudo raspi-config" and enabled camera and SPI interfaces. Leaving raspi-config I rebooted the Pi Zero.

On new ssh login I did "raspistill -t 0" first to verify camera is working (only for the initial logins and tests I connect HDMI monitor). Then, as stated in this thread, I did

Code: Select all

sudo modprobe fbtft_device name=rpi-display gpios=reset:23,dc:24,led:18 rotate=90
and verified via "dmesg" that all was fine:

Code: Select all

...
[   53.045805] random: crng init done
[  358.071025] fbtft: module is from the staging directory, the quality is unknown, you have been warned.
[  358.077162] fbtft_device: module is from the staging directory, the quality is unknown, you have been warned.
[  358.078627] spidev spi0.0: spidev spi0.0 500kHz 8 bits mode=0x00
[  358.078646] spidev spi0.1: spidev spi0.1 500kHz 8 bits mode=0x00
[  358.078697] bcm2708_fb soc:fb: soc:fb id=-1 pdata? no
[  358.078736] spidev spi0.0: Deleting spi0.0
[  358.089256] fbtft_device: GPIOS used by 'rpi-display':
[  358.089272] fbtft_device: 'reset' = GPIO23
[  358.089277] fbtft_device: 'dc' = GPIO24
[  358.089283] fbtft_device: 'led' = GPIO18
[  358.089301] spidev spi0.1: spidev spi0.1 500kHz 8 bits mode=0x00
[  358.089311] spi spi0.0: fb_ili9341 spi0.0 32000kHz 8 bits mode=0x00
[  358.186123] fb_ili9341: module is from the staging directory, the quality is unknown, you have been warned.
[  358.490926] graphics fb1: fb_ili9341 frame buffer, 320x240, 150 KiB video memory, 16 KiB DMA buffer memory, fps=20, spi0.0 at 32 MHz
[email protected]:~ $ 
Next I did "wget https://stamm-wilbrandt.de/en/forum/giraffe.565" for my default test image, and "tail --bytes 153600 giraffe.565 > /dev/fb1", and the giraffe showed up on 320x240 display:
Image

I used USB2ethernet adapter for first login because I forgot to setup Pi Zero OTG allowing to ssh into Pi Zero over USB:
http://blog.gbaman.info/?p=791#comment-145374

Last, but not least, instead of referencing Kolban's book above, here are the connections:
ILI9341__ Pi Zero pin
VCC______17 VCC
GND______09 GND
CS________24 CE0
RESET____16 GPIO23
D/C_______18 GPIO24
MOSI_____19 MOSI
SCK______23 SCLK
LED_______12 GPIO18
MISO_____--
In case of using SD card of display module, its MISO would need to be connected to 21 MISO on Pi Zero.

Hermann.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1569
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Raspberry Pi Zero and ILI9341 320x230 TFT

Sun Sep 24, 2017 10:54 am

Next step was to stream from Raspberry camera to ILI9341 320x240 TFT. I did that in the past with connected USB webcam(s):
viewtopic.php?f=63&t=161551

Instread of pipeing "raspivid" output into gstreamer fdsrc, I chose v4l2 driver this time without using raspivid. After reboot and ssh into Raspberry Pi Zero (over USB2ethernet as here, or over USB OTG), this command loads the v4l2 module:

Code: Select all

sudo modprobe bcm2835-v4l2
Next step is to configure fbtft_device, this time with a slightly changed set of pins:

Code: Select all

sudo modprobe fbtft_device name=rpi-display gpios=reset:25,dc:24,led:27 rotate=90
As you can see in this photo I superglued a 9x1 connector on one ILI9341 side, and a 4x2 connector for the Pi Zero:
Image

The ILI9341 LED pin is permanently soldered to ILI9341 VCC pin making the cable counts match. Placing reset from GPIO23 to GPIO25, GND from pin 09 to pin 20, and connecting MISO although it is not used (yet), allowed the compact 4x2 connector on Pi Zero pins 17-24.

A first function test for the framebuffer can be done with above mentioned giraffe picture, or alternatively with this simple gtsreamer command:

Code: Select all

gst-launch-1.0 videotestsrc ! fbdevsink device=/dev/fb1
Streaming Raspberry camera video was easy, but I was not able to make fpsdisplaysink work with /dev/fb1. I remembered to use "fakesink" for fps determination, and faced the problem to have two streams now, one for ILI9341 display, and the other for fakesink. Surprisingly the standard Unix command "tee" is abailable as gstreamer plugin as well ! This command streams Raspberry camera video to ILI9341 display, and displays average framerate (51fps !!) on ssh session:

Code: Select all

gst-launch-1.0 -v v4l2src device=/dev/video0 do-timestamp=true ! video/x-raw,width=320,height=240 ! videoconvert ! tee name=t ! queue ! fbdevsink device=/dev/fb1 t. ! fpsdisplaysink text-overlay=false video-sink="fakesink sync=true"
And this is the output generated on ssh session:

Code: Select all

...
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 13705, dropped: 0, current: 51.92, average: 51.86
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 13731, dropped: 0, current: 51.86, average: 51.86
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 13757, dropped: 0, current: 51.66, average: 51.86
/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 13783, dropped: 0, current: 51.88, average: 51.86
...
Hermann.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “General discussion”