Silicon ChipLow-cost 3.5-inch LCDs for Arduino or Micromite - May 2019 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: “Crippleware” possibly to blame for two airliner crashes
  4. Feature: Avalon Airshow: from killer drones to spacecraft! by Dr David Maddison
  5. Project: DSP Active Crossover and 8-channel Parametric Equaliser by Phil Prosser and Nicholas Vinen
  6. Feature: El Cheapo Modules: Class D amplifier modules by Allan Linton-Smith
  7. Project: Solar-powered data repeater for 433MHz remotes by John Clarke
  8. Serviceman's Log: Samsunk – or the dishwasher that wouldn’t by Dave Thompson
  9. Project: Bridge adaptor gives four times your amplifier power! by Nicholas Vinen
  10. Review: Microchip’s new “SNAP” debugger/programmer by Tim Blythman
  11. Project: Low-cost 3.5-inch LCDs for Arduino or Micromite by Tim Blythman
  12. Vintage Radio: Admiral 1956 5ACW Clock Radio by Associate Professor Graham Parslow
  13. Product Showcase
  14. PartShop
  15. Market Centre
  16. Advertising Index
  17. Notes & Errata: Multi Diode Curve Plotter, March 2019; DAB+/FM/AM Radio, January-March 2019; 3-Way Adjustable Active Stereo Crossover, September-October 2017
  18. Outer Back Cover: Hare & Forbes Machineryhouse

This is only a preview of the May 2019 issue of Silicon Chip.

You can view 46 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Articles in this series:
  • The Avalon 2013 Air Show (May 2013)
  • The Avalon 2013 Air Show (May 2013)
  • The Australian International Airshow 2015 (May 2015)
  • The Australian International Airshow 2015 (May 2015)
  • Avalon Airshow: from killer drones to spacecraft! (May 2019)
  • Avalon Airshow: from killer drones to spacecraft! (May 2019)
  • Avalon Airshow 2023 (May 2023)
  • Avalon Airshow 2023 (May 2023)
Items relevant to "DSP Active Crossover and 8-channel Parametric Equaliser":
  • DSP Crossover CPU PCB [01106193] (AUD $5.00)
  • DSP Crossover LCD Adaptor PCB [01106196] (AUD $2.50)
  • DSP Crossover front panel control PCB [01106195] (AUD $5.00)
  • DSP Crossover DAC PCB [01106192] (AUD $7.50)
  • DSP Crossover power supply PCB [01106194] (AUD $7.50)
  • DSP Crossover ADC PCB [01106191] (AUD $7.50)
  • DSP Active Crossover complete PCB set (7 boards) [01106191-6] (AUD $40.00)
  • PIC32MZ2048EFH064-250I/PT programmed for the DSP Active Crossover/Equaliser (V8) (Programmed Microcontroller, AUD $30.00)
  • Pulse-type rotary encoder with pushbutton and 18t spline shaft (Component, AUD $3.00)
  • 128x64 Blue LCD screen with KS0108-compatible controller (Component, AUD $30.00)
  • Firmware and source code for the DSP Active Crossover/Equaliser project [0610619A.HEX] (Software, Free)
  • DSP Active Crossover/DDS/Reflow Oven PCB patterns (PDF download) [01106191-6] (Free)
Articles in this series:
  • DSP Active Crossover and 8-channel Parametric Equaliser (May 2019)
  • DSP Active Crossover and 8-channel Parametric Equaliser (May 2019)
  • DSP Active Crossover and 8-channel Parametric Equaliser, part two (June 2019)
  • DSP Active Crossover and 8-channel Parametric Equaliser, part two (June 2019)
  • DSP Active Crossover and 8-channel Parametric Equaliser (July 2019)
  • DSP Active Crossover and 8-channel Parametric Equaliser (July 2019)
Articles in this series:
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • A Gesture Recognition Module (March 2022)
  • A Gesture Recognition Module (March 2022)
  • Air Quality Sensors (May 2022)
  • Air Quality Sensors (May 2022)
  • MOS Air Quality Sensors (June 2022)
  • MOS Air Quality Sensors (June 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Heart Rate Sensor Module (February 2023)
  • Heart Rate Sensor Module (February 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • VL6180X Rangefinding Module (July 2023)
  • VL6180X Rangefinding Module (July 2023)
  • pH Meter Module (September 2023)
  • pH Meter Module (September 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 1-24V USB Power Supply (October 2024)
  • 1-24V USB Power Supply (October 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
Items relevant to "Solar-powered data repeater for 433MHz remotes":
  • 433MHz Wireless Data Range Extender PCB [15004191] (AUD $10.00)
  • PIC16F88-I/P programmed for the 433MHz Wireless Data Range Extender [1500419A.HEX] (Programmed Microcontroller, AUD $15.00)
  • 23LCV1024-I/P SRAM and MCP73831T charger IC for the 433MHz UHF Repeater (Component, AUD $12.50)
  • Firmware and source code for the 433MHz Wireless Data Range Extender [1500419A.HEX] (Software, Free)
  • 433MHz Wireless Data Range Extender PCB pattern (PDF download) [15004191] (Free)
  • 433MHz Wireless Data Range Extender lid panel artwork (PDF download) (Free)
Items relevant to "Bridge adaptor gives four times your amplifier power!":
  • Amplifier Bridge Adaptor PCB [01105191] (AUD $5.00)
  • Amplifier Bridge Adaptor PCB pattern (PDF download) [01105191] (Free)
  • Panel artwork for the Bridge-mode Audio Amplifier Adaptor (Free)
Items relevant to "Low-cost 3.5-inch LCDs for Arduino or Micromite":
  • Low-cost 3.5-inch LCD Adaptor PCB for Arduino R3 [24111181] (AUD $5.00)
  • 3.5-inch TFT Touchscreen LCD module with SD card socket (Component, AUD $35.00)
  • Sample software and source code for low-cost 3.5-inch LCDs for Arduino and Micromite (Free)
  • Low-cost 3.5-inch LCDs Adaptor for Arduino R3 boards PCB pattern (PDF download) [24111181] (Free)

Purchase a printed copy of this issue for $10.00.

A low-cost 3.5-inch touchscreen for the Arduino & Micromite by Tim Blythman We’ve published many projects using 320x240 pixel, 2.8-inch colour touchscreens. We love them because of their low cost and ease of use. But sometimes they’re a bit too small! Now we’ve discovered larger, higher-resolution displays that only cost a bit more and are almost as easy to drive. Where do you get them . . . and how do you use them with an     Arduino or Micromite? W hile we were working on the Diode Curve Plotter project, published in the March issue (siliconchip.com.au/Article/11447), we thought that it would be nice to have a larger display area for the graphs. The 5in (13cm) display that we’ve used with Explore-100 based projects such as the DAB+/FM/AM radio (Jan86 Silicon Chip uary-March 2019; siliconchip.com.au/ Series/330) is fantastic – but it’s quite expensive and a bit larger than is really required for many projects. There is a similar 4.3in (11cm) screen, but it’s hardly any cheaper than the 5in display. And both the 4.3in and 5in screens have another problem: they use a parallel interface, which takes up a lot Australia’s electronics magazine of I/O pins, and the regular Micromite doesn’t have support for parallel displays. You need to use the Micromite Plus, which means soldering an SMD microcontroller. What we really wanted was a larger, higher-resolution screen that uses the same serial control interface as the 2.8in (7cm) ILI9341-based screens that siliconchip.com.au have been so popular. That would give us more screen real estate and more pixels, without using up any more I/O pins. And that’s just what we found. We have been aware of the existence of 3.2in (8cm) and 3.5in (9cm) touchscreen modules for some time, but in the past, all the ones we’d seen had a parallel interface. That’s good for providing a fast update rate, but it requires a micro with a parallel interface and plenty of pins to use efficiently. So we went searching for similar serial-controlled screens, and we found two vendors in AliExpress offering just that (see www.aliexpress.com/ item//32954128438.html and www. aliexpress.com/item//32954240862. html). We bought one from each to test. There are several different variants of this type of display around, with different connectors and interfaces, but all use 0.1in (2.54mm) pitch header pins to connect to the controller board. Many sellers indicated that they use the ILI9488 controller IC, although, as we found out later, this is not always the case. They all come with either a fullsize SD or microSD socket onboard, and many have a resistive touch panel too. We particularly wanted to get the touchscreen variants since that obviates the need to fit any buttons or other controls in most cases. Once we got the screens, it took quite a bit of effort to get them work- Contestant number one: we recommend that you use this 3.5in display panel as it works with either a Micromite or Arduino (once you build our breakout board). We cut off the pin which is now missing, as it was causing a conflict between the touch and display controllers, but that is no longer necessary with the revised breakout board we present in this article. ing (for reasons we’ll explain later), but we got there in the end. Later on, we’ll give you download links to our software and source code, so that you can do it too. We also decided to try out some other similar screens, one from Altronics (because it was easy to get) and another which is designed to plug straight into an Arduino, since that one is really easy to get up and running if Arduino is your platform of choice. This article assumes that you are familiar with either the Arduino Integrated Development Environment (IDE) or Micromite BASIC and the various possible methods of uploading MMBasic code to a Micromite. If you are not, we suggest that you try working on simpler projects with these platforms before diving into this one. We have designed a small breakout board to connect the ‘universal’ 3.5in serial touchscreen (ie, the one that does not come as a ‘shield’) to an Arduino. We’ll describe this board below. This breakout board also works with the 2.8in touchscreen that we’ve used so often in the past in the Micromite LCD BackPack. Contestant number one: 3.5inch serial touchscreen Fig.1: this excerpt from the XPT2046 datasheet shows a typical circuit for the chip and demonstrates how the touch panel can be viewed as a variable resistor network. siliconchip.com.au Australia’s electronics magazine The 3.5in serial touchscreens we sourced look very similar to the 2.8in touchscreen used in the very popular Micromite LCD BackPack project (February 2016; siliconchip.com.au/ Article/9812). The screen is not only bigger but it also has a substantially higher resolution, at 480x320 pixels (0.15MP) compared to 320x240 pixels (0.07MP). So May 2019  87 it has exactly twice as many pixels. As you would expect, given the extra 0.7 inches (20mm) of diagonal screen size, it is slightly larger, and the PCB is slightly longer, so the two pin headers on the board are around 13mm further along than in the smaller LCD. The mechanical mounting holes are also arranged differently. Otherwise, the main 14-pin interface header appears identical, and the pins are marked with the same designations. Like the 2.8in display, you can get these with or without the touch panel. The difference in price is small, so we think it’s worthwhile to get the one that has it. The main appeal of this unit is that it can plug into the existing Micromite BackPack and even if you’re using it with an Arduino Uno, it won’t take up all that many digital I/O pins, so you will still have plenty left for other tasks. It’s controlled using two SPI interfaces, one for the display and one for the touch panel, although you can drive both from a single set of SPI pins on the micro. Like the 2.8in LCD used with the Micromite BackPack, the fullsize SD card socket is accessible from one of the long edges of the PCB. To simplify our experiments on these displays with Arduino boards, we designed the aforementioned breakout PCB that suits both the 2.8in 320x240 display and the 3.5in 480x320 display. The instructions for assembling this breakout board can be found below. If you have one of these displays and an Arduino board, you might want to build this board before reading the following usage instructions. Getting it working with an Arduino Because of the prevalence of Arduino libraries, we started our testing using our breakout board with an Arduino Uno. After a few attempts, we found a library that was able to drive the display. This library can be found at https:// github.com/jaretburkett/ILI9488 (see Fig.4) We had to change the pin assignments in the example sketch, named “graphicstest” to the following: #define TFT_CS #define TFT_DC #define TFT_LED #define TFT_RST 88 Silicon Chip 10 9 -1 8 There is no pin ‘-1’, but this value can’t be empty, so a value of -1 is used because this is ignored by digitalWrite commands since it is an invalid pin number, and therefore has no effect. On our board, the LED pin is hardwired to the 5V rail, forcing the LCD backlight on, to save as many pins as possible for other uses. Interestingly, this library was modified from another library designed for the ILI9341 controller, which is what is in the 2.8” inch displays. It simply provides a low-level interface to the “Adafruit_GFX” library. This library provides common, highlevel functions like drawing shapes and text to displays. Adafruit has developed a good number of display boards and modules (many of which are now appearing as clones), and they have excellent support for their displays. Their libraries are a great resource for getting many displays running. While it’s nice to have some library code that works, we wanted to know how to control these displays at a much lower level and get an understanding of their operation. To see what sets the larger ILI9488based displays apart from the smaller ILI9341s, we added some code to the libraries to print out (to the serial monitor) what commands and text were being sent to the board, formatting this output as commands which could be pasted directly into the Arduino IDE. This is shown in Screen1. This showed us the required initialisation sequence for the display controller. We then checked the ILI9488 datasheet (http://siliconchip.com.au/ link/aanr) and confirmed that the commands that were being issued were appropriate. There are a few commands that require a delay after they are sent, to allow the controller to process the data, so we needed to know when these should occur. We could then build a working sketch from scratch to drive the display. Since the ILI9488’s drawing (as opposed to initialisation) commands are practically identical to those for the ILI9341, once it’s initialised, the process of drawing on the screen is quite straightforward. Although the datasheet hints that a 16-bit colour mode (as used with the ILI9341) is available, it doesn’t appear Australia’s electronics magazine to work in SPI mode on the ILI9488, so we had to modify the code to produce 24-bit colour values. We’ve distilled all this code down to just the essentials and put it in a demo sketch titled “SPI_320x480_display_ demo”. This demonstrates drawing on the screen in all four orientations, including region fills, text and lines made of individual pixels. Micromite support We were then able to translate this Arduino sketch into working Micromite BASIC (MMBasic) code. We had to do a search and replace to change Arduino’s “0x” hexadecimal prefix with “&H” to suit BASIC, as well as changing the function definitions to subroutines, amongst other changes. The demo BASIC file is called “SPI_320x480_display_demo.bas”. For the Micromite, the font data is embedded as a CFUNCTION. While this directive is usually used to store machine code, it can be used to store any binary data for MMBasic, and is a more compact way of doing this than DATA statements. Some of the display routines have been modified to work with larger arrays of data, as the SPI interface works more quickly with arrays than individual values. Before this improvement, clearing the screen took nearly a minute. This display code would be an ideal candidate for a CFUNCTION, as that would allow it to work a lot quicker, but the intention here is to demonstrate what is possible, and also to show how the interface works. We expect readers will have an easier time understanding the BASIC code than the equivalent C code, even if the C code would be substantially faster. If you are using the Micromite Plus BackPack, use the source files with the “MMplus” suffix at the end. The SPI2 peripheral is used for display communications on the Micromite Plus, so you may need to run an “OPTION … DISABLE” command if there are any other peripherals using SPI2 before the display code will work. Similarly, on the regular Micromite, any OPTIONs that lock the SPI bus may need to be disabled before using our sample programs. Note that we have not designed a breakout board to interface this screen to a Micromite. That’s because it can be plugged siliconchip.com.au straight into the 14-pin header socket on a Micromite LCD BackPack (V1 or V2). The mounting holes don’t line up, but we’re sure that our readers will figure out clever ways to mount these boards successfully. Touch interface One of the great features of these displays is the touch interface. A quick inspection shows that like the 2.8in touchscreen we’re familiar with, the 3.5 inch screen uses the same XPT2046 touch controller IC and the connections appear to be practically identical. We even found some schematics which indicated that this was the case. The XPT2046 touch controller is effectively a multi-channel 12-bit analog-to-digital converter (ADC), which is intended to be connected to a four-wire touch panel. It can drive its analog pins as needed to supply a voltage difference across the touch surface. Fig.1 shows a typical connection for the XPT2046 IC. An 8-bit command is sent to the XPT2046 over the SPI bus, which sets up the drivers and ADC multiplexer and starts an ADC conversion. This conversion is clocked (timed) by the following pulses on the SPI SCK clock line. Twelve bits of data are read out from the chip, along with four zero bits (for a total of 16 bits or two bytes), after which the touch controller is ready for another conversion. So this is all pretty straightforward, and we had code which worked with the 2.8in touch panels, but it would not work with the 3.5in panels. We tried many different approaches to solve this, including probing the lines going to the touch panel itself, and ultimately we discovered that the problem was due to the LCD controller and touch controller sharing one MISO (master in slave out) line. The display controller should not be driving this pin when its CS (chip select) line is high, as this is how multiple devices share an SPI bus. The touch controller correctly leaves its MISO pin floating when its CS line is high. But the LCD controller appeared to be driving MISO all the time, and this was preventing the touch controller from pulling it high, resulting in the micro receiving all zeros. The fix was easy; we disconnected the LCD controller’s MISO line entirely, as it is not needed since we never read data back from the LCD controller. Then, everything worked like a charm. The final Arduino shield design has a jumper to disconnect this pin from the SPI bus, so you should be able to get the touch controller working simply by leaving it open. Once we got the touch interface working, we wrote a few more sample programs (both Arduino sketches and Micromite BASIC). One of these is a basic demo and the other provides test and calibration features. They are named “SPI_3.5_inch_ TFT_shield_demo_wth_touch.bas” and “SPI_3.5_inch_TFT_touch_calibration.bas”, with the Micromite Plus equivalents having the same names but with “MMplus” at the end. SD card support Like the smaller 2.8in display modules, the 3.5in displays also have an SD card socket connected to a separate set of pins via 1k resistors. As there is no direct connection to these pins on the Micromite or Micromite Plus BackPack, the only way to access the SD card with these boards is by adding jumper lead connections. Our Arduino breakout board has headers to make connections to the SD pins for both the 2.8in and 3.5in displays. And since the display module has nothing to prevent 5V being fed into the SD card pins, we have designed the breakout board to do all the level conversion, as this is also needed for the display and touch controllers. The Arduino IDE provides a basic “SD” interface library, and we tried the “listfiles” example from (Files -> Examples -> SD). Our design uses digital pin 6 as the SD card chip select line, so we simply changed one line in the “listfiles” sketch to use the correct CS-bar pin like this: if (!SD.begin(6)) { We were then able to retrieve a list of the files from an SD card plugged into the socket on the display. Our breakout board can also be used to read data from SD cards. Verdict Now that we’ve figured out how to drive it and use the touch panel, this display is an excellent choice, especially for use with Arduino boards. And since it can also be used with both the Arduino and Micromite boards, we hope to use it more in the future. The SPI interface means that the pin usage is minimal. We’ll need to come up with some CFUNCTIONs if we hope to use this These are the test patterns you will see when you run our sample programs. The shadowing (particularly on the right photo) is an artefact from photography – this is almost invisible with the naked eye. siliconchip.com.au Australia’s electronics magazine May 2019  89 Contestant number two: this display board lacks a touch panel but sits neatly over the top of an Arduino Mega. The tactile switch resets the connected microcontroller when pressed. display to any extent with the Micromite, as the BASIC interface is quite slow. But the BASIC code is certainly a good starting point, and may be sufficient for some applications. Before we get to the assembly of the breakout board for this display, let’s take a look at a couple of other candidates that we evaluated. Contestant number two: Altronics Z-0575 The next board is a 3.2 inch LCD screen with no touch panel. It’s designed to plug into an Arduino Mega, and it is available from Altronics, Cat Z6527 (www.altronics.com.au/p/ z6527) as well as other sources. Altronics say that it has an ILI9481 controller IC, and they appear to be correct, as it works with Arduino libraries designed for that controller chip. This display has a 16-bit parallel interface and is designed to work with contiguous port pins on the Arduino Mega, meaning that, in theory, it will is capable of very fast communication using direct port writes. But that also makes it virtually impossible to use with a regular Arduino or a Micromite. Its header layout is interesting. There is a long 2x18 pin header at one end, which suits the large header block at one end of the Mega. There is also a small 2-pin header which connects to the 3.3V and RESET pins at the other end of the Mega. This requires the display to rest on the USB socket for support while blocking practically all of the other pins. 90 Silicon Chip Interestingly, the full-size SD card socket is deep inside the board outline and is not accessible while the board is attached to a Mega. On the same side as the SD card socket are three small SSOP ICs (which are responsible for converting between the Arduino’s 5V logic levels and the display’s 3.3V) as well as a capacitor, resistor, voltage regulator and an unpopulated SOIC-8 footprint. The specification sheet notes that the display will work from 3.3V to 5.5V, so it might also be suitable for 3.3V boards such as the Arduino Due, although we have not tried this. On the front of the display is a tactile pushbutton, which is connected between the GND and RESET pins on the Mega board, so that pressing it resets the microcontroller on the Mega board. Getting it working Altronics provide a good amount of sample code, which can be downloaded from the downloads tab of the product page linked above. This download includes manuals, libraries and images of sample display output. We used an Arduino Mega to test it, mainly because most of the other micro boards we had on hand didn’t have enough I/O pins to drive it – you need 20 I/O pins just to run the display, and even if you have that many free, it would be fiddly to wire it up using jumper leads (see Fig.2). The board is effectively a shield for the Mega and directly plugs in on top. While easy to insert, the large header is hard to remove, and we found we Australia’s electronics magazine Fig.2: a pin map for the Altronics display shield, designed to plug into an Arduino Mega. We have added the Mega pin numbers for clarity, although these are not needed for the direct port writes used in the library code. had to take care detaching the shield by wiggling the display to gently ease the pins out so that they don’t catch and bend. We extracted the “Arduino Demo_ Mega2560” folder from the zip file and copied the contents of the “Arduino Demo_Mega2560\Install libraries” folder to the Arduino libraries folder. In Windows 10, our libraries folder is at “Documents\Arduino\libraries”. We then had a libraries folder as shown in Fig.3. It appears these libraries are adapted from those that can be downloaded from www.rinkydinkelectronics.com/ library.php This is a handy website which also offers fonts that can be used with graphical LCDs. We restarted the Arduino IDE for it to recognise the newly copied libraries. The example sketches can be found in the “Arduino Demo_Mega2560” folder. The “Example01-UTFT_ Demo_480x320” sketch cycles through a few demonstration patterns. The other sample sketches demonstrate fonts, buttons and bitmaps, although, as we noted earlier, this display does not feature a touch panel, so it was not possible to test the button sketches properly. SD card slot As we mentioned, there is an SD card slot tucked under the board. siliconchip.com.au Contestant number three: while this display module does have a touch panel, the lack of available spare pins when paired with an Uno means that it may not be very useful, as the Arduino can then not easily be connected to any other device. This can be a handy as it allows large images, graphics or icons to be stored on an SD card instead of taking up valuable flash memory in the microcontroller. Once again, we tested it with the “listfiles” example from Files -> Examples -> SD. Although the pin map on the diagram does not have the pins numbered, we were able to ascertain that the SD card’s CS-bar pin is connected to pin 53 on the Mega. Thus we needed to change the line if (!SD.begin(4)) { to read if (!SD.begin(53)) { before compiling and uploading the sketch. It then worked, showing a listing of all the files on an inserted SD card, so the SD card slot on this board works as expected. The unpopulated footprint noted earlier is designed to be fitted with a flash memory IC. It too uses the SPI bus, and according to the specification sheet, uses the Mega’s pin 45 as its CS (chip select) line. There is no further information on how this should be used, although we would not be surprised if the footprint matches many of the commonly available flash memory ICs. In summary, this display is easy to get, looks good and works well with the provided libraries. siliconchip.com.au The lack of a touch panel limits its utility somewhat, as does the awkward placement of the SD card slot. Being slightly smaller than the other two screens but with a similar pixel count, it does offer a slightly higher pixel density. Contestant number three: 3.5 inch with Arduino pinout The final display we tried is a 3.5in touchscreen with a standard Arduino shield pinout, and it gives a very tidy result when plugged into an Arduino Uno (see above). The display’s PCB sits flush with the USB socket on the Arduino board, and the microSD card slot fits neatly next to that USB socket. On the back of the PCB, along with the microSD card slot, there are two SSOP ICs (presumably for level conversion) and an unpopulated SOIC footprint. The SD card and SOIC-8 footprint appear to be connected directly to the board’s I/O pins and not via the level converter ICs. The PCB itself is only marginally wider and longer than the display. So when combined with an Arduino Uno, it’s quite compact. But because this display uses an 8-bit parallel interface, it uses up many of the available pins. With the Uno, only a single analog pin and the serial communication pins are left free. That rather limits the utility of the combination! Australia’s electronics magazine So you would need to use it with a Mega in practical applications, which rather negates its compactness advantage, and also would require significant software changes that would slow it down. The board is marked with ‘mcufriend’ branding, and this hint led us to find some helpful tools to work with the module. We tried code designed to interface to the ILI9488 controller in parallel mode (which it supposedly used), but that didn’t work. Since the seller advised that the display could have one of a few different controller ICs, we decided to figure out which one it actually had. There is an excellent resource at siliconchip.com.au/link/aans – this is a tool designed to help identify and operate these shield-type displays. At the time of writing, the most recent update to this tool/library was only four days prior, so it appears that it is continually being updated. It also requires the “Adafruit_GFX” library, and it can identify and control a large number of different displays. Both the “Adafruit_GFX” and “MCUFRIEND_kbv” libraries can be found and installed from the Arduino IDE’s library manager. Screen2 shows how you can find and install these library dependencies using the Arduino Library Manager. May 2019  91 The serial 3.5in touchscreen: the reverse of the PCB is quite bare except for an SD card socket and the touch controller IC and its associated components. The circle highlights the pin we had to remove during testing to resolve a conflict on the SPI bus (also shown at left). You shouldn’t have to do this on your board! We then opened and ran the “graphictest_kbv” sketch from the File -> Examples -> MCUFRIEND_kbv -> graphictest_kbv menu. This displays some information to the serial monitor at 9600 baud, including an identification code which is read from the board. In our case, the code was 0x6814. According to the “MCUFRIEND_kbv.cpp” file in the library, this suggests that the controller in an RM68140, which is similar to the ILI9488 but has a different initialisation sequence. In our case, this demo code initialised the display and drew various test patterns, indicating that this sketch is capable of working with this display board. We took a look at the RM68140 data sheet but opted for a sneaky trick to work out the initialisation sequence, without having to read it in depth. We embedded some extra code into the library mentioned above to see what commands and data were being issued to the display, then copied these back to our sketch. This resulted in a working example sketch, named “8bit_320x480_display_demo”. Our download package also has a cut-down version of the MCUFRIEND_kbv library demo sketch. You will note that the sketch produces similar results to our example, but is much larger due to the library having many features that aren’t used. Our sample code is designed to work on an Arduino Uno board. Due to differing port and pin configurations, it will not work on other Arduino boards; it depends on direct port access for speed. The sketch includes some code that should work on other Arduino boards, but it is very slow and has been commented out for simplicity Fig.3: after unzipping the Z6527 resources from the Altronics website, the library files should look like this. The three selected folders starting with “U” are the ones being copied. Fig.4: the ILI9488 library from https://github.com/jaretburkett/ ILI9488 can be installed using the Arduino Library Manager by searching for “ili9488”. 92 Silicon Chip Touch panel The touch panel on this type of display is a simple fourwire resistive type. It doesn’t even have a dedicated controller IC, but instead, connects directly to the Arduino analog I/O pins. You can determine the touch location setting one of these pins to 5V (high), another to GND (low), and then performing an ADC read on either of the two remaining pins. The resulting value indicates the relative position of the touch in the X or Y axis. So the touch panel effectively behaves as a two-dimensional potentiometer, with the “wiper” actually being the point being touched. As two of the wires are connected to the horizontal edges and two to the vertical edges, the location in two dimensions can be found by performing two readings as described above, but changing which pins are driven and which are sampled. On this panel, the touch panel is connected to pins D6, D7, A1 and A2. Interestingly, all of these pins are also used for driving the display, so this is a very busy shield. This does not interfere with their touch functions. We’ve written a basic sketch that reads from the touch panel and displays the raw ADC readings on the screen. It’s called “8bit_320x480_touch_demo”. These ADC readings would need to be converted into Australia’s electronics magazine siliconchip.com.au display coordinates to implement a functional interactive touch interface, which in turn would require a calibration procedure, to account for differences in displays. We’ve also provided a sketch called “8bit_320x480_ touch_calibration”, which shows the basics of how to do this conversion and gives you a starting point for doing it. microSD card slot Even though the SD card socket on this display appears to be wired directly to the Arduino’s I/O pins (and thus, would be driving a 3.3V device from 5V outputs), we tried the “listfiles” sketch as above, but this time changing the initialisation line to read: if (!SD.begin(10)) { to suit the Uno’s pin mapping. Surprisingly, it worked. We suspect that we have a tough microSD card and would be surprised if it lasts long being directly driven from 5V pins. The SOIC-8 footprint on the board also appears to be directly connected to 5V I/O pins as well, with its pin 1 (which is CS-bar on many flash ICs) connected to pin A5 on the Uno. Verdict As noted above, this unit looks very tidy when paired with an Uno board, but since it leaves virtually no I/O pins free, it’s hard to think of a useful application for it. And as also mentioned above, if you use the obvious solution of upgrading to an Arduino Mega board, you lose most of its speed advantage over a serial display, since you can no longer do direct port writes. That the shield appears to connect to the microSD card slot and flash chip pins at 5V is concerning, and we would not recommend using those interfaces on these modules. Building the Arduino breakout board We are very happy with the 3.5 inch SPI display panels (the first ones described above). We felt that a proper breakout board was necessary to make it easier to connect them to an Arduino, avoiding the need for messy jumper wires. The circuit for this board is shown in Fig.5. There isn’t much to it. It mainly just routes the signals between the Arduino and display, while converting the Screen1: this Arduino code was generated by software running on the Arduino itself, after we added carefully crafted debugging code to the library which was able to initialise the LCD controller successfully. siliconchip.com.au Arduino’s 5V signal swing to 3.3V to suit the LCD screen, touch panel and SD card interfaces. There are seven 470/1k resistive dividers to achieve this. These are for the MOSI and SCK connections on the shared SPI bus, three CS lines (one each for the LCD, touch controller and SD card) and two extra control lines on the LCD controller; DC (data/command) and RESET. Note that we haven’t put a divider on MISO since it is a 3.3V signal coming out of the touch controller (or SD card), which a 5V Arduino boards can accept as-is. Per the data sheet, the minimum voltage level that an ATmega328 micro running from 5V is guaranteed to read as high is 3.0V. The board also supplies logic power (3.3V) to the display, which is taken from the Arduino’s 3.3V supply, and power for the backlight LED(s), which comes directly from the Arduino’s 5V supply. The touch controller’s T_IRQ line is not connected, as we felt that this would eat too much into the already dwindling number of available I/O pins on the Arduino. We have provided connection pads to all unused pins on the Arduino, so they can be connected by jumper lead if needed. In most applications, we find that it is not necessary. The SPI communication lines for the display are routed to the 6-pin ICSP header on the Arduino board. Since the introduction of the so-called ‘R3’ Arduino board layout, this is the location which is guaranteed to be connected to the Arduino’s hardware SPI pins, regardless of which digital I/O pins they map to (that differs between various Arduino boards). For this reason, the breakout board can be used with just about any 5V Arduino R3 board, and we’ve tested it with a few including the Leonardo, Mega and Uno. If you’re not sure that your board is R3 compatible, check that it has the ICSP header approximately halfway between the TX/RX pins and the analog pins. It should also have one 10-way, two 8-way and one 6-way female pin headers. Earlier versions typically lack the 10-way header. As mentioned earlier, JP1 can be used to connect the MISO line to the LCD controller, but generally, you will want to leave this open, or else the touch controller interface may not work. The PCB also has mounting holes for both the 2.8 inch and 3.5 inch display panels, as well as the Arduino board itself. The remaining spare room is occupied with a small prototyping area with 5V, 3.3V and GND connections nearby, and all unused Arduino pins have adjacent breakout pads. There’s also a slot which allows the end of the PCB to Screen2: both the Adafruit_GFX and MCUFRIEND_kbv libraries can be installed through the Arduino IDE’s Library Manager. Use the search terms above to help find them. Australia’s electronics magazine May 2019  93 Plug the 6-way, 8-way, 10-way male headers and the 2x3-way female header into the Arduino board and then slot the breakout board on top. Ensure it is flush and pushed down firmly before soldering the headers into place. All these header pins are soldered from the top side of the board. Check the headers are correctly soldered, and unplug the breakout board from the Arduino board. Use a similar technique for the headers that connect to the display panel, although you may find that your display panel does not come with the 4-pin male header fitted. Assuming this is the case, plug the 4-way male header into the 4-way female header, then plug the 14-way female header onto the display panel’s Fig.5: the breakout board circuit routes the connections between the Arduino pins and LCD pin header. Put the 4-way male headtouchscreen headers, while providing level translation to allow the 5V Arduino to drive the er end into the display pan3.3V chips on the LCD board. This conversion is done using 1k/470resistive dividers. el and rest the breakout board on top, ensuring that be broken off if you are using it for the 2.8in display, as all 18 header pins are in their correct locations. otherwise the board is 13mm wider than it needs to be. Now solder the headers onto the breakout board and then flip the assembly over to solder the 4-way male header to Construction the display panel. The breakout board is now complete The breakout board PCB is coded 24111181 and meas- and can be plugged back into the Arduino. ures 98 x 55mm. Use Fig.5, the PCB overlay diagram, as a Optionally, you can use tapped spacers and machine guide during construction. screws to secure the display panel to the breakout board. If you wish to cut down your board to suit a 2.8in dis- Mount the spacers to the display panel with the spacers plays, this should be done first, to avoid damage to installed behind and the screws on top. Fit the breakout board to the components. Run a sharp knife over the four tracks cross- rear of the display panel, and secure with the four remaining the narrow bridge to cut them cleanly. This avoids any ing screws. There will be a slight gap between the male risk of them tearing and lifting off the board. Now use broad-edged pliers to gently flex the board along the line of the slot until it breaks. You may like to clean up the rough edges with a file; we recommend doing this outside, preferably with a face mask to avoid inhaling fibreglass dust. The resistors are the first parts to fit, where shown in Fig.6. The 1k resistors will have colour bands of either brown-black-red-gold or brown-black-blackbrown-brown, while the 470 resistors will have either yellow-violet-brown-gold or yellow-violetblack-black-brown. You can leave the header for JP1 off (you probably won’t need it) but if you do want to install it, do so now. You can mount the header but leave the shunt off at first if you aren’t sure. Fig.6: use this PCB overlay diagram as a guide when building the Next, fit the five headers which connect to the Ar- breakout board. After fitting the resistors where shown, you just duino board. The easiest and neatest way to do this need to solder the headers in place. Some go on the top while those which plug into the Arduino are mounted on the bottom. is to use the Arduino board itself as a jig. 94 Silicon Chip Australia’s electronics magazine siliconchip.com.au Parts list – Arduino breakout board The completed R3 to LCD Adaptor. Note the jumper (highlighted above) is not populated and we have fitted headers for both 3.5 and 2.8 inch displays, although you will probably only use one (fit one or the other). If using the 2.8 inch display, you can break this PCB along the slots at the right side. and female headers as the 12mm spacers are longer than the approximately 11mm combined height of the headers, but they should still make good contact so this shouldn’t cause any problems. Software The sketches we have created are designed to stand on their own and do not require any separate libraries to be installed. The ZIP download package contains three sample sketches, all starting with “SPI”. Extract the contents of the .zip file to somewhere on your computer, and open one of the files with the Arduino IDE. Select the appropriate board and port combination, and click “Upload”. The three examples work as follows: 1) “SPI_320x480_display_demo” draws boxes, lines and text to the display as it cycles through the four possible orientation settings (two in portrait and two in landscape). 2) “SPI_3.5_inch_TFT_shield_demo_wth_touch” shows off the touch feature by drawing lines and displaying the current touch coordinates to the display. 3) “SPI_3.5_inch_TFT_touch_calibration” can be used to fine-tune the touch settings, although we found the default calibration worked fine with three different screens. The touch calibration sketch requires the Arduino Serial Monitor to be running. During the calibration stage, it will send four lines of text to the Monitor that should be copied over the similar lines in any sketch that uses these touch routines. For example: #define TOUCH_X0 1 #define TOUCH_X1 2001 #define TOUCH_Y0 199 #define TOUCH_Y1 76 You might also like to experiment with the library we mentioned earlier, remembering to change the pin definitions near the start of the “graphicstest” sketch like this: #define TFT_CS #define TFT_DC #define TFT_LED #define TFT_RST 10 9 -1 8 Resistors (all 1/4W 1% or 5%) 7 1k (brown black red gold or brown black black brown brown) 7 470 (yellow violet brown gold or yellow violet black black brown) the “Adafruit_GFX” library to be installed, which can be found by searching for its name in the Library Manager. In the software resource bundle for this project, we’ve included .zip files of the current versions of these opensource libraries in case you have trouble finding them. Future updates Now that we have confirmed that these displays can be used on both the Arduino and Micromite platforms, we plan to use them in future projects. Before we use them with a Micromite, we will need to write CFUNCTIONs to get an acceptable display update SC speed. INTO MODEL RAILWAYS IN A BIG WAY? With lots of points, multiple tracks, reversing loops, multiple locos/trains, – in other words, your model trains are more a passion than just a hobby? Then you might be interested in these specialised model train projects from March 2013 Automatic Points Controller (Supplied with two infrared sensor boards) (PCB 09103131/2)........................$13.50 Frog Relay Board (09103133)............$4.50 Capacitor Discharge for Twin-Coil Points Motors (PCB 09203131)..................$9.00 See article previews at www.siliconchip.com.au The library can also be installed via the Library Manager by searching for “ili9488” (see Fig.4). It also requires siliconchip.com.au 1 double-sided PCB coded 24111181, 98x55mm 1 3.5in 480x320 pixel ILI9488-based LCD touchscreen with SPI interface 1 Arduino R3-compatible board, such as the Uno R3, Mega R3 or Leonardo R3 1 10-way pin header 2 8-way pin headers 1 6-way pin header 1 4-way pin header 1 14-way female header (CON1) 1 4-way female header (CON2) 2 3-way female header strip OR 3 2-way female header strips 4 12mm-long M3 tapped spacers 8 6mm M3 panhead machine screws 1 2-way male header strip and jumper shunt (JP1; optional) ORDER NOW AT www.siliconchip.com.au/shop Australia’s electronics magazine May 2019  95