TFT 3.5 LCD Raspberry: Skirtumas tarp puslapio versijų
45 eilutė: | 45 eilutė: | ||
#define TFT_RST 4 // Reset pin (could connect to RST pin) | #define TFT_RST 4 // Reset pin (could connect to RST pin) | ||
#define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen | #define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen | ||
+ | |||
+ | TFT Taip pat gali veikti kartu su SD Kortele pagal [[sd card module|šį aprašymą]], abu moduliai naudos skirtingus SPI interfeisus, todėl nesipyks tarpusavyje. | ||
Pinai atitinka aprašytus ant esp32 esančius fizinius pinus. Kodo pavyzdys: | Pinai atitinka aprašytus ant esp32 esančius fizinius pinus. Kodo pavyzdys: | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> |
Dabartinė 02:49, 12 gruodžio 2022 versija
ESP8266[keisti]
ESP8266 NodeMCU support for spi interface displays https://github.com/Bodmer/TFT_eSPI
Turėkite omenyje, kad konfigūracija yra globali visiems projektams, nes keičiama pačiame library konfigūraciniame faile. Norint naudotis "per project" konfigūracija, siūlyčiau migruoti į normalesnį IDE -> PlatformIO
Lib konfigūracija Arduino/libraries/TFT_eSPI/User_Setup.h:
#define RPI_ILI9486_DRIVER #define SPI_FREQUENCY 20000000 #define TOUCH_CS PIN_D2 // Chip select pin (T_CS) of touch screen
Pajungimo schema:
- Display SDO/MISO to NodeMCU pin D6
- Display LED to NodeMCU pin VIN (or 5V)
- Display SCK to NodeMCU pin D5
- Display SDI/MOSI to NodeMCU pin D7
- Display DC (or AO)to NodeMCU pin D3
- Display RESET to NodeMCU pin D4 (or RST, see below)
- Display CS to NodeMCU pin D8 (or GND, see below)
- Display GND to NodeMCU pin GND (0V)
- Display VCC to NodeMCU 5V or 3.3V
- Display Touch_CD to NodeMCU pin D1
- Display T_CS to NodeMCU pin D2
Kitas lib: https://github.com/ZinggJM/ILI9486_SPI
Galima drąsiai išbandyti su projektu: https://github.com/e1z0/WifiAnalyzer
ESP32[keisti]
Turėkite omenyje, kad konfigūracija yra globali visiems projektams, nes keičiama pačiame library konfigūraciniame faile. Norint naudotis "per project" konfigūracija, siūlyčiau migruoti į normalesnį IDE -> PlatformIO
Lib konfigūracija Arduino/libraries/TFT_eSPI/User_Setup.h
#define RPI_ILI9486_DRIVER #define SPI_FREQUENCY 20000000 #define TFT_MISO 19 #define TFT_MOSI 23 #define TFT_SCLK 18 #define TFT_CS 15 // Chip select control pin #define TFT_DC 2 // Data Command control pin #define TFT_RST 4 // Reset pin (could connect to RST pin) #define TOUCH_CS 21 // Chip select pin (T_CS) of touch screen
TFT Taip pat gali veikti kartu su SD Kortele pagal šį aprašymą, abu moduliai naudos skirtingus SPI interfeisus, todėl nesipyks tarpusavyje. Pinai atitinka aprašytus ant esp32 esančius fizinius pinus. Kodo pavyzdys:
#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
void setup(void) {
tft.init();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
// Set "cursor" at top left corner of display (0,0) and select font 4
tft.setCursor(0, 0, 4);
// Set the font colour to be white with a black background
tft.setTextColor(TFT_WHITE, TFT_BLACK);
// We can now plot text on screen using the "print" class
tft.println("Initialised default\n");
tft.println("White text");
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.println("Red text");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("Green text");
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.println("Blue text");
delay(5000);
}
void loop() {
tft.invertDisplay( false ); // Where i is true or false
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0, 4);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Invert OFF\n");
tft.println("White text");
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.println("Red text");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("Green text");
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.println("Blue text");
delay(5000);
// Binary inversion of colours
tft.invertDisplay( true ); // Where i is true or false
tft.fillScreen(TFT_BLACK);
tft.setCursor(0, 0, 4);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Invert ON\n");
tft.println("White text");
tft.setTextColor(TFT_RED, TFT_BLACK);
tft.println("Red text");
tft.setTextColor(TFT_GREEN, TFT_BLACK);
tft.println("Green text");
tft.setTextColor(TFT_BLUE, TFT_BLACK);
tft.println("Blue text");
delay(5000);
}
Metodas (su gfx akseleracija) be touchscreen[keisti]
apt-get install cmake git git clone https://github.com/juj/fbcp-ili9341.git cd fbcp-ili9341 mkdir build cd build cmake -DILI9486=ON -DSPI_BUS_CLOCK_DIVISOR=6 .. make -j sudo ./fbcp-ili9341
Patvirtintas metodas su touchscreen[keisti]
/boot/config.txt[keisti]
dtparam=spi=on dtparam=i2c_arm=on dtoverlay=piscreen2r,speed=16000000,rotate=270
/boot/cmdline.txt[keisti]
Pridedam į galą branduolio parametrų eilutės:
fbcon=map:10 fbcon=font:VGA2x2
pygameui fix (raspbian jessie)[keisti]
The package "libsdl1.2-15-10", which ships with Debian Jessie, breaks pygame. To make it work we have to revert back to "libsdl1.2-15-5" from Wheezy.
The quickest way is to comment everything out in your /etc/apt/sources.list and temporarily add:
deb http://archive.raspbian.org/raspbian wheezy main contrib non-free
Import the corresponding keys:
deb http://archive.raspbian.org/raspbian wheezy main contrib non-free gpg -a --export 9165938D90FDDD2E | sudo apt-key add -
Remove the offending package and replace it with the working one:
sudo apt-get update sudo apt-get remove libsdl1.2debian python-pygame apt-get install libsdl-image1.2 libsdl-mixer1.2 libsdl-ttf2.0-0 libsdl1.2debian libsmpeg0 python-pygame sudo apt-mark hold libsdl1.2debian
Restore "/etc/apt/sources.list" to it's original state.
pygameui fix (raspbian stretch)[keisti]
Downgradiname paketa ir nepamirstame is naujo perkalibruoti touchscreen.
TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 TSLIB_CALIBFILE=/etc/pointercal TSLIB_CONFFILE=/etc/ts.conf TSLIB_PLUGINDIR=/usr/lib/ts ts_calibrate
Binary Install way[keisti]
wget http://devnull.eofnet.lt/stuff/raspbian_wheezy/libsdl1.2-dev_1.2.15-5~bpo9%2B1_armhf.deb wget http://devnull.eofnet.lt/stuff/raspbian_wheezy/libsdl1.2debian_1.2.15-5~bpo9%2B1_armhf.deb dpkg -i libsdl1.2debian_1.2.15-5~bpo9+1_armhf.deb dpkg -i libsdl1.2-dev_1.2.15-5~bpo9+1_armhf.deb
Source install way[keisti]
mkdir /root/sources cd /root/sources wget http://legacy.raspbian.org/raspbian/pool/main/libs/libsdl1.2/libsdl1.2_1.2.15.orig.tar.gz wget http://legacy.raspbian.org/raspbian/pool/main/libs/libsdl1.2/libsdl1.2_1.2.15-5.debian.tar.gz
Or use my mirror
wget http://devnull.eofnet.lt/stuff/raspbian_wheezy/libsdl1.2_1.2.15-5.debian.tar.gz http://devnull.eofnet.lt/stuff/raspbian_wheezy/libsdl1.2_1.2.15.orig.tar.gz tar xzvf libsdl1.2_1.2.15.orig.tar.gz tar xzvf libsdl1.2_1.2.15-5.debian.tar.gz mv debian SDL-1.2.15/ cd SDL-1.2.15
Install dependencies to build the packages
apt-get install packaging-dev debian-keyring devscripts equivs
Prepare the package deps
mk-build-deps --install
Add the revision to the change file, report the backporting
dch --bpo
Build the package
fakeroot debian/rules binary dpkg-buildpackage -us -uc
Now you can install the package
dpkg -i ../libsdl1.2debian_1.2.15-5~bpo9+1_armhf.deb dpkg -i ../libsdl1.2-dev_1.2.15-5~bpo9+1_armhf.deb
/etc/X11/xorg.conf.d/99-ads7846-cal.conf[keisti]
Section "InputClass" Identifier "calibration" MatchProduct "ADS7846 Touchscreen" Option "Calibration" "3950 253 254 3971" Option "SwapAxes" "0" driver "evdev" EndSection
Išimam iš konfigūracinių failų esančių /usr/share/X11/xorg.conf.d/ touchscreen interfeisus pvz. 40-libinput.conf esantis su Driver "libinput", būtina jį pašalinti, galima taip pat padaryti, kad naudotų draiverį "evdev". Pakeičiam 99-fbturbo.conf esantį fb0 į fb1
[keisti]
10-amdgpu.conf[keisti]
Section "OutputClass"
Identifier "AMDgpu"
MatchDriver "amdgpu"
Driver "amdgpu"
EndSection
10-evdev.conf[keisti]
Section "InputClass"
Identifier "evdev pointer catchall"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
EndSection
Section "InputClass"
Identifier "evdev keyboard catchall"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
EndSection
Section "InputClass"
Identifier "evdev touchpad catchall"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
EndSection
Section "InputClass"
Identifier "evdev tablet catchall"
MatchIsTablet "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
EndSection
Section "InputClass"
Identifier "evdev touchscreen catchall"
MatchIsTouchscreen "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
EndSection
10-quirks.conf[keisti]
# Collection of quirks and blacklist/whitelists for specific devices.
# Accelerometer device, posts data through ABS_X/ABS_Y, making X unusable
# http://bugs.freedesktop.org/show_bug.cgi?id=22442
Section "InputClass"
Identifier "ThinkPad HDAPS accelerometer blacklist"
MatchProduct "ThinkPad HDAPS accelerometer data"
Option "Ignore" "on"
EndSection
# https://bugzilla.redhat.com/show_bug.cgi?id=523914
# Mouse does not move in PV Xen guest
# Explicitly tell evdev to not ignore the absolute axes.
Section "InputClass"
Identifier "Xen Virtual Pointer axis blacklist"
MatchProduct "Xen Virtual Pointer"
Option "IgnoreAbsoluteAxes" "off"
Option "IgnoreRelativeAxes" "off"
EndSection
# https://bugs.freedesktop.org/show_bug.cgi?id=55867
# Bug 55867 - Doesn't know how to tag XI_TRACKBALL
Section "InputClass"
Identifier "Tag trackballs as XI_TRACKBALL"
MatchProduct "trackball"
MatchDriver "evdev"
Option "TypeName" "TRACKBALL"
EndSection
# https://bugs.freedesktop.org/show_bug.cgi?id=62831
# Bug 62831 - Mionix Naos 5000 mouse detected incorrectly
Section "InputClass"
Identifier "Tag Mionix Naos 5000 mouse XI_MOUSE"
MatchProduct "La-VIEW Technology Naos 5000 Mouse"
MatchDriver "evdev"
Option "TypeName" "MOUSE"
EndSection
40-libinput.conf[keisti]
# Match on all types of devices but tablet devices and joysticks
Section "InputClass"
Identifier "libinput pointer catchall"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "libinput keyboard catchall"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "libinput touchpad catchall"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "libinput tablet catchall"
MatchIsTablet "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
70-wacom.conf[keisti]
# Some of the below input classes appear 3x times, once for each of
# "tablet", "touchscreen", and "touchpad" to ensure that the Wacom
# driver is not accidentally bound to other types of hardware that
# Wacom has made which are not handled by the wacom driver (e.g the
# Wacom Bluetooth Keyboard)
#
# https://sourceforge.net/p/linuxwacom/bugs/294/
Section "InputClass"
Identifier "Wacom USB tablet class"
MatchUSBID "056a:*"
MatchDevicePath "/dev/input/event*"
MatchIsTablet "true"
Driver "wacom"
EndSection
Section "InputClass"
Identifier "Wacom USB touchscreen class"
MatchUSBID "056a:*"
MatchDevicePath "/dev/input/event*"
MatchIsTouchscreen "true"
Driver "wacom"
EndSection
Section "InputClass"
Identifier "Wacom USB touchpad class"
MatchUSBID "056a:*"
MatchDevicePath "/dev/input/event*"
MatchIsTouchpad "true"
Driver "wacom"
EndSection
Section "InputClass"
Identifier "Wacom tablet class"
MatchProduct "Wacom|WACOM|PTK-540WL|ISD-V4"
MatchDevicePath "/dev/input/event*"
MatchIsTablet "true"
Driver "wacom"
EndSection
Section "InputClass"
Identifier "Wacom touchscreen class"
MatchProduct "Wacom|WACOM|PTK-540WL|ISD-V4"
MatchDevicePath "/dev/input/event*"
MatchIsTouchscreen "true"
Driver "wacom"
EndSection
Section "InputClass"
Identifier "Wacom touchpad class"
MatchProduct "Wacom|WACOM|PTK-540WL|ISD-V4"
MatchDevicePath "/dev/input/event*"
MatchIsTouchpad "true"
Driver "wacom"
EndSection
# Serial Wacom devices should always be one of tablet, touchscreen, or
# touchpad so we can safely get away with just one match section in
# these cases
Section "InputClass"
Identifier "Wacom PnP device class"
MatchPnPID "WACf*|WCOM*|WACM*|FUJ02e5|FUJ02e7|FUJ02e9"
MatchDevicePath "/dev/input/event*"
Driver "wacom"
EndSection
Section "InputClass"
Identifier "Wacom serial class"
MatchProduct "Serial Wacom Tablet"
Driver "wacom"
EndSection
Section "InputClass"
Identifier "Wacom serial class identifiers"
MatchProduct "WACf|FUJ02e5|FUJ02e7|FUJ02e9"
Driver "wacom"
EndSection
# Hanwang tablets
Section "InputClass"
Identifier "Hanwang class"
MatchProduct "Hanwang"
MatchDevicePath "/dev/input/event*"
Driver "wacom"
EndSection
# Waltop tablets
Section "InputClass"
Identifier "Waltop class"
MatchProduct "WALTOP"
MatchIsTablet "on"
MatchDevicePath "/dev/input/event*"
Driver "wacom"
EndSection
# N-Trig Duosense Electromagnetic Digitizer
Section "InputClass"
Identifier "Wacom N-Trig class"
MatchProduct "HID 1b96:0001|N-Trig Pen|N-Trig DuoSense"
MatchDevicePath "/dev/input/event*"
Driver "wacom"
Option "Button2" "3"
EndSection
799-fbturbo.conf[keisti]
Section "Device"
Identifier "Allwinner A10/A13 FBDEV"
Driver "fbturbo"
Option "fbdev" "/dev/fb1"
# Option "SwapbuffersWait" "true"
EndSection
Kataloge /etc/X11/xorg.conf.d/ failų apart mūsų įdeto 99-ads7846-cal.conf daugiau nėra.
Kivy GUI toolkit[keisti]
Prieš pradėdami, atnaujiname sistemą:
pi@raspberrypi ~ $ sudo apt-get update && sudo apt-get -y upgrade
Perkrauname:
pi@raspberrypi ~ $ sudo reboot
Įdiegiame paketus
pi@raspberrypi ~ $ sudo apt-get -y libffi-dev install libpango1.0-dev libcogl-pango-dev libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev libsdl2-gfx-dev libsdl2-dev libsdl-ttf2.0-dev libsdl-sge-dev libsdl-pango-dev libsdl-ocaml-dev libsdl-console-dev libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev \ pkg-config libgl1-mesa-dev libgles2-mesa-dev \ python-setuptools libgstreamer1.0-dev git-core \ gstreamer1.0-plugins-{bad,base,good,ugly} \ gstreamer1.0-{omx,alsa} python-dev libmtdev-dev \ xclip xsel
Įdiegiame pip iš source
pi@raspberrypi ~ $ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py pi@raspberrypi ~ $ sudo python get-pip.py
Įdiegiame kitus reikalingus paketus:
pi@raspberrypi ~ $ pip install -U Cython==0.28.2 pi@raspberrypi ~ $ sudo pip install pygments docutils
Pagaliau galime įdiegti kivy:
pi@raspberrypi ~ $ git clone https://github.com/kivy/kivy pi@raspberrypi ~ $ cd kivy pi@raspberrypi ~/kivy $ python setup.py build pi@raspberrypi ~/kivy $ sudo python setup.py install
Norint įgalinti touchscreen reikia padaryti keletą modifikacijų kivy konfigūraciniame faile, pirmiausia paleiskime:
pi@raspberrypi ~/kivy $ python ~/kivy/examples/demo/pictures/main.py
Bus sukurtas kivy konfigūracinis failas, kurį atsidarysime:
pi@raspberrypi ~/kivy $ nano ~/.kivy/config.ini
Einame į [input] sekciją, išimame esančias eilutes ir pridedame šias:
mouse = mouse mtdev_%(name)s = probesysfs,provider=mtdev hid_%(name)s = probesysfs,provider=hidinput
Paleidžiame kitą demo ir išbandome (patampome, paspaudžiame, bandome tempti):
pi@raspberrypi ~/kivy $ python ~/kivy/examples/demo/pictures/main.py
Išbandome kitus demo:
pi@raspberrypi ~/kivy $ python ~/kivy/examples/demo/showcase/main.py
Taip pat yra daugelis kitų direktorijoje ~/kivy/examples/.
FIXME
|
Reziume gauname totalų šūdą kuris segfaultina norint paleisti be X'o... Laukiam kol sutvarkys kivy, jog veiktu be Xorg palaikymo, tik sdl'e.
raylib-go[keisti]
apt-get update&&apt-get install libbsd-dev rpi-update wget https://dl.google.com/go/go1.12.5.linux-armv6l.tar.gz tar -C /usr/local -xzf go1.12.5.linux-armv6l.tar.gz
Sudedame į /etc/profile ir /root/.bashrc:
export GOPATH=$HOME/go export RPI_HOME=/opt/tools/arm-bcm2708/arm-linux-gnueabihf export PATH=${RPI_HOME}/bin:/usr/local/go/bin:$PATH:$GOPATH/bin
Sudiegiame biblioteką
go get github.com/gen2brain/raylib-go/raylib
Sudedam mirrorinima i mūsų LCD:
git clone https://github.com/AndrewFromMelbourne/raspi2fb.git cd raspi2fb&&mkdir build&&cd build&&cmake ..&&make&&make install
Taip pat reiktų nustatyti LCD rezoliuciją į mažesnę, kadangi mirrorinimas HDMI išėjimo į rezoliuciją pvz.: 480x320, bus nelabai įskaitomas. Prirašome eilutę į /boot/config.txt:
hdmi_cvt 480 320 60 1 0 0 0 framebuffer_width=480 framebuffer_height=320
Paleidžiame mirrorinimą:
/usr/local/bin/raspi2fb --daemon
Padarome, kad mirrorinimas vyktų sistemos startavimo metu:
cd ..&&mv raspi2fb\@.service /etc/systemd/system/&&systemctl daemon-reload&&systemctl enable raspi2fb@1.service
Sukalibruojame ekrana:
TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 TSLIB_CALIBFILE=/etc/pointercal TSLIB_CONFFILE=/etc/ts.conf TSLIB_PLUGINDIR=/usr/lib/ts ts_calibrate
Taip pat sukuriame tslib pagalba naują touchscreen input:
TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 TSLIB_CALIBFILE=/etc/pointercal TSLIB_CONFFILE=/etc/ts.conf TSLIB_PLUGINDIR=/usr/lib/ts ts_uinput -v -d
/dev/input/event0 yra mūsų touchscreen (Įsitikinkite, kad ten būtent jis), paleidus turėtų ateiti grąžinimas pvz.:
/dev/input/event1
Tai ir bus mūsų naujas event device'as
package main
import "github.com/gen2brain/raylib-go/raylib"
func main() {
rl.InitWindow(800, 450, "raylib [rpi] example - basic window")
rl.SetTargetFPS(60)
for !rl.WindowShouldClose() {
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("Congrats! You created your first window!", 190, 200, 20, rl.LightGray)
rl.EndDrawing()
}
rl.CloseWindow()
}
go build main.go ./main