This is a part of MP Electronic Devices site.
The information about the use of LCDs (liquid-crystal displays) with the Raspberry Pi is rather sparse, especially when comparing the information about the use of LCDs with Arduino. I think there are several reasons for this:
These problems can be avoided with the following strategies:
On this page I intend to give a basic electronic and programming introduction and instructions on how to use these strategies on different LCDs.
Chip name | Producer | Communication | Vdd | Min. logic High | Compatible chips | Comments |
---|---|---|---|---|---|---|
Graphic LCD | ||||||
KS0108 | Samsung | par (6800) | 4.5 V – 5.5 V | 2.0 V or 0.7 Vdd | ||
RA6963 | RAiO | par (8080) | 3.0 V – 5.5 V | Vdd − 2.2 V | ||
ST7565 | Sitronix | ser (SPI), par (6800 & 8080) | 1.8 V – 3.3 V | 0.8 Vdd | ||
ST7920 | Sitronix | ser (SPI), par (6800) | 2.7 V – 5.5 V | 0.7 Vdd | oscillation resistor 5 V—33 kΩ, 2.7 V—18 kΩ | |
T6963C | Toshiba | par (8080) | 4.5 V – 5.5 V | Vdd − 2.2 V | RA6963 | outdated |
Character LCD | ||||||
HD44780 | Hitachi | par (6800) | 2.7 V – 5.5 V | 0.7 Vdd | SPLC780C, ST7066, KS0066 | oscillation resistor 5 V—91 kΩ, 3.0 V—75 kΩ |
Graphic epaper | ||||||
SSD1680 | Solomon Systech | ser (SPI†) | 2.2 V – 3.7 V | 0.8 Vdd |
As the table above shows, most LCD controller chips support 5 V logic, but there are a number of chips that support both 3.3 V and 5 V logic.
But even if the LCD controller chip is supplied with 5 V and operates in 5 V logic, it can sometimes accept 3.3 V as logic High. For example, if the RA6963 chip is supplied with Vdd = 5 V, it will accept anything above 5 V − 2.2 V = 2.8 V as a logic High. In these cases, however, the device can only be used in write mode – using the LCD in read mode may destroy Raspberry Pi!
The biggest problem, however, is not the LCD controller chip supply voltage, but the unrelated supply voltage required for operating liquid crystals. If the supply voltage is too high, the pixel is always dark, if the supply voltage is too low, the pixel is always bright. The optimal supply voltage depends on the LCD device and also on the temperature.
The temperature dependence is taken into account by an external potentiometer for the so-called contrast management. However, many LCD devices do not support contrast management and can only be used at room temperature. The more annoying problem is that the optimal supply voltage for liquid crystals is usually above 3.3 V (and usually below 5 V), which makes LCD devices supplied at 5 V much simpler.
LCD devices that are supplied with 3.3 V use so-called charge pumps that generate negative potential. The total difference between supply potential and negative potential is then larger than 3.3 V and is sufficient for operating liquid crystals.
Sometimes LCD devices are sold for the 5 V supply, but there is a free space on the PCB (printed circuit board) for the charge pump, and the device can be adapted for the 3.3 V supply. In such cases it is best to consult the seller regarding the adaptation, but with some basic knowledge of electronics such situations can be identified and the device adapted without consultation.
The figure above left shows how a charge pump (MAX660, ICL7660) can be used as a voltage inverter. The total voltage between Vdd and −Vdd doubles the starting voltage and is in most cases sufficient for liquid crystal supply. The picture above right shows a typical free space on the PCB for the charge pump, where U7 stands for the charge pump, while C8 and C9 stand for two capacitors.
Liquid crystals do not generate the light, but block it. Therefore, every LCD device must have a light source behind the liquid crystals, which consists of one or more light emitting diodes (LED). Although LED and chip share the same PCB, their circuits are galvanically isolated. This makes it possible to supply the backlight LEDs with 5 V, even if the LCD device is used with Raspberry Pi.
The topic that needs to be addressed is maximum LED current. If the current through the LED is too high, it can destroy it. To limit this current, a resistor is connected in series with a LED. It is common that the LCD device already has an appropriate resistor for the maximum permissible current at a designed supply voltage. If not, such a resistor must be connected in series by the user. Note that since LEDs are required to illuminate large displays, their typical maximum current is between a few tens of mA and 100 mA.
In principle one could calculate the value of the appropriate resistor RL by knowing the supply voltage Vdd, the LED voltage drop VL and the designed LED current IL by RL = (Vdd − VL)/IL. The problem is that the LED voltage drop is not constant, but depends on the LED current, as one can see for example see on this page. The exact relationship depends on several factors, especially the LED colour, and is generally not provided by the manufacturer of LCD device. In case you have to determine the resistance value yourself, I suggest an experimental method where LEDs, potentiometer and ammeter are connected in series.
Sometimes a user wants to control the backlight by turning it on and off and changing its brightness. Since the individual Raspberry Pi GPIO current is limited to 16 mA, this usually means that backlight LEDs cannot be sufficiently supplied directly by GPIO pin. Fortunately, a very simple circuit with a common inexpensive NPN transistor can be used, as shown in the figure above. If the GPIO pin is set to High, the transistor is open and can be considered a short circuit. The resistor RG is used to limit the GPIO current. If the current gain of the transistor hFE is known, the resistor can be calculated using the expression RG = 3.3 V × hFE / IL. Typically for 2N3904 and IL = 100 mA, hFE ≥ 30, so RG = 1 kΩ.
This setup can be used for both a 5 V and a 3.3 V supply. So if the LCD device design supply is 5 V, the backlight can be supplied by the 5 V rail of Raspberry Pi without any changes to the PCB.
The same setup can also be used for brightness control using a pulse width modulated (PWM) GPIO pin. The pulse width modulation turns the GPIO pin High and Low very fast, so fast that our eyes do not detect the flickering. As the share of High state drops, the perceived brightness decreases.
All LCD controller chips have RAM (random access memory) which can be accessed and modified by communicating with the chip. A specific memory address corresponds to a bit on the graphic LCD or a character on the character LCD.
In a graphic LCD, when the byte at the home memory address is set to 0x50 (0b01010000), the second and fourth bits in the first line of the display become dark.
In a character LCD, when the byte at the home memory address is set to 0x50, the first character in the first line of the display is usually the letter 'P', since the ASCII code for 'P' is 0x50. Character LCDs also have CGROM and CGRAM (character generation RAM and ROM) where glyphs are defined for characters. Eight bytes are required to define glyphs for 8 × 8 character: The letter 'P' in the figure above can be defined by bytes 0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10, 0x00 (0b00011110, 0b00010001, 0b00010001, 0b00011110, 0b00010000, 0b00010000, 0b00010000, 0b00000000). This is important to understand because most character LCDs have additional memory set in which user-defined glyphs, usually non-ASCII characters, can be defined.
In some cases the LCD controller chip supports both graphics and text. In this case, the chip has three memory sets: one for displayed bits, one for displayed characters, and one for character generation.
Mostly two different parallel communication protocols are used, which were introduced with the microprocessors Intel 8080 and Motorola 6800. These communication protocols are usually simply referred to as 8080 and 6800.
Both protocols use in principle 11 lines, 3 control lines and 8 bit lines. The 8 bit lines transmit the byte, while the control lines determine whether the byte is a command or a datum, determine whether the byte is to be read or written, and trigger the byte transmission.
The figure above shows the simplified process of both communication types.
For type 8080, both lines WR and RD must be High before communication. At the start, line C/D must be set to determine whether the byte is a command or a datum.
For type 6800, the line E must be Low before communication. At the start, line RS must be set to determine whether the byte is a command or a datum and the line R/W must be set to determine whether the byte is to be read or written.
If the communication is programmed in Python, it takes about 1 ms to send one byte. With large amounts of data, the entire communication can take up to several seconds. However, if pigpio module scripts and C code are used, the transmission time can be reduced to about 20 µs and 20 µs, respectively. All the specified times being measured at Raspberry Pi 3. For large LCDs, especially graphic ones, the use of pigpio scripts or C code is essential to achieve a sufficient refresh rate.
If you are interested in using the general purpose C library for parallel communications at Raspberry Pi, you can find it here. Note that the speed of the library is limited by a very inefficient gettime
function, which takes about 250 ns to run on Raspberry Pi 3.
This LCD controller chip has several extraordinary capabilities:
The RA6963 chip operates at both 3.3 V and 5 V. However, a very high supply voltage is required for the liquid crystals.
The picture above shows the PCB of the 5 V supply voltage 13 cm 240 × 128 graphic LCD device. For this device, the required supply voltage for the liquid crystals is 17.3 V at room temperature. This is achieved by using two voltage inverters connected in series, U9 and U10, which generate a negative potential of −3Vdd = −15 V. Note that there is free space for the third voltage inverter connected in series, U11, which allows a total negative potential of −5 Vdd. The third inverter is short-circuited by a zero resistance at position C19.
The seller claimed that the device could be adapted to the 3.3 V supply voltage by replacing the 0805 resistor R4 from 21.5 kΩ to 6.8 kΩ, which reduces required supply voltage for the liquid crystals. After the replacement, the contrast at room temperature is hardly sufficient, so I intend to investigate other options. Two 47 Ω 1206 resistors R12 and R13 in parallel limit the current through the LED backlight to 55 mA at 5 V supply. One of two resistors should be replaced from 47 Ω to 6.8 Ω if the backlight is to be supplied with a voltage of 3.3 V.
The figure above shows the setup for using the LCD device, which is suitable for both 5 V and 3.3 V supply. Even if the RA6963 chip is supplied with Vdd = 5 V, it accepts anything above 2.8 V as a logic High (see LCD voltage), that is it can be used in the write-only mode with Raspberry Pi. The write-only mode in the setup is achieved by connecting RD to Vdd. Please note that if the LCD device is supplied with 5 V, the read mode destroys the Raspberry Pi! The chip enable CE, the font select FS and the frame ground FG are connected to ground. The line VOUT is the output of voltage inverters, V0 is the liquid crystals supply and a potentiometer is used to optimize the latter.
The RA6963 chip has an additional reset line RES or RST. To reset the chip, this line is set to Low for a short time. The chip must be reset after power-up.
According to the manual, a status check must be performed before reading or writing data to ensure that the chip is ready to execute commands and read or write data. If the chip is supplied with 5 V, this check cannot be performed by Raspberry Pi, as reading 5 V logic data may destroy it. On the other hand, the speed of the chip is very high and the chip is ready after only a few hundred nanoseconds (much more than Raspberry Pi needs to prepare the communication). Therefore, status checks can be avoided completely.
Many commands for the RA6963 chip require one or two bytes as parameters. According to the chip protocol, these parameters are sent before the command. Since two byte parameters usually represent a low and a high part of the memory address, the corresponding Python function can be written as follows:
def writecommand(self, com, num=0, dat=0):
while num>=0:
if num==0:
value=com
self._gpio.write(self._cd, 1)
else:
value=dat
self._gpio.write(self._cd, 0)
self._gpio.write(self._d0,value & 0x01)
self._gpio.write(self._d1,(value & 0x02) >> 1)
self._gpio.write(self._d2,(value & 0x04) >> 2)
self._gpio.write(self._d3,(value & 0x08) >> 3)
self._gpio.write(self._d4,(value & 0x10) >> 4)
self._gpio.write(self._d5,(value & 0x20) >> 5)
self._gpio.write(self._d6,(value & 0x40) >> 6)
self._gpio.write(self._d7,(value & 0x80) >> 7)
self._gpio.write(self._wr,False)
self._gpio.write(self._wr,True)
dat = dat >> 8
num=num-1
By default, this function assumes a command com
without parameters. If a parameter is required, dat
indicates whether the parameter has one byte (int8) or two bytes (int16), while dat
is an actual parameter. The _cd
corresponds to the C/D line, the _wr
to the WR line, while _d0
correspond to _d7
to the data lines.
It would be very inefficient to write to or read from chip memory with one command for every byte. For this reason, the RA6963 chip defines the data auto read and write. As in the corresponding Python function below, the procedure starts with issuing the auto write command, followed by sending the data list and ends with issuing the auto reset command:
LCD_SETDATAAUTOWRITE = 0xB0
LCD_AUTORESET = 0xB2
def writedata(self, data):
self.writecommand(LCD_SETDATAAUTOWRITE)
self._gpio.write(self._cd, 0)
for value in data:
self._gpio.write(self._d0,value & 0x01)
self._gpio.write(self._d1,(value & 0x02) >> 1)
self._gpio.write(self._d2,(value & 0x04) >> 2)
self._gpio.write(self._d3,(value & 0x08) >> 3)
self._gpio.write(self._d4,(value & 0x10) >> 4)
self._gpio.write(self._d5,(value & 0x20) >> 5)
self._gpio.write(self._d6,(value & 0x40) >> 6)
self._gpio.write(self._d7,(value & 0x80) >> 7)
self._gpio.write(self._wr,False)
self._gpio.write(self._wr,True)
self.writecommand(LCD_AUTORESET)
Here, data
is a list of bytes to be written to memory.
When the LCD device is in graphic mode, a total of 240 × 128 bits or a total of 3840 bytes should be sent for one full screen picture. If the communication is programmed in Python, this takes about 4.5 s, which is obviously too much (Raspberry Pi 3).
However, if pigpio module scripts or C code are used, the transmission time can be significantly reduced. Writing scripts is somewhat complex because it follows the syntax of Assembly language and is currently limited to transmitting 40 bytes per stack. I have therefore written C code and a corresponding Python library, which can be accessed here.
For easier understanding a test Python file is also included. Note that a contiguous data block must be prepared in Python so that C code can access it directly.
When using pigpio module scripts, the transmission time for the full 240 × 128 bits screen is approximately 68 ms, of which 35 ms is for script operation, 16 ms for triggering scripts, and 17 ms for the rest (Raspberry Pi 3). When using C code, this time is further reduced to approximately 14 ms. A simple demonstration of the C code library executed by the supplied test Python file is shown in the video below.
This LCD controller chip has two extraordinary capabilities:
It is by far the most common character LCD controller and there are many Python libraries that support it.
The HD44780 chip operates at both 3.3 V and 5 V. However, a supply voltage of 4 V – 5 V is required for the liquid crystals.
The picture above shows the PCB of the 5 V supply voltage 15 cm 40 × 4 character LCD device. It contains two HD44780 compatible chips, one of which operates the upper half of the screen and one the lower half. Three 100 Ω resistors R13, R14, R15 in parallel limit the current through the LED backlight to 100 mA at 5 V supply. The device has the pin 12 as the liquid crystal supply V0, but this line goes through jumper J1, which is not activated. Therefore, the supply voltage for liquid crystals cannot be adjusted by default, and the device may only have good contrast at room temperature.
On closer inspection, the liquid crystal supply is connected to the left side of jumper J1, the right side of R8 and the left side of R9. By default, the supply is shortened by zero resistance at R8 to ground. However, if one wants supply the LCD device with 3.3 V instead of 5 V, the supply potential of liquid crystals must be reduced to −1.7 V. This is achieved by removing resistor R8, installing a charge pump (MAX660, ILC7660) at U7, two 10 µF capacitors at C8 and C9 and 3 kΩ resistor at R9. As before, the supply voltage for the liquid crystals cannot be adjusted, so the contrast is convinient only for room temperature. Finally, according to the manual, R6 should be replaced by 75 kΩ.
The figure above shows the setup for using the LCD controller with 4 wire parallel communication and backlight control. When the HD44780 compatible chip is supplied with Vdd = 5 V, it accepts anything above 0.7 Vdd = 3.5 V as a logic High (see LCD voltage). Theoretically this means that it could not even be used with Raspberry Pi, but in practice 3.3 V is sufficient to use the chip in the write-only mode. The write-only mode in the setup is achieved by connecting R/W to ground. Please note that if the LCD device is supplied with 5 V, the read mode destroys the Raspberry Pi! The V0 is for the liquid crystal supply and a potentiometer is used to optimize it.
All commands for the HD44780 chip consist of only one byte, part of which can also be a parameter. It is therefore reasonable to write a single function that writes command or data bytes. The corresponding Python function can be written as follows:
def writebyte(self, value, char_mode=False):
if char_mode:
self._gpio.write(self._rs, 1)
else:
self._gpio.write(self._rs, 0)
self._gpio.write(self._d7,(value & 0x80) >> 7)
self._gpio.write(self._d6,(value & 0x40) >> 6)
self._gpio.write(self._d5,(value & 0x20) >> 5)
self._gpio.write(self._d4,(value & 0x10) >> 4)
self._gpio.write(self._en,True)
self._gpio.write(self._en,False)
self._gpio.write(self._d7,(value & 0x08) >> 3)
self._gpio.write(self._d6,(value & 0x04) >> 2)
self._gpio.write(self._d5,(value & 0x02) >> 1)
self._gpio.write(self._d4,value & 0x01)
self._gpio.write(self._en,True)
self._gpio.write(self._en,False)
By default, this function assumes a command. The _en
corresponds to the E line, the _rs
to the RS line, while _d0
correspond to _d7
to the data lines.
A total of 40 × 4 characters or a total of 320 half-bytes should be sent for one full screen text. If the communication is programmed in Python, this takes about 0.27 s, which is already unpleasant for the eye (Raspberry Pi 3). It is even slower when using Raspberry Pi Zero.
However, if pigpio module scripts or C code are used, the transmission time can be significantly reduced. Writing scripts is somewhat complex because it follows the syntax of Assembly language and is currently limited to transmitting 40 bytes per stack. I have therefore written C code a corresponding Python library, which can be accessed here.
It is important to note that the chip is rather slow in processing data. The manual states that the execution time for each byte is 37 µs. However, I have found experimentally that 55 µs is required when the chip is supplied with 3.3 V. In my library the value for the execution time can be selected by the user.
For easier understanding a test Python file is also included. Note that a contiguous data block must be prepared in Python so that C code can access it directly.
When using pigpio module scripts, the transmission time for the full 40 × 4 character screen is approximately 15 ms (Raspberry Pi 3). When using C code, this time is further reduced to approximately 10 ms. A simple demonstration of the C code library executed by the supplied test Python file is shown in the video below.
Many other useful resources for setting up and programming this chip are also available on the Internet, of which I especially recommend the following two. Programming the HD44780 LCD Display with Raspberry Pi gives instructions for programming the parallel communication, while LCD16x2 HD44780 Tutorial has a good overview of the chip's commands.
This LCD controller chip has several extraordinary capabilities:
This makes the devices with this chip suitable for more demanding environments, such as battery supply and adaptation to temperature-related contrast changes.
The chip also has some other more unconventional capabilities, but they may not be supported by a particular LCD device, as is the case with the device I tested.
On the other hand, the pixels are arranged in a very unusual way and only graphics are supported, which makes programming much more difficult.
The ST7565 chip operates at voltages up to 3.3 V, so most devices sold on the Internet are Raspberry Pi friendly.
The picture above shows the PCB of the 3.3 V supply voltage 8.5 cm 128 × 64 graphic LCD device. The 10 Ω resistor R11 limits the current through the LED backlight to 20 mA at 3.3 V supply voltage. Positions R6 and R7 select between 8080 and 6800 parallel communications, while R8 and R9 select between serial and parallel communications. Selection between serial and parallel communications can also be made via pin PS if none of the R8 and R9 positions are shorted. By default on this PCB serial communication is selected by a zero resistor at R9, and in the case of parallel communication, 6800 communication is selected by a zero resistor at R6. I have removed resistor R9 and select between serial and parallel communication using pin PS. Do not use the pin PS if the selection between serial and parallel communication has already been made on the PCB, as this can destroy Raspberry Pi!
The pixels on the screen are arranged in pages of eight lines each. Each screen is then divided into columns of eight pixels represented by a byte in the chip's memory. The memory is not contiguous, so switching between pages is possible only by a special command. This unusual arrangement is advantageous when pages are used as lines filled with variable-width or narrow 8-pixel fonts rather than the more common monospace 8-pixel fonts. For all other uses, the programming is much more complicated.
The chip supports serial SPI communication and two parallel 6800- and 8080-based communications. Line A0 (labeled RS on the PCB above) is used by all three types to select between data and command (CD for 8080 and RS for 6800). The remaining control lines for parallel communication (RD, WR for 8080 and RS, R/W for 6800) are shared. All data lines DB0 through DB7 are used by both parallel communications, while lines DB6 and DB7 are also used for the SCLK and MOSI lines of serial communication. The MISO line is not present because the serial communication is write-only. Finally the CS and RES lines are used to select and reset the chip, respectively.
Thus, if the chip is always selected, only four lines are sufficient for serial communication. Moreover, the frequency of serial communication ranges up to 50 MHz. Since the number of pixels is relatively small, the transmission time for the full 128 × 64 pixel screen is approximately 4 ms (Raspberry Pi 3), most of which corresponds to Python calling the SPI C code to change pages and switch between command and data modes. This speed is sufficient and there is no need to bother with parallel communication. A simple demonstration of the SPI C code library executed by the supplied test Python file is shown in the video below.
This LCD controller chip has several extraordinary capabilities:
The ST7920 chip operates at both 3.3 V and 5 V. However, a supply voltage of 4 V – 5 V is required for the liquid crystals.
The picture above shows the PCB of the 3.3 V supply voltage 8.5 cm 128 × 64 graphic LCD device. For this device, the required supply voltage for the liquid crystals is 4.7 V at room temperature. With a small supply voltage, this is achieved with a voltage larger than Vdd, unlike other graphic displays. One possibility is to supply the voltage via the built-in potentiometer VR1. The supply is controlled by jumper JP3. For high supply voltages, the potentiometer is connected directly to supply Vdd in the right jumper position. On the other hand, for lower supply voltages, Vdd ≤ 4.0 V, the left jumper position is used to connect the potentiometer to the output of the built-in charge pump. The charge pump is activated with capacitors of 4.7 µF at positions C4 and C5. Do not activate the charge pump at Vdd > 4.0 V! Finally, a suitable voltage for liquid crystals can be supplied directly to line V0. With external liquid crystals supply the jumper JP3 must remain unselected!
The 30 Ω resistor R10 limits the current through the LED backlight to 70 mA at 5 V supply voltage. Selection between serial SPI and parallel 6800 communications can also be made either by jumper JP2 or line PSB if none of the jumper positions are shorted. By default, jumper selection is not used on this PCB. Do not use pin PSB if the selection between serial and parallel communication has already been made on the PCB, as this can destroy Raspberry Pi! Resistor R7 controls the oscillation frequency and should be 33 kΩ for 5 V and 18 kΩ for 2.7 V accoring to the manual. Resistor R6 is the pull-up resistor for the reset line.
The figure above shows the setup for using the LCD controller with 4 wire parallel communication and backlight control. Note that parallel communication is selected by setting the line PSB High. When the ST7920 is supplied with Vdd = 5 V, it accepts anything above 0.7 Vdd = 3.5 V as a logic High (see LCD voltage). Theoretically this means that it could not even be used with Raspberry Pi, but in practice 3.3 V is sufficient to use the chip in the write-only mode. The write-only mode in the setup is achieved by connecting R/W to ground. Please note that if the LCD device is supplied with 5 V, the read mode destroys the Raspberry Pi! Since the Raspberry Pi provides a 5 V supply line, I decided to use to directly supply the liquid crystals directly without having to use a build-in charge pump.
The chip has the following predefined characters:
Despite the extensive character capacities, they are practically useless when using Latin characters. Full-size Latin characters are simply too large to present a meaningful message, while no additional half-size characters can be defined.
The ST7920 chip has an additional reset line RST. To reset the chip, this line is set Low for a short time. According to the manual, the chip must be reset after power-up.
The ST7920 is actually designed to display 256 × 32 pixels, but its memory supports a total of two full pages, for a total of 256 × 64 pixels. The first line to be displayed can be selected, so that for the intended setup the image can be vertically scrolled. Correspondingly, the device is designed to display 2 lines of 16 full-size characters or 32 half-size characters, but its memory supports a total of 4 lines. While the characters of one line are followed without interruption by the characters of the next line, the pixels of one row are not followed by the pixels of the next row. Each memory location holds a 16-bit number.
To use the chip for 128 × 64 graphic LCD devices, the left side addresses represent the top of the display and the right side addresses represent the bottom of the display. As a result, pixels follow without interruption from row 0 to row 32, from row 31 to row 63, from row 64 to row 96 and from row 95 to row 127. Correspondingly, characters follow without interruption from line 0 to line 2 to line 1 to line 3 to line 4 to line 6 to line 5 and finally to line 7. This makes vertical scrolling between two pages completely pointless.
Another awkward thing is the communication protocols. For every 8-bit datum, three 8-bit data must be sent serially. Also, there is no command for automatic write or read: Each 16-bit write must be preceded by an 8-bit command. According to the manual, the top frequency at 2.7 V is 1.7 MHz for serial and 0.8 MHz for parallel communication, but in fact the chip easily manages frequencies up to 10 MHz. Despite the relatively small number of pixels, the transmission time for the full 128 × 64 pixel screen is approximately 240 ms and 60 ms (Raspberry Pi 3) for serial and parallel communications, respectively, most of which corresponds to Python calls to the serial/parallel C code to issue a write command and write data. A simple demonstration of the parallel C code library executed by the supplied test Python file is shown in the video below.
This epaper controller chip has several extraordinary capabilities:
The ST7920 chip operates at 3.3 V. Apart from the selection between 3-wire and 4-wire SPI, there is not much to change or regulate with this chip.
†The SSD1680 chip allows a standard 4-wire SPI and an unusual 3-wire SPI, but neither is fully standard. Standard SPI includes MOSI (Master Out Slave In), MISO (Master In Slave Out), SCLK (Serial Clock) and CS (Chip Select). This chip combines the functions of MOSI and MISO in one SDA line, which is extremely dangerous because with signals fully driven in both directions, either master or slave can easily be damaged. Make sure that none of the read commands (0x1B, 0x27, 0x2D, 0x2E, 0x2F, 0x35) are ever invoked! In addition to the lines SDA, SCLK and CS, there is also the line DC, which selects between command and data bytes, giving a total of four lines. The line DC can be avoided by using 3-wire SPI, where the selection between command and data bytes is achieved by an extra bit, making a nonstandard 9-bit communication that requires bitbanging. In my opinion, this is not worth the effort. I recommend using only 4-wire communication in writing only, which allows the use of standard SPI communication.
The SSD1680 chip also has two additional lines RES (reset) and BUSY. To reset the chip, RES is set Low for a short time. According to the manual, the chip must be reset after power-up. The line BUSY can be read to determine whether the chip is ready to accept the next command. Thus, if the chip is always selected and appropriate time pauses are used instead of checking the BUSY line, only four lines are sufficient for communication.
The chip only supports graphics, with two buffers, one for the white colour and one for the red colour, each of size 296 × 176 bytes. If the communication is programmed in Python, a total of 13024 bytes would take several seconds. The frequency of the serial communication ranges up to 20 MHz. However, the transmission time for the 296 × 128 pixel screen is only about 5 ms (Raspberry Pi 4), when the standard Linux driver SPI communication is used. I have therefore written C code and a corresponding Python library, which can be accessed here. A simple demonstration of the SPI C code library executed by the supplied test Python file is shown in the video below.
The available commands can be divided into two groups. The first group relates to data processing - how do the bits in the buffer correspond to the pixels on the screen. There are many options, such as choosing the direction of the pixels on the screen and which pixel position, horizontal or vertical, changes first when an address is increased. It is also possible to choose whether the data for the entire buffer or only part of it is transmitted via SPI communication. If the SPI communication is done properly and the transmission takes only a few milliseconds, sending data for only part of the buffer makes little sense and is therefore not used in the sample code. The display of the bits in the buffer as pixels on the screen is then triggered by a special pair of commands.
The pixels on the 296 × 128 screen are arranged in sixteen lines each, each in turn divided into columns of eight pixels represented by one byte in the chip's buffer. The memory is not contiguous, that is when the last datum in a column/row is reached, the data continue in the next column/row.
The second group of commands relates to so-called lookup tables (LUTs). The LUTs and other relevant settings determine which voltages and in which order are applied to the ink capsules within the display to obtain the correct distribution with the correct appearance. Usually there is already a set of in-built producer-defined LUTs on the chip, which are selected depending on the ambient temperature. Note that the epapers should display good contrast and permanent images, which comes at the cost of very slow refresh, which is about 5 s for single colour displays and 20 s for two colour displays. However, user can specify other conditions, such as a faster full single colour refresh or a two colour display and much faster and less conspicuous partial refresh, but at the cost of lower image quality. There is very little that a hobbyist can invent on these issues.
Various Displays & Display Backpacks by Trevor Gowen
Please use the feedback form to tell me what else you would like to see here, suggestions, new tricks, etc.
Created by Marko Pinteric: feedback form.
Updated . Web page has been read by visitors since October 2020.