controlling leds with tft display free sample
In this Arduino touch screen tutorial we will learn how to use TFT LCD Touch Screen with Arduino. You can watch the following video or read the written tutorial below.
The next example is controlling an RGB LED using these three RGB sliders. For example if we start to slide the blue slider, the LED will light up in blue and increase the light as we would go to the maximum value. So the sliders can move from 0 to 255 and with their combination we can set any color to the RGB LED, but just keep in mind that the LED cannot represent the colors that much accurate.
As an example I am using a 3.2” TFT Touch Screen in a combination with a TFT LCD Arduino Mega Shield. We need a shield because the TFT Touch screen works at 3.3V and the Arduino Mega outputs are 5 V. For the first example I have the HC-SR04 ultrasonic sensor, then for the second example an RGB LED with three resistors and a push button for the game example. Also I had to make a custom made pin header like this, by soldering pin headers and bend on of them so I could insert them in between the Arduino Board and the TFT Shield.
Here’s the circuit schematic. We will use the GND pin, the digital pins from 8 to 13, as well as the pin number 14. As the 5V pins are already used by the TFT Screen I will use the pin number 13 as VCC, by setting it right away high in the setup section of code.
As the code is a bit longer and for better understanding I will post the source code of the program in sections with description for each section. And at the end of this article I will post the complete source code.
I will use the UTFT and URTouch libraries made by Henning Karlsen. Here I would like to say thanks to him for the incredible work he has done. The libraries enable really easy use of the TFT Screens, and they work with many different TFT screens sizes, shields and controllers. You can download these libraries from his website, RinkyDinkElectronics.com and also find a lot of demo examples and detailed documentation of how to use them.
After we include the libraries we need to create UTFT and URTouch objects. The parameters of these objects depends on the model of the TFT Screen and Shield and these details can be also found in the documentation of the libraries.
Next we need to define the fonts that are coming with the libraries and also define some variables needed for the program. In the setup section we need to initiate the screen and the touch, define the pin modes for the connected sensor, the led and the button, and initially call the drawHomeSreen() custom function, which will draw the home screen of the program.
So now I will explain how we can make the home screen of the program. With the setBackColor() function we need to set the background color of the text, black one in our case. Then we need to set the color to white, set the big font and using the print() function, we will print the string “Arduino TFT Tutorial” at the center of the screen and 10 pixels down the Y – Axis of the screen. Next we will set the color to red and draw the red line below the text. After that we need to set the color back to white, and print the two other strings, “by HowToMechatronics.com” using the small font and “Select Example” using the big font.
Next is the distance sensor button. First we need to set the color and then using the fillRoundRect() function we will draw the rounded rectangle. Then we will set the color back to white and using the drawRoundRect() function we will draw another rounded rectangle on top of the previous one, but this one will be without a fill so the overall appearance of the button looks like it has a frame. On top of the button we will print the text using the big font and the same background color as the fill of the button. The same procedure goes for the two other buttons.
Here’s that function which uses the ultrasonic sensor to calculate the distance and print the values with SevenSegNum font in green color, either in centimeters or inches. If you need more details how the ultrasonic sensor works you can check my particular tutorialfor that. Back in the loop section we can see what happens when we press the select unit buttons as well as the back button.
Ok next is the RGB LED Control example. If we press the second button, the drawLedControl() custom function will be called only once for drawing the graphic of that example and the setLedColor() custom function will be repeatedly called. In this function we use the touch screen to set the values of the 3 sliders from 0 to 255. With the if statements we confine the area of each slider and get the X value of the slider. So the values of the X coordinate of each slider are from 38 to 310 pixels and we need to map these values into values from 0 to 255 which will be used as a PWM signal for lighting up the LED. If you need more details how the RGB LED works you can check my particular tutorialfor that. The rest of the code in this custom function is for drawing the sliders. Back in the loop section we only have the back button which also turns off the LED when pressed.
In order the code to work and compile you will have to include an addition “.c” file in the same directory with the Arduino sketch. This file is for the third game example and it’s a bitmap of the bird. For more details how this part of the code work you can check my particular tutorial. Here you can download that file:
The ST7789 TFT module contains a display controller with the same name: ST7789. It’s a color display that uses SPI interface protocol and requires 3, 4 or 5 control pins, it’s low cost and easy to use. This display is an IPS display, it comes in different sizes (1.3″, 1.54″ …) but all of them should have the same resolution of 240×240 pixel, this means it has 57600 pixels. This module works with 3.3V only and it doesn’t support 5V (not 5V tolerant).
The ST7789 display module shown in project circuit diagram has 7 pins: (from right to left): GND (ground), VCC, SCL (serial clock), SDA (serial data), RES (reset), DC (or D/C: data/command) and BLK (back light).
As mentioned above, the ST7789 TFT display controller works with 3.3V only (power supply and control lines). The display module is supplied with 3.3V (between VCC and GND) which comes from the Arduino board.
To connect the Arduino to the display module, I used voltage divider for each line which means there are 4 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.
The first library is a driver for the ST7789 TFT display which can be installed from Arduino IDE library manager (Sketch —> Include Library —> Manage Libraries …, in the search box write “st7789” and install the one from Adafruit).
In this guide we’re going to show you how you can use the 1.8 TFT display with the Arduino. You’ll learn how to wire the display, write text, draw shapes and display images on the screen.
The 1.8 TFT is a colorful display with 128 x 160 color pixels. The display can load images from an SD card – it has an SD card slot at the back. The following figure shows the screen front and back view.
This module uses SPI communication – see the wiring below . To control the display we’ll use the TFT library, which is already included with Arduino IDE 1.0.5 and later.
The TFT display communicates with the Arduino via SPI communication, so you need to include the SPI library on your code. We also use the TFT library to write and draw on the display.
In which “Hello, World!” is the text you want to display and the (x, y) coordinate is the location where you want to start display text on the screen.
The 1.8 TFT display can load images from the SD card. To read from the SD card you use the SD library, already included in the Arduino IDE software. Follow the next steps to display an image on the display:
Note: some people find issues with this display when trying to read from the SD card. We don’t know why that happens. In fact, we tested a couple of times and it worked well, and then, when we were about to record to show you the final result, the display didn’t recognized the SD card anymore – we’re not sure if it’s a problem with the SD card holder that doesn’t establish a proper connection with the SD card. However, we are sure these instructions work, because we’ve tested them.
In this guide we’ve shown you how to use the 1.8 TFT display with the Arduino: display text, draw shapes and display images. You can easily add a nice visual interface to your projects using this display.
This new library is a standalone library that contains the TFT driver as well as the graphics functions and fonts that were in the GFX library. This library has significant performance improvements when used with an UNO (or ATmega328 based Arduino) and MEGA.
Examples are included with the library, including graphics test programs. The example sketch TFT_Rainbow_one shows different ways of using the font support functions. This library now supports the "print" library so the formatting features of the "print" library can be used, for example to print to the TFT in Hexadecimal, for example:
To use the F_AS_T performance option the ILI9341 based display must be connected to an MEGA as follows:MEGA +5V to display pin 1 (VCC) and pin 8 (LED) UNO 0V (GND) to display pin 2 (GND)
In the library Font 0 (GLCD font), 2, 4, 6 and 8 are enabled. Edit the Load_fonts.h file within the library folder to enable/disable fonts to save space.
TFT_ILI9341 library updated on 1st July 2015 to version 12, this latest version is attached here to step 8:Minor bug when rendering letter "T" in font 4 without background fixed
In this article, you will learn how to use TFT LCDs by Arduino boards. From basic commands to professional designs and technics are all explained here.
In electronic’s projects, creating an interface between user and system is very important. This interface could be created by displaying useful data, a menu, and ease of access. A beautiful design is also very important.
There are several components to achieve this. LEDs, 7-segments, Character and Graphic displays, and full-color TFT LCDs. The right component for your projects depends on the amount of data to be displayed, type of user interaction, and processor capacity.
TFT LCD is a variant of a liquid-crystal display (LCD) that uses thin-film-transistor (TFT) technology to improve image qualities such as addressability and contrast. A TFT LCD is an active matrix LCD, in contrast to passive matrix LCDs or simple, direct-driven LCDs with a few segments.
In Arduino-based projects, the processor frequency is low. So it is not possible to display complex, high definition images and high-speed motions. Therefore, full-color TFT LCDs can only be used to display simple data and commands.
In this article, we have used libraries and advanced technics to display data, charts, menu, etc. with a professional design. This can move your project presentation to a higher level.
In electronic’s projects, creating an interface between user and system is very important. This interface could be created by displaying useful data, a menu, and ease of access. A beautiful design is also very important.
There are several components to achieve this. LEDs, 7-segments, Character and Graphic displays, and full-color TFT LCDs. The right component for your projects depends on the amount of data to be displayed, type of user interaction, and processor capacity.
TFT LCD is a variant of a liquid-crystal display (LCD) that uses thin-film-transistor (TFT) technology to improve image qualities such as addressability and contrast. A TFT LCD is an active matrix LCD, in contrast to passive matrix LCDs or simple, direct-driven LCDs with a few segments.
In Arduino-based projects, the processor frequency is low. So it is not possible to display complex, high definition images and high-speed motions. Therefore, full-color TFT LCDs can only be used to display simple data and commands.
In this article, we have used libraries and advanced technics to display data, charts, menu, etc. with a professional design. This can move your project presentation to a higher level.
Size of displays affects your project parameters. Bigger Display is not always better. if you want to display high-resolution images and signs, you should choose a big size display with higher resolution. But it decreases the speed of your processing, needs more space and also needs more current to run.
After choosing the right display, It’s time to choose the right controller. If you want to display characters, tests, numbers and static images and the speed of display is not important, the Atmega328 Arduino boards (such as Arduino UNO) are a proper choice. If the size of your code is big, The UNO board may not be enough. You can use Arduino Mega2560 instead. And if you want to show high resolution images and motions with high speed, you should use the ARM core Arduino boards such as Arduino DUE.
In electronics/computer hardware a display driver is usually a semiconductor integrated circuit (but may alternatively comprise a state machine made of discrete logic and other components) which provides an interface function between a microprocessor, microcontroller, ASIC or general-purpose peripheral interface and a particular type of display device, e.g. LCD, LED, OLED, ePaper, CRT, Vacuum fluorescent or Nixie.
The display driver will typically accept commands and data using an industry-standard general-purpose serial or parallel interface, such as TTL, CMOS, RS232, SPI, I2C, etc. and generate signals with suitable voltage, current, timing and demultiplexing to make the display show the desired text or image.
The LCDs manufacturers use different drivers in their products. Some of them are more popular and some of them are very unknown. To run your display easily, you should use Arduino LCDs libraries and add them to your code. Otherwise running the display may be very difficult. There are many free libraries you can find on the internet but the important point about the libraries is their compatibility with the LCD’s driver. The driver of your LCD must be known by your library. In this article, we use the Adafruit GFX library and MCUFRIEND KBV library and example codes. You can download them from the following links.
By these two functions, You can find out the resolution of the display. Just add them to the code and put the outputs in a uint16_t variable. Then read it from the Serial port by Serial.println(); . First add Serial.begin(9600); in setup().
Upload your image and download the converted file that the UTFT libraries can process. Now copy the hex code to Arduino IDE. x and y are locations of the image. sx and sy are size of the image.
In this template, We converted a .jpg image to .c file and added to the code, wrote a string and used the fade code to display. Then we used scroll code to move the screen left. Download the .h file and add it to the folder of the Arduino sketch.
In this template, We used sin(); and cos(); functions to draw Arcs with our desired thickness and displayed number by text printing function. Then we converted an image to hex code and added them to the code and displayed the image by bitmap function. Then we used draw lines function to change the style of the image. Download the .h file and add it to the folder of the Arduino sketch.
In this template, We created a function which accepts numbers as input and displays them as a pie chart. We just use draw arc and filled circle functions.
while (a < b) { Serial.println(a); j = 80 * (sin(PI * a / 2000)); i = 80 * (cos(PI * a / 2000)); j2 = 50 * (sin(PI * a / 2000)); i2 = 50 * (cos(PI * a / 2000)); tft.drawLine(i2 + 235, j2 + 169, i + 235, j + 169, tft.color565(0, 255, 255)); tft.fillRect(200, 153, 75, 33, 0x0000); tft.setTextSize(3); tft.setTextColor(0xffff); if ((a/20)>99)
while (b < a) { j = 80 * (sin(PI * a / 2000)); i = 80 * (cos(PI * a / 2000)); j2 = 50 * (sin(PI * a / 2000)); i2 = 50 * (cos(PI * a / 2000)); tft.drawLine(i2 + 235, j2 + 169, i + 235, j + 169, tft.color565(0, 0, 0)); tft.fillRect(200, 153, 75, 33, 0x0000); tft.setTextSize(3); tft.setTextColor(0xffff); if ((a/20)>99)
In this template, We display simple images one after each other very fast by bitmap function. So you can make your animation by this trick. Download the .h file and add it to folder of the Arduino sketch.
In this template, We just display some images by RGBbitmap and bitmap functions. Just make a code for touchscreen and use this template. Download the .h file and add it to folder of the Arduino sketch.
This is a small graphics library, specifically aimed at ATtiny microcontrollers, for the variety of small colour TFT displays available at low cost from suppliers like Adafruit, AliExpress, or Banggood:
It"s an updated version of my Tiny TFT Graphics Library. This latest version of the library supports both the classic ATtiny processors, such as the ATtiny85, and the new 0-series, 1-series, and 2-series ATtiny processors, such as the ATtiny402. Like the original library it allows you to plot points, draw lines, draw filled rectangles, and plot characters and text with an optional scale factor, in 16-bit colour.
This version adds the ability to plot outline rectanges, and outline and filled circles. I"ve included demo curve-plotting and histogram-plotting programs that adjust to fit any display.
This library supports TFT displays that use an SPI interface and require four pins to drive the display. This leaves one pin free on an 8-pin chip such as the ATtiny85 or ATtiny402. If you need more pins choose a larger chip, such as the ATtiny84 or ATtiny404.
Unlike my Compact TFT Graphics Library which uses standard Arduino SPI calls, this library uses direct I/O pin manipulations. This means that you can use any assignment of pins to the four I/O lines needed by the display, and makes it about twice as fast as one using SPI calls. I"ve also added support for some additional displays, so it now supports 16 different TFT displays.
So provided you set all the pins to their disabled state at startup, the display routines can simply toggle the appropriate pins to enable or disable them.
The differences between each family of processors are handled by constants to define the pin assignments, and preprocessor macros to define the bit manipulations. If you use the circuits given below you won"t need to change anything, apart from specifying which display you"re using.
The ClearDisplay() routine has been optimised further by realising that we don"t need to keep setting the mosi bit, since to clear the display it is always zero, so the routine only needs to toggle the sck bit the appropriate number of times. I"m grateful to Thomas Scherer for suggesting this.
The library occupies less than 4K bytes, including the character set and demo programs, and so will fit on microcontrollers with 4K flash such as the ATtiny45 and ATtiny402.
This library will work with displays based on the ST7735 which supports a maximum display size of 162x132, or the ST7789 and ILI9340/1 which support a maximum display size of 320x240. It includes parameters for the following colour TFT displays:
* These Adafruit displays conveniently all have the same edge-connector layout, so you can make a prototyping board or PCB that will take any of them, such as my Universal TFT Display Backpack.
Some of the AliExpress displays include a LDO 3.3V regulator, but not logic-level translation, so I recommend only interfacing them to a processor running from 3.3V.
The Adafruit displays all include an LDO 3.3V regulator and logic-level translation, so can be safely interfaced to processors powered from either 5V or 3.3V.
On the AliExpress red 160x128 display you need to connect the backlight pin to Vcc to turn it on. This doesn"t seem to be necessary with the other displays.
The library will probably support other TFT displays that use the same ST7735, ST7789, ILI9340/1 driver chips, but you may need to experiment with the parameters to get the image scaled and centered correctly.
The display needs to be connected to the microcontroller via four I/O lines: MOSI, SCK, CS, and DC. You can use any pins for these, but they should all be in the same port. You need to specify the port pin numbers of the pins you are using at the start of the Tiny TFT Graphics Library listing.
The 33kΩ pullup resistor from the display"s CS pin is optional; it is only needed on the AliExpress displays, and holds the chip select high to prevent the display from flickering while programming the ATtiny85.
The different displays are catered for by seven constants which specify the size of the display, the offsets relative to the area supported by the display driver, whether the display is inverted, the rotation value, and the order of the colours; for example:
By default the parameters give the correct orientation assuming you"re using the display with the header pins along the top, except in the case of the larger displays which have the header pins along the shorter edge, in which case the header pins are assumed to be on the left.
To check or adjust the values for each display you can run the TestChart() program, which draws a one-pixel border around the display area, and plots a red "F" to show the orientation:
The library will probably support other TFT displays that use the same driver chips, but you may need to experiment with the parameters to get the image scaled and centered correctly.
The library includes basic graphics routines for plotting points and drawing lines. These work on a conventional coordinate system with the origin at lower left. For example, on the 80x160 display:
DrawRect() draws an outline rectangle andFillRect() draws a filled rectangle in the foreground colour with width w and height h, and the bottom left corner at the current drawing position:
DrawCircle() draws an outline circle andFillCircle() draws a filled circle in the foreground colour with radius radius, and the centre at the current drawing position:
You can plot larger characters by setting the global variable scale, default value 1. After plotting a character PlotChar() moves the drawing position to the start of the next character to make it easy to plot several characters in a row without needing to call MoveTo().
It works with TFT displays available from AliExpress, and I"ve included four examples showing how you can do things that wouldn"t be possible without the ability to read from the display.
You can use an exclusive-OR drawing mode that changes the state of pixels reversibly. Drawing the same thing a second time restores the display to its previous state. This is especially important for dynamic data plotting.
To implement these applications without the ability to read pixels from the display would require you to keep a mirror of the display in RAM, and update the mirror every time you draw to the actual display. This would slow down graphics and require a lot of memory: for example, to mirror a 320x240 colour display would require 153.6Kbytes of RAM. To put this in context, the ATtiny414 used to run these examples only has 256 bytes of RAM.
Unfortunately this feature does not work with Adafruit displays, which is why I didn"t include it in my original Tiny TFT Graphics Library 2. It is, however, compatible with all displays based on the ST7735 and ST7789 driver chips available from vendors such as AliExpress and Banggood. Here"s a list of displays I"ve tested:
Adafruit have a range of great TFT displays, in a wide selection of sizes and resolutions, but unfortunately they are not compatible with this library. The reason is that their displays all include a unidirectional on-board logic-level converter to allow them to be used with either 3.3V or 5V, but this has the downside of preventing them from being able to read back from the display memory.
The solution would be to replace the unidirectional logic-level converter on the MOSI connection to the display driver with a bidirectional one, which would require one N-MOSFET and two resistors. I originally planned to include details of how to modify an Adafruit display to implement this, but I"ve decided against this because the displays are fragile, and the risk of ending up with a non-functional display is too great.
This first uses the display commands CASET and RASET to set the column range and row range to the current point. It then gives the RAM read command, RAMRD.
The sequence to shift the 21 bits into the variable pixel needs to be slightly different depending on whether the display uses the ST7735 or ST7789 driver chip. The two if statements determine this from the width of the display, and toggle the sck pin either before or after reading the mosi pin, as appropriate. It took a bit of experimentation to figure this out.
These examples included with the library demonstrate applications of reading back from the display memory. For convenience I"ve used my Universal TFT Display Backpack to run these examples, but that"s not necessary.
This simple demo takes a triangular section of an existing image on the screen, and reflects it through horizontal, vertical, and diagonal lines to create a symmetrical image, like a kaleidoscope. It works best on square displays; here it is on a 240x240 1.54" display:
To run it first draw an image, and then run Kaleidoscope(). For this example the initial image is the Waterfall() demo, used for the title image in the article Tiny TFT Graphics Library 2:
The stopwatch takes advantage of exclusive-OR plotting to draw and undraw the hand when it moves without corrupting the clock face. It is designed for a 128x128 display:
Anything drawn in red on the display is treated as a barrier, and the ball will bounce off it. Any other colours, such as the white text, are ignored and can be used to create an interesting background.
The final demo draws the BarChart() demo, and it then calls BMPSave() to save it to a BMP-format image file on an SD card. Here"s the BarChart() demo running on a 320x170 display:
Here is the version of the Tiny TFT Graphics Library with the extensions for reading from the display, and the demos described above (excluding BMPSave()): Tiny TFT Graphics Library with Read.
Hi guys, welcome to today’s tutorial. Today, we will look on how to use the 1.8″ ST7735 colored TFT display with Arduino. The past few tutorials have been focused on how to use the Nokia 5110 LCD display extensively but there will be a time when we will need to use a colored display or something bigger with additional features, that’s where the 1.8″ ST7735 TFT display comes in.
The ST7735 TFT display is a 1.8″ display with a resolution of 128×160 pixels and can display a wide range of colors ( full 18-bit color, 262,144 shades!). The display uses the SPI protocol for communication and has its own pixel-addressable frame buffer which means it can be used with all kinds of microcontroller and you only need 4 i/o pins. To complement the display, it also comes with an SD card slot on which colored bitmaps can be loaded and easily displayed on the screen.
The schematics for this project is fairly easy as the only thing we will be connecting to the Arduino is the display. Connect the display to the Arduino as shown in the schematics below.
Due to variation in display pin out from different manufacturers and for clarity, the pin connection between the Arduino and the TFT display is mapped out below:
We will use two libraries from Adafruit to help us easily communicate with the LCD. The libraries include the Adafruit GFX library which can be downloaded here and the Adafruit ST7735 Library which can be downloaded here.
We will use two example sketches to demonstrate the use of the ST7735 TFT display. The first example is the lightweight TFT Display text example sketch from the Adafruit TFT examples. It can be accessed by going to examples -> TFT -> Arduino -> TFTDisplaytext. This example displays the analog value of pin A0 on the display. It is one of the easiest examples that can be used to demonstrate the ability of this display.
The second example is the graphics test example from the more capable and heavier Adafruit ST7735 Arduino library. I will explain this particular example as it features the use of the display for diverse purposes including the display of text and “animated” graphics. With the Adafruit ST7735 library installed, this example can be accessed by going to examples -> Adafruit ST7735 library -> graphics test.
Next, we create an object of the library with the pins to which the LCD is connected on the Arduino as parameters. There are two options for this, feel free to choose the most preferred.
Next, we move to the void setup function where we initialize the screen and call different test functions to display certain texts or images. These functions can be edited to display what you want based on your project needs.
All the functions called under the void setup function, perform different functions, some draw lines, some, boxes and text with different font, color and size and they can all be edited to do what your project needs.
Uploading the code to the Arduino board brings a flash of different shapes and text with different colors on the display. I captured one and its shown in the image below.
That’s it for this tutorial guys, what interesting thing are you going to build with this display? Let’s get the conversation started. Feel free to reach me via the comment section if you have any questions as regards this project.
The wide range of conditions over which LCD monitors are used means that it is desirable to produce displays whose luminance (brightness) can be altered to match both bright and dim environments. This allows a user to set the screen to a comfortable level of brightness depending on their working conditions and ambient lighting. Manufacturers will normally quote a maximum brightness figure in their display specification, but it is also important to consider the lower range of adjustments possible from the screen as you would probably never want to use it at its highest setting. Indeed with specs often ranging up to 500 cd/m2, you will certainly need to use the screen at something a little less harsh on the eyes. As a reminder, we test the full range of backlight adjustments and the corresponding brightness values during each of our reviews. During our calibration process as well we try to adjust the screen to a setting of 120 cd/m2 which is considered the recommended luminance for an LCD monitor in normal lighting conditions. This process helps to give you an idea of what adjustments you need to make to the screen in order to return a luminance which you might actually want to use day to day.
Changing the display luminance is achieved by reducing the total light output for both CCFL- and LED-based backlights. By far the most prevalent technique for dimming the backlight is called Pulse Width Modulation (PWM), which has been in use for many years in desktop and laptop displays. However, this technique is not without some issues and the introduction of displays with high brightness levels and the popularisation of LED backlights has made the side-effects of PWM more visible than before, and in some cases may be a source of visible flicker, eyestrain, eye fatigue, headaches and other associated issues for people sensitive to it. This article is not intended to alarm, but is intended to show how PWM works and why it is used, as well as how to test a display to see its effects more clearly. We will also take a look at the methods some manufacturers are now adopting to address these concerns and provide flicker-free backlights instead. As awareness grows, more and more manufacturers are focusing on eye health with their monitor ranges.
Pulse Width Modulation (PWM) is one method of reducing the perceived luminance in displays, which it achieves by cycling the backlight on and off very rapidly, at a frequency you can’t necessary detect with the naked eye, but which could lead to eye issues, headaches etc. This method generally means that at 100% brightness a constant voltage is applied to the backlight and it is continuously lit. As you lower the brightness control the perceived luminance for the user reduces due to a number of possible controlling factors:
1) Frequency –The backlight is cycled on and off very rapidly, and this cycling typically occurs at a fixed frequency (in Hz). How fast this cycling occurs can impact whether flicker is visible or perceivable to the user, with higher frequencies being potentially less problematic. PWM has been known to operate at low frequencies of 180 – 240Hz for example which are likely to be more problematic than higher frequencies ranging up in to the Kilohertz range (e.g. 18,000Hz).
2) Modulation –The modulation of the cycling has an impact on the perceived brightness, and this describes the difference between the luminance in an “on” and in an “off” state. In some examples the backlight is completely turned off during the cycle so it is literally being turned on/off rapidly across the full brightness adjustment range. In those examples the luminance output is controlled really by the duty cycle only (see point 3). In other examples the backlight is not always being completely turned off but rather the voltage applied to the backlight is being rapidly alternated, resulting in less extreme differences between the on and off states. Often this modulation will be narrow in the high brightness range of the display, but as you reduce further, the modulation becomes wider until it reaches a point where the backlight is being switched completely off. From there, the change in the duty cycle (point 3) controls the further changes in the luminance output.
While PWM is attractive to hardware makers for the reasons outlined above, it can also introduce distracting visual effects if not used carefully. Flicker from LED backlights is typically much more visible than for older CCFL backlights at the same duty cycle because the LED’s are able to switch on and off much faster, and do not continue to “glow” after the power is cut off. This means that where the CCFL backlight showed rather smooth luminance variation, the LED version shows sharper transitions between on and off states. This is why more recently the subject of PWM has cropped up online and in reviews, since more and more displays are moving to W-LED backlighting units now.
Where the effect of flicker can really come into play is any time the user’s eyes are moving. Under constant illumination with no flickering (e.g. sunlight) the image is smoothly blurred and is how we normally perceive motion. However, when combined with a light source using PWM several discrete afterimages of the screen may be perceived simultaneously and reduce readability and the ability of the eyes to lock onto objects. From the earlier analysis of the CCFL backlighting we know that false colour may be introduced as well, even when the original image is monochromatic. Below are shown examples of how text might appear while the eyes are moving horizontally under different backlights.
It is important to remember that this is entirely due to the backlight, and the display itself is showing a static image. Often it is said that humans cannot see more than 24 frames per second (fps), which is not true and actually corresponds to the approximate frame rate needed to perceive continuous motion. In fact, while the eyes are moving (such as when reading) it is possible to see the effects of flicker at several hundred hertz. The ability to observe flicker varies greatly between individuals, and even depends on where a user is looking since peripheral vision is most sensitive.
So how fast is PWM cycling backlights on and off? This seems to depend on the backlight type used, with CCFL-based backlights nearly all cycling at 175Hz or 175 times per second. LED backlights have been reported typically running from 180 – 420Hz, with those at the lower end flickering much more visibly. Some have even faster frequencies of >2000Hz so it really can vary. While this might seem too fast to be visible, keep in mind that 175Hz is not much faster than the 100-120Hz flicker observed in lights connected directly to the mains power.
100-120Hz flickering of fluorescent lights has in fact been linked to symptoms such as severe eye strain and headaches in a portion of the population, which is why high-frequency ballast circuits were developed that provide almost continuous output. Using PWM at low frequencies negates the advantages of using these better ballasts in backlights because it turns an almost constant light source back into one that flickers. An additional consideration is that poor quality or defective ballasts in fluorescent backlights can produce audible noise. In many cases this is exacerbated when PWM is introduced since the electronics are now dealing with an additional frequency at which power usage is changing.
It is also important to distinguish the difference between flicker in CRT displays and CCFL and LED backlit TFT displays. While a CRT may flicker as low as 60Hz, only a small strip is illuminated at any time as the electron gun scans from top to bottom. With CCFL and LED backlit TFT displays the entire screen surface illuminates at once, meaning much more light is emitted over a short time. This can be more distracting than in CRTs in some cases, especially if short duty cycles are used.
The flicker itself in display backlights may be subtle and not easily perceptible for some people, but the natural variation in human vision seems to make it clearly visible to others. With the use of high-brightness LED’s on the rise it is becoming increasingly necessary to use short PWM duty cycles to control brightness, making flicker more of a problem. With users spending many hours every day looking at their monitors, shouldn’t we consider the long term effects of both perceptible and imperceptible flicker?
A much better method of course would be to purchase a display not relying on PWM for dimming, or at least one which uses a much higher cycling frequency. Few manufacturers seem to have implemented PWM at frequencies that would limit visible artefacts (well above 500Hz for CCFL and above 2000 Hz for LED). Additionally, some displays using PWM do not use a 100% duty cycle even at full brightness, meaning they will always produce flicker. Several LED-based displays may in fact be currently available which do not use PWM, but until backlight frequency and modulation become listed in specifications it will be necessary to see the display in person. Some manufacturers promote “flicker free” monitors in their range (BenQ, Acer for example) which are designed to not use PWM at all and instead use a Direct Current (DC) method of backlight dimming. Other manufacturers such as Eizo talk about flicker free backlights but also list a hybrid solution for their backlight dimming, where PWM is used for some of the brightness adjustment range at the lower end. In fact it seems an increasingly common practice for a screen to be PWM free down to a certain point, and then fro PWM to be used to really drive down the minimum luminance from there.
(Optional) Set the camera white balance by getting a reading off the screen while displaying only white. If not possible, then manually set the white balance to about 6000K.
Display a single vertical thin white line on a black background on the monitor (1-3 pixels wide should be fine). The image should be the only thing visible. Here is an example you may wish to save and use, show it full screen on your monitor.
Hold the camera about 2 feet in front of the monitor and perpendicular to (looking straight at) the front. Press the shutter button as you slowly move it horizontally across the screen (remaining perpendicular). You may need to experiment with moving the camera at different speeds.
What we are doing with this technique is turning a temporal effect into a spatial one by moving the camera during capture. The only significant source of light during the image capture is the thin line on the display, which is exposed onto consecutive columns on the sensor. If the backlight is flickering, different columns will have different brightness or colour values determined by the backlight at the time it was exposed.
A common problem when first attempting this technique is that the image is too dark. This can be mitigated by using a larger camera aperture (lower f/number) or increasing the ISO value. The shutter speed is not a factor in the exposure since we are using it only to control the total exposure time. The brightness of the image can also be adjusted by changing the speed at which the camera is moved, with a fast speed giving a darker image and more temporal resolution and a slow speed a brighter image with lower resolution. Another problem encountered is unevenly-spaced cycles in the final image, which is caused by the camera changing speed during exposure. Continuing to move the camera before and after the exposure helps to steady this. An image which looks particularly smooth may be due to it being out of focus. This can sometimes be helped by pressing the shutter button halfway to focus on the line target, then proceeding as normal.
The oscillographs for a typical CCFL display using PWM at 0% looks like the above. You can see the transitions from on to off are less sudden as the phosphors don’t go dark as quickly as with LED backlight units. As a result, the use of PWM may be less problematic to users.
As we said at the beginning, this article is not designed to scare people away from modern LCD displays, rather to help inform people of this potential issue. With the growing popularity in W-LED backlit monitors it does seem to be causing more user complaints than older displays, and this is related to the PWM technique used and ultimately the type of backlight selected. Of course the problems which can potentially be caused by the use of PWM are not seen by everyone, and in fact I expect there are far more people who would never notice any of the symptoms than there are people who do. For those who do suffer from side effects including headaches and eye strain there is an explanation at least.
With the long term and proven success of a technology like Pulse Width Modulation, and the many years of use in CCFL displays we can’t see it being widely changed at any time soon to be honest, even with the popular move to W-LED backlit units. It is still a reliable method for controlling the backlight intensity and therefore offering a range of brightness adjustments which every user would want and need. Those who are concerned about its side effects or who have had problems with previous displays should try and consider the frequency of the PWM in their new display, or perhaps even try and find a screen where it is not used at all in backlight dimming. Some manufacturers are proactively addressing this concern through the use of flicker free backlights, and so options are emerging which do not use PWM.
//#define ILI9488_DRIVER // WARNING: Do not connect ILI9488 display SDO to MISO if other devices share the SPI bus (TFT SDO does NOT tristate when CS is high)