EBC Exercise 12a 2.4 TFT LCD display via SPI



This is an exercise in interfacing the 2.4" TFT LCD display (ili9341) via a SPI bus. The newer using the tinyDRM driver and the older uses fbtft.

The Hardware
This table shows how to wire the LCD display for SPI 0.

tinyDRM
The tinyDRM driver requires a 4.19 kernel or newer. Run uname -a to see which kernel is being run. If it isn't new enough run:

bone$ cd /opt/scripts/tools bone$ sudo ./update_kernel.sh --lts-4_19 bone$ reboot

Clone the course repo.

bone$ git clone https://github.com/MarkAYoder/BeagleBoard-exercises.git exercises

and then

bone$ cd exercises/display/ili9341 bone$ git pull bone$ cd tinyDRM bone$ ls BB-LCD-ADAFRUIT-24-SPI1-00A0.dts install.sh  Makefile

BB-LCD-ADAFRUIT-24-SPI1-00A0.dts is the device driver for the LCD attached to SPI 1. It also assumes the backlight is attached to P9_14 (not P9_16 as in the table above.).

To compile it: bone$ make cpp -x assembler-with-cpp -nostdinc -I /opt/source/dtb-4.19-ti/include -undef -D__DTS__ < BB-LCD-ADAFRUIT-24-SPI1-00A0.dts | dtc -i /opt/source/dtb-4.19-ti/include -I dts -O dtb -b 0 -o BB-LCD-ADAFRUIT-24-SPI1-00A0.dtbo - BB-LCD-ADAFRUIT-24-SPI1-00A0.dtbo: Warning (chosen_node_is_root): /fragment@0/__overlay__/chosen: chosen node must be at root nod bone$ make install sudo cp --backup BB-LCD-ADAFRUIT-24-SPI1-00A0.dtbo /lib/firmware Add uboot_overlay_addr4=/lib/firmware/BB-LCD-ADAFRUIT-24-SPI1-00A0.dtbo to /boot/uEnv.txt

Now, follow the instructions from the Makefile and edit /boot/uEnv.txt and find the line starting with Uncomment it and change it to: uboot_overlay_addr4=/lib/firmware/BB-LCD-ADAFRUIT-24-SPI1-00A0.dtbo The reboot and check of /dev/fb0 bone$ sudo reboot After rebooting... bone$ ls -ls /dev/fb0 0 crw-rw 1 root video 29, 0 Oct 3 10:07 /dev/fb0
 * 1) uboot_overlay_addr4=/lib/firmware

You can control the backlight with: bone$ cd /sys/devices/platform/backlight_pwm/backlight/backlight_pwm bone$ sudo chgrp debian * bone$ sudo chmod g+w * Turn the display off, then on with: bone$ echo 1 > bl_power bone$ echo 0 > bl_power Change the brightness to 25% with: bone$ echo 25 > brightness

Now jump to the Using the Frame Buffer section to see how to display images, etc..

Legacy fbtft
Clone the course repo.

bone$ git clone https://github.com/MarkAYoder/BeagleBoard-exercises.git exercises

and then

bone$ cd exercises/display/ili9341/fb bone$ git pull bone$ ./on.sh

After a moment the display should turn dark. Look in on.sh to see what it did. If the display doesn't turn on, look in on.sh and make sure it's set for the correct SPI bus.

Displaying Images
Follow the instructions in install.sh to download fbi and some images. bone$ sudo apt update bone$ sudo apt install fbi Display them with: bone$ fbi -noverbose -T 1 -a boris.png You should now see Boris the Beagle on your display.

Playing Movies
Install mplayer and load a movie on the Bone (see install.sh). bone$ sudo apt install mplayer

Play the movie. Rotate the movie.

Generate Text
Install imagemagick. bone$ sudo apt install imagemagick

See text.sh for an example of using imagemagick to write text to the LCD display. Write your name on the LCD. Display an image and write some text on it.

SIZE=320x240 TMP_FILE=/tmp/frame.png convert -background lightblue -fill blue -font Times-Roman -pointsize 24 \ -size $SIZE \ label:'ImageMagick\nExamples\nby Anthony' \ -draw "text 0,200 'Bottom of Display'" \ $TMP_FILE sudo fbi -noverbose -T 1 $TMP_FILE
 * 1) Here's how to use imagemagick to display text
 * 2) Make a blank image
 * 1) From: http://www.imagemagick.org/Usage/text/