raspberry pi tft display code made in china
While googling for any info about lcd controller I came across this page: http://heikki.virekunnas.fi/2015/raspberry-pi-tft/, author managed to get from manufacturer patch file for kernel sources and tested it with 4.1.y - on which lcd worked. But still LCD replace HDMI, but I want to use this screen as additional for user interaction, while the bigger on HDMI as presentation monitor.
Since, fbtft has been merged with rpi kernel, so the fb drivers (including ili9341.c) was moved to fbtft_device driver (so the author of page can"t compile latest kernel with driver+patch).
So something about hardware, which I reverse engineered by the "hard way" - "grab multimeter and run through all LCD FPC pins and shift register pins"
I"m pretty sure about D/C (Pin 37 on LCD) and Reset (Pin 19 on LCD) pins by looking into driver code, but I can"t identify other signals (WR/RD/CS/etc...)
[ 0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=656 bcm2708_fb.fbheight=416 bcm2709.boardrev=0xa01041 bcm2709.serial=0x2938b030 smsc95xx.macaddr=B8:27:EB:38:B0:30 bcm2708_fb.fbswap=1 bcm2709.disk_led_gpio=47 bcm2709.disk_led_active_low=0 sdhci-bcm2708.emmc_clock_freq=250000000 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
- Controller is not ILI9341/ILI9325 - those are for smaller displays (320x240, etc...), I guess this might be ILI9486/9488 because they are for 480x320 displays. But when I compared init with DS it does not fit right so LCD can have a clone of ILI9486/9488 ...
- Module use only SPI interface and two CE signals (CE0 for touch controller, CE1 for LCD shift registers - compared to others lcd modules, in KeDei module this is swapped),
• PCAP size from 1.3”-65”• PCAP & LCD module size: 1.3”-32”• Optical Bonding service : 1.3”-21.5”• HDMI & VGA T-CON Board available• IIC-USB interface Bridge board available•CTP can be Customized with cover glass surface treatment process AG(anti-glare), AR(anti-reflective), AF(anti-fingerprint) • Support touch with 12mm cover glass.• Support touch with water.• Support touch with 5mm gloves.• Custom Highlight TFT (Up to 2300cd/㎡)• Support operating temperature: -40℃-85℃.
-15.6 inch capacitive raspberry pi touch display: the structure of the product is Glass + Glass,multi touch , ILITEK controller IC,USB interface,support operation with gloves, water , and working well with additional 10mm thick tempered glass on the top. Mainly used in industrial, home appliances, medical, outdoor terminals and other fields. Deep customization service supported and a variety of interface converting & drive boards available, which is convenient for customers to use..The display uses LVDS/EDP interface,we can provide HDMI/VGA driver board.
The RPi LCD can be driven in two ways: Method 1. install driver to your Raspbian OS. Method 2. use the Ready-to-use image file of which LCD driver was pre-installed.
2) Connect the TF card to the PC, open the Win32DiskImager software, select the system image downloaded in step 1 and click‘Write’ to write the system image. ( How to write an image to a micro SD card for your Pi? See RPi Image Installation Guides for more details)
3) Connect the TF card to the Raspberry Pi, start the Raspberry Pi. The LCD will display after booting up, and then log in to the Raspberry Pi terminal,(You may need to connect a keyboard and HDMI LCD to Pi for driver installing, or log in remotely with SSH)
This LCD can be calibrated through the xinput-calibrator program. Note: The Raspberry Pi must be connected to the network, or else the program won"t be successfully installed.
The 1.54inch LCD uses the PH2.0 8PIN interface, which can be connected to the Raspberry Pi according to the above table: (Please connect according to the pin definition table. The color of the wiring in the picture is for reference only, and the actual color shall prevail.)
The example we provide is based on STM32F103RBT6, and the connection method provided is also the corresponding pin of STM32F103RBT6. If you need to transplant the program, please connect according to the actual pin.
The built-in controller used in this LCD is ST7789VW, which is an LCD controller with 240 x RGB x 320 pixels, while the pixels of this LCD itself is 135 (H)RGB x 240(V). There are two types of horizontal and vertical screens, so the internal RAM of the LCD is not fully used.
The LCD supports 12-bit, 16-bit, and 18-bit input color formats per pixel, namely RGB444, RGB565, and RGB666 three color formats, this routine uses RGB565 color format, which is also a commonly used RGB format
Note: Different from the traditional SPI protocol, the data line from the slave to the master is hidden since the device only has display requirement.
Framebuffer uses a video output device to drive a video display device from a memory buffer containing complete frame data. Simply put, a memory area is used to store the display content, and the display content can be changed by changing the data in the memory.
2.We use Dev libraries by default. If you need to change to BCM2835 or WiringPi libraries ,please open RaspberryPi\c\Makefile and modify lines 13-15 as follows:
If you need to draw pictures, or display Chinese and English characters, we provide some basic functions here about some graphics processing in the directory RaspberryPi\c\lib\GUI\GUI_Paint.c(.h).
Set points of the display position and color in the buffer: here is the core GUI function, processing points display position and color in the buffer.
The fill color of a certain window in the image buffer: the image buffer part of the window filled with a certain color, usually used to fresh the screen into blank, often used for time display, fresh the last second of the screen.
Display time: in the image buffer,use (Xstart Ystart) as the left vertex, display time,you can choose Ascii visual character font, font foreground color, font background color.;
Python has an image library PIL official library link, it do not need to write code from the logical layer like C, can directly call to the image library for image processing. The following will take 1.54inch LCD as an example, we provide a brief description for the demo.
Note: Each character library contains different characters; If some characters cannot be displayed, it is recommended that you can refer to the encoding set ro used.
I"m trying to write a driver to use the module from a Pico. I have a preliminary spec I found online for the display chip, but am seeing some things that have yet to make sense to me. For one thing when I walk a "1" down the 16-bit color value the high-order byte seems to be ignored and the lower byte exhibits a RGB behavior in a 3-2-3 bit layout. I can make this work, but this limits the color availability to 256. This format is not documented in the spec I have. The spec outlines a 5-6-5 bit layout for 16-bit color. I then proceeded to attempt 18-bit color, but with this I get 6 bits red, nothing for green, and blue actually appears as cyan (mix of the green and blue).
The board seems to be driving the parallel inputs of the controller chip and doing the serial to parallel conversion using the four ICs shown at the bottom of the board in the picture instead of sending the SPI input directly to the chip. Since the board doesn"t seem to allow reading information from the main chip, it is difficult to tell if the high-order bits are even sent to the chip (only the lower byte is used by any of the instructions except "Memory Write" and "Memory Write Continue"). The controller chip is sandwiched between the lcd display and the board you can see in the picture. I kind of doubt I would be able to observe anything useful if I pulled the module apart since the ili9486 is packaged in a 1776-ball grid array.
In tft-lcd, the TFT operates as a switch tube. The frequently made use of TFT is a three-terminal device. Make use of the voltage related to the gate to control the current between the resource and the leakage electrode. For screen screens, each pixel is structurally visible as a layer of liquid crystal sandwiched between the pixel electrode and also the usual electrode. A lot more notably, from an electrical viewpoint you can think about it as capacitance.
To bill the pixel P (I, j) in row j as well as column I, switch over T (I, j) on and also use the target voltage to the signal line D (I). When the pixel electrode is fully charged, the charge in the capacitor is maintained even if the switch is disconnected, and also the liquid crystal particles in between the electrodes remain to have an electrical area. The information (column) driver ACTS to apply the target voltage to the signal line, while eviction (row) chauffeur ACTS to activate and off. The trick to present the picture is additionally the molecular orientation of the liquid crystal under the action of an electric field. In general, the plan of LCD molecules can be warped by the alignment on the within the substratum to realize different display settings. Under the action of electric area, the positioning of liquid crystal particles modifications, and also the intensity of incident light adjustments after going through the liquid crystal layer via the coordination with the polarizer. To attain image display screen.
Tft-lcd colorization is usually attained by including a layer of color filter on the front panel of the display. It requires a black matrix of red, green, blue and shielding on each pixel.
A parallel RGB interface up to 24 bits is available on all Raspberry Pi boards with the 40-way header (A+, B+, Pi2, Pi3, Zero) and the compute module. This interface allows to connect parallel RGB displays to the Raspberry Pi GPIO either in RGB24 (8 bits for red, green and blue) or RGB666 (6 bits per color) or RGB565 (5 bits red, 6 green and 5 blue).
This mode is accompanied by new overlays, which allow to produce an RGB signal thanks to the VGA666 (get the 666 passive VGA adapter for Raspberry-Pi B+ : code and hardware).
This TFT LCD Display for Raspberry Pi has 5″ size which features 800×480 pixel resolution. Getting the Pi onto the display board is easy enough!!! make use of stand-off screws included in this pack to put the Raspberry Pi on the display board. But while you do this please ensure that the HDMI ports of both the Display and the Pi would line up with each other so that you will take advantage of HDMI connector that we are providing in this product pack.
This 5 Inch Touch Screen HDMI Interface TFT LCD Module is a mini panel-mountable HDMI monitor. Small and simple, yet you can use this display with any computer that has HDMI output, and the shape makes it easy to attach to an electronic product.
It features efficient operation by equipping Backlight Power switch with which you can control the backlight whether to be on and off to save power. It has 13×2 Pin Socket from where one can get 5V Power from raspberry Pi to LCD and at the same time, transfer touch signal back to Raspberry Pi. It also features extended interface which is the replica of 13×2 Pin Socket.
Connecting an LCD to your Raspberry Pi will spice up almost any project, but what if your pins are tied up with connections to other modules? No problem, just connect your LCD with I2C, it only uses two pins (well, four if you count the ground and power).
BONUS: I made a quick start guide for this tutorial that you can download and go back to later if you can’t set this up right now. It covers all of the steps, diagrams, and code you need to get started.
There are a couple ways to use I2C to connect an LCD to the Raspberry Pi. The simplest is to get an LCD with an I2C backpack. But the hardcore DIY way is to use a standard HD44780 LCD and connect it to the Pi via a chip called the PCF8574.
The PCF8574 converts the I2C signal sent from the Pi into a parallel signal that can be used by the LCD. Most I2C LCDs use the PCF8574 anyway. I’ll explain how to connect it both ways in a minute.
I’ll also show you how to program the LCD using Python, and provide examples for how to print and position the text, clear the screen, scroll text, print data from a sensor, print the date and time, and print the IP address of your Pi.
Connecting an LCD with an I2C backpack is pretty self-explanatory. Connect the SDA pin on the Pi to the SDA pin on the LCD, and the SCL pin on the Pi to the SCL pin on the LCD. The ground and Vcc pins will also need to be connected. Most LCDs can operate with 3.3V, but they’re meant to be run on 5V, so connect it to the 5V pin of the Pi if possible.
If you have an LCD without I2C and have a PCF8574 chip lying around, you can use it to connect your LCD with a little extra wiring. The PCF8574 is an 8 bit I/O expander which converts a parallel signal into I2C and vice-versa. The Raspberry Pi sends data to the PCF8574 via I2C. The PCF8574 then converts the I2C signal into a 4 bit parallel signal, which is relayed to the LCD.
Before we get into the programming, we need to make sure the I2C module is enabled on the Pi and install a couple tools that will make it easier to use I2C.
Now we need to install a program called I2C-tools, which will tell us the I2C address of the LCD when it’s connected to the Pi. So at the command prompt, enter sudo apt-get install i2c-tools.
Next we need to install SMBUS, which gives the Python library we’re going to use access to the I2C bus on the Pi. At the command prompt, enter sudo apt-get install python-smbus.
Now reboot the Pi and log in again. With your LCD connected, enter i2cdetect -y 1 at the command prompt. This will show you a table of addresses for each I2C device connected to your Pi:
We’ll be using Python to program the LCD, so if this is your first time writing/running a Python program, you may want to check out How to Write and Run a Python Program on the Raspberry Pi before proceeding.
There are a couple things you may need to change in the code above, depending on your set up. On line 19 there is a function that defines the port for the I2C bus (I2CBUS = 0). Older Raspberry Pi’s used port 0, but newer models use port 1. So depending on which RPi model you have, you might need to change this from 0 to 1.
The function mylcd.lcd_display_string() prints text to the screen and also lets you chose where to position it. The function is used as mylcd.lcd_display_string("TEXT TO PRINT", ROW, COLUMN). For example, the following code prints “Hello World!” to row 2, column 3:
On a 16×2 LCD, the rows are numbered 1 – 2, while the columns are numbered 0 – 15. So to print “Hello World!” at the first column of the top row, you would use mylcd.lcd_display_string("Hello World!", 1, 0).
You can create any pattern you want and print it to the display as a custom character. Each character is an array of 5 x 8 pixels. Up to 8 custom characters can be defined and stored in the LCD’s memory. This custom character generator will help you create the bit array needed to define the characters in the LCD memory.
The code below will display data from a DHT11 temperature and humidity sensor. Follow this tutorial for instructions on how to set up the DHT11 on the Raspberry Pi. The DHT11 signal pin is connected to BCM pin 4 (physical pin 7 of the RPi).
By inserting the variable from your sensor into the mylcd.lcd_display_string() function (line 22 in the code above) you can print the sensor data just like any other text string.
These programs are just basic examples of ways you can control text on your LCD. Try changing things around and combining the code to get some interesting effects. For example, you can make some fun animations by scrolling with custom characters. Don’t have enough screen space to output all of your sensor data? Just print and clear each reading for a couple seconds in a loop.