Silicon ChipMicromite LCD BackPack With Touch-Screen Display - February 2016 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: A defibrillator could save your life or that of your friend
  4. Feature: Defibrillators Save Lives by Ross Tester
  5. Project: Micromite LCD BackPack With Touch-Screen Display by Geoff Graham
  6. Project: Solar MPPT Charger & Lighting Controller, Pt.1 by John Clarke
  7. Product Showcase
  8. Subscriptions
  9. Project: Raspberry Pi Temperature/Humidity/Pressure Monitor, Pt.2 by Greg Swain
  10. Feature: Crowd Funding: Kickstarter & “The Joey” by Steve OBrien & David Meiklejohn
  11. Project: Valve Stereo Preamplifier For HiFi Systems, Pt.2 by Nicholas Vinen
  12. Review: Keithley’s 2460 Sourcemeter by Jim Rowe
  13. Vintage Radio: The 1948 Healing L502E 5-valve radio by Associate Professor Graham Parslow
  14. PartShop
  15. Notes & Errata
  16. Market Centre
  17. Advertising Index
  18. Outer Back Cover

This is only a preview of the February 2016 issue of Silicon Chip.

You can view 39 of the 96 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.

Items relevant to "Micromite LCD BackPack With Touch-Screen Display":
  • Micromite LCD BackPack PCB [2.8-inch version) [07102122] (AUD $5.00)
  • Micromite LCD BackPack PCB [2.4-inch version) [07102121] (AUD $1.50)
  • PIC32MX170F256B-50I/SP programmed for the Micromite Mk2 plus capacitor (Programmed Microcontroller, AUD $15.00)
  • 2.8-inch TFT Touchscreen LCD module with SD card socket (Component, AUD $25.00)
  • MCP1700 3.3V LDO (TO-92) (Component, AUD $2.00)
  • CP2102-based USB/TTL serial converter with 5-pin header and 30cm jumper cable (Component, AUD $5.00)
  • Micromite LCD BackPack V1 complete kit (Component, AUD $65.00)
  • Matte/Gloss Black UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $5.00)
  • Clear UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $5.00)
  • Gloss Black UB3 Lid for 2.8-inch Micromite LCD BackPack (PCB, AUD $4.00)
  • Firmware (HEX) file and documents for the Micromite Mk.2 and Micromite Plus (Software, Free)
  • Micromite LCD BackPack PCB patterns (PDF download) [07102121/2] (Free)
  • Micromite LCD BackPack/Ultrasonic sensor lid cutting diagrams (download) (Panel Artwork, Free)
Items relevant to "Solar MPPT Charger & Lighting Controller, Pt.1":
  • Solar MPPT Charger & Lighting Controller PCB [16101161] (AUD $15.00)
  • PIC16F88-E/P programmed for the Solar MPPT Charger & Lighting Controller [1610116A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Firmware (ASM and HEX) files for the Solar MPPT Charger & Lighting Controller [1610116A.HEX] (Software, Free)
  • Solar MPPT Charger & Lighting Controller PCB pattern (PDF download) [16101161] (Free)
Articles in this series:
  • Solar MPPT Charger & Lighting Controller, Pt.1 (February 2016)
  • Solar MPPT Charger & Lighting Controller, Pt.1 (February 2016)
  • Solar MPPT Charger & Lighting Controller, Pt.2 (March 2016)
  • Solar MPPT Charger & Lighting Controller, Pt.2 (March 2016)
Items relevant to "Raspberry Pi Temperature/Humidity/Pressure Monitor, Pt.2":
  • Script for Raspberry Pi Temperature/Humidity/Pressure Monitor Pt.2 (Software, Free)
Articles in this series:
  • Raspberry Pi Temperature/Humidity/Pressure Monitor Pt.1 (January 2016)
  • Raspberry Pi Temperature/Humidity/Pressure Monitor Pt.1 (January 2016)
  • Raspberry Pi Temperature/Humidity/Pressure Monitor, Pt.2 (February 2016)
  • Raspberry Pi Temperature/Humidity/Pressure Monitor, Pt.2 (February 2016)
  • 1-Wire Digital Temperature Sensor For The Raspberry Pi (March 2016)
  • 1-Wire Digital Temperature Sensor For The Raspberry Pi (March 2016)
Items relevant to "Valve Stereo Preamplifier For HiFi Systems, Pt.2":
  • Stereo Valve Preamplifier PCB [01101161] (AUD $15.00)
  • STFU13N65M2 650V logic-level Mosfet (Component, AUD $10.00)
  • Red & White PCB-mounting RCA sockets (Component, AUD $4.00)
  • Dual gang 50kΩ 16mm logarithmic taper potentiometer with spline tooth shaft (Component, AUD $5.00)
  • Hard-to-get parts for Stereo Valve Preamplifier (Component, AUD $30.00)
  • Hifi Stereo Valve Preamplifier clear acrylic case pieces (PCB, AUD $20.00)
  • Stereo Valve Preamplifier PCB pattern (PDF download) [01101161] (Free)
  • Laser cutting artwork and drilling diagram for the Hifi Stereo Valve Preamplifier (PDF download) (Panel Artwork, Free)
Articles in this series:
  • Valve Stereo Preamplifier For HiFi Systems (January 2016)
  • Valve Stereo Preamplifier For HiFi Systems (January 2016)
  • Valve Stereo Preamplifier For HiFi Systems, Pt.2 (February 2016)
  • Valve Stereo Preamplifier For HiFi Systems, Pt.2 (February 2016)

Purchase a printed copy of this issue for $10.00.

The Micromite LCD BackPack . . . add a touch-screen LCD to your next project By Geoff Graham The Micromite LCD BackPack combines a full colour touchsensitive LCD panel with a low-cost 32-bit microcontroller running a BASIC interpreter. It packs an incredible amount of power at an amazingly cheap price and will leave you thinking up project after project where you could put it to good use. A S ANYONE with a smartphone or tablet is keenly aware, a touchsensitive colour graphics LCD is the primary input and output interface for a whole range of products. These include not only smartphones and tablets but also air-conditioners, vehicle controls and GPS units, plus simpler devices such as coffee makers. Using the LCD screen, the user can clearly see what the product is doing and by using the touch screen, they can set options and control the device’s operation. So wouldn’t it be great to have the same capability in your next creation? Well now you can, with the Micromite LCD BackPack. It’s based on SILICON CHIP’s Micromite Mk2 microcontroller running a BASIC interpreter and a 20  Silicon Chip 240 x 320 pixel colour LCD panel with a touch-sensitive interface. The LCD panel can be purchased on eBay for less than $10 and by adding the low-cost Micromite and a few other components, you have a complete controller/display package. By using the easy-to-learn BASIC programming language, you can create a professional graphical interface for your next creation, be it a reticulation controller, battery monitor, temperature controller or some other project that you probably haven’t yet thought of. With just a few lines of BASIC, you can display text and draw graphs and symbols. The touch sensitive input can be queried from within BASIC, so the display is all you need to use and control the gadget. It really is that easy! It’s also easy to build, uses just a few parts and costs less than $25. What are you waiting for? Start creating. The Micromite Regular SILICON CHIP readers will remember the Micromite which was introduced in May 2014, followed by an updated version, the Micromite Mk2 in the January 2015 issue. These both use a low-cost 32-bit PIC32 microcontroller running a Microsoft compatible BASIC interpreter called MMBasic. The BASIC language used by the Micromite is easy to use, yet powerful. It has the ability to detect logic signals (ie, on/off) as well as measure voltages, frequency, temperature, siliconchip.com.au humidity and more. Other functions include an infrared remote control input, support for numeric keypads and an in-built clock. Programs are stored in the chip’s internal flash memory and can be edited on the Micromite using its in-built full screen editor, via a serial interface. A program can be configured to run immediately on power up so that the Micromite acts as a pre-programmed custom chip and the user need not know anything about what is running inside. A powerful feature of the Micromite is the range of communications protocols that it supports. These include I2C, asynchronous serial, RS-232, IEEE 485, SPI and 1-Wire. These can allow your program to communicate with other chips and sensors and to send data to test equipment. The 28-pin Micromite used in the LCD BackPack has 11 spare input/output pins, so there is plenty of capability for controlling and interacting with the outside world. ILI9341-based LCD panel The ILI9341 is a graphics LCD controller that is often referred to as a COG device (Controller On Glass). This means that the controller chip is bonded directly to the glass substrate used for the LCD. LCD panels using this technique are manufactured in very large numbers for use in common consumer products such as microwave ovens and refrigerators. As a result, they are startlingly cheap. You can find them on eBay for under $10 and that often includes free freight. This is incredible value considering what you get, especially when compared to the old standby for DIY microcontroller projects, the tiny 2-line 16-character LCD module. That’s now so “last century”! The display supported by the Micromite has 270 x 340 pixels, 65,536 colours and comes in three different sizes – 2.2 inch, 2.4 inch and 2.8 inch diagonal. Most versions also have a built-in resistive touch controller, so you can draw buttons and symbols on the screen and users can then select these by simply touching the screen. MMBasic 5.1 The latest version of MMBasic used by the Micromite Mk2 includes many improvements but the stand-out feature is its support for ILI9341-based LCD panels. There are six basic commands that interact with the display, siliconchip.com.au Features & Specifications • Colour TFT LCD with 320 x 240 pixels, 65,536 colours, and 2.2-inch, 2.4-inch or 2.8-inch diagonal measurement. • • Touch sensitive screen with the touch coordinates reported in pixels. • 11 input/output pins. All can operate as digital input/outputs and four can operate as analog inputs. Three additional I/O pins for SPI use. • • Digital I/O sink or source capability of 15mA. • Graphic commands include CLS, PIXEL, LINE, BOX, RBOX, CIRCLE, TEXT and BITMAP, using any of the 65,536 colours. • Communications protocols include I2C, asynchronous serial, RS232, IEEE 485, SPI and 1-Wire. • Built in support for IR remote controls, temperature and humidity sensors, distance sensors, numeric keypads and battery-backed clocks. • • Power supply: 4.5V to 5.5V. • Dimensions: 50 x 86 x 27mm for 2.8-inch LCD; 45 x 77 x 27mm for 2.4-inch LCD. Microchip 32-bit 48MHz microcontroller with 256KB flash memory and 64KB of RAM. MMBasic interpreter with 59KB program space and 53KB RAM (for variables and other uses). Programs can be 2500 lines or more in size. Current drain: 175mA at normal screen brightness; 225mA at full brightness (40MHz CPU speed). the simplest being PIXEL which allows you to set a single pixel to any one of 65,536 colours. You can also draw lines with the LINE command, circles with the CIRCLE command and boxes with the BOX command. These commands have many options so, for example, you can control the width and colour of the lines as well as the colour used to fill boxes and circles. The TEXT command will display text in any position on the display panel in the same 65,536 colours. More than a dozen fonts are available, ranging from tiny to large, and these include graphical icons which can be used to liven up the display. Most cheap LCD panels also have a resistive touch screen and MMBasic 5.1 includes full support for detecting a touch on the screen via the TOUCH() function. This will return the X and Y coordinates (in pixels) of where the screen is touched so that your program can react accordingly. Using the drawing commands, you can draw a button on the screen and then monitor the touch function to see if that button has been pressed. The touch feature is so convenient that you will be able to dispense with physical switches and/or knobs in many projects. Micromite LCD BackPack The Micromite LCD BackPack brings The Micromite LCD BackPack incorporates graphic drawing capabilities with touch sensitivity, so it’s easy to use it as a user input/ output interface in a project. In this case, the display shows a keypad which can be used to enter a number. February 2016  21 +5V POWER AND CONSOLE REG1 MCP1700-3302E IN GND 10 µF +3.3V OUT 10 µF 100nF 100nF 5V Tx 13 Rx GND CON1 DATA OUT 11 DATA IN 12 MICROMITE I/O 1 RESET 3 4 5 9 10 14 16 SPI OUT/ANALOG/DIGITAL/INTERRUPT ANALOG/DIGITAL/INTERRUPT 4 ANALOG/DIGITAL/INTERRUPT 5 COM2:TX/DIGITAL/INTERRUPT 9 COM2:RX/DIGITAL/INTERRUPT 10 SPI IN/5V-TOLERANT DIGITAL 14 5V-TOLERANT DIGITAL/COUNT/WAKEUP/IR 16 5V-TOLERANT DIGITAL/COUNT/I C CLOCK 17 2 17 5V-TOLERANT DIGITAL/COUNT/I C DATA 18 COM1:TX/5V-TOLERANT DIGITAL 21 COM1:RX/5V-TOLERANT DIGITAL 22 ANALOG/DIGITAL 24 SPI CLK/ANALOG/DIGITAL 25 ANALOG/DIGITAL 26 2 18 21 22 24 25 26 3 +3.3V 15 T_IRQ T_DO T_DIN 7 T_CS MICROMITE MK2 T_CLK SDO (MISO) LED IC1 PIC32MX170F –256B SCK SDI (MOSI) 2 D/C 23 RESET 6 CS VR1 100 Ω 14 25 20 8 +5V ILI9341 BASED LCD DISPLAY 28 19 27 PINS ON IC1 47 µF TANT GND 3 BACK LIGHT +5V GND VCC CON3 ICSP 1 3 – GND RESET 5 – PGC 4 – PGD S1 6 – NC 10k CON4 +3.3V +5V 20 1 6 2 –Vcc 5 CON2 SC  1 – MCLR +3.3V 4 MC P1700 MICROMITE MK2 Backpack For LCD touch-screen IN OUT GND Fig.1: the Micromite LCD BackPack circuit uses just 10 components, including the LCD panel. IC1 is the Micromite which does most of the work, while IC2 is a voltage regulator supplying 3.3V to IC1. There is another voltage regulator built into IC1 which supplies 1.8V for the CPU inside this IC. The 47µF capacitor on pin 20 (Vcap) stabilises this regulator and it is critical that a high-quality capacitor, such as a tantalum type, is used in this position. all three of these elements together. It is a small PCB that is designed to piggyback on an ILI9341-based LCD panel, making a two-layer “sandwich”. It uses just 10 components and will take less than half an hour to build. The backpack is designed so that it and its LCD panel can be plugged into a solderless breadboard with a 0.1-inch pitch. This allows interface circuitry to be tested and debugged in an easy-to-use environment. Then, once debugged, the circuit can be transferred to a custom PCB or strip board and mounted on the back of the BackPack, making a compact threelayer sandwich. The accompanying photographs give some examples of what you can use the Micromite LCD BackPack for. We experimented with a battery monitor, digital speedometer and an engine 22  Silicon Chip monitor. But as you may have realised by now, the possibilities are endless. Referring to the circuit in Fig.1, you can see that the Micromite LCD BackPack is about as simple as it gets. The main power input is 5V and this is used to directly power the LCD. It is also fed to a small 3-pin regulator that provides 3.3V for the microcontroller. The microcontroller used for the Micromite is the Microchip PIC32MX­ 170F256B. This device has a 32-bit processor running at up to 50MHz, 256KB of rewritable flash memory and 64KB of RAM; not bad for something so cheap. Most pins on the Micromite run to the four main connectors: • CON1 is the power input and the console (more on that later); • CON2 is the main I/O connector and it is here that you interface the Micromite LCD BackPack to the outside world; • CON3 is the connector dedicated to the ILI934-based LCD panel; and • CON4 is the ICSP (In-Circuit Serial Programmer) connector which is used to load the MMBasic firmware into a blank microcontroller. We specified a rightangle 6-pin header for this connector, as that allows a programmer such as the PICKit3 to plug into CON4 even when an LCD panel is attached. The only other components of note are S1 which is a small pushbutton used to reset the processor and R1 which is a 100Ω trimpot that’s used to adjust the brightness of the LCD’s backlight. R1 is in series with the power to the backlight LEDs, so it limits the current drawn by them and therefore the brightness. Note that the LCD panel also has a siliconchip.com.au This view shows the 2.8-inch touch-screen LCD panel. The 2.4-inch panel is slightly smaller but is otherwise virtually identical in appearance. Both display sizes will plug into either BackPack PCB and will work perfectly. The only issue with a mismatched display and BackPack PCB is that a special physical mounting arrangement would be required. 3.9Ω resistor in series with the backlight so you will not burn out the backlight if you wind R1 all the way down to 0Ω. Sourcing the LCD panel As stated, the ILI9341-based LCD panels come in three sizes: 2.2-inch (56mm), 2.4-inch (61mm) and 2.8-inch (71mm) diagonal. Generally, the 2.2inch display does not have a touchsensitive screen while the 2.4-inch and 2.8-inch displays do. The display also includes an SD card socket but that is not supported by the Micromite Mk2 due to memory limitations. The best place to find a suitable display is on eBay but other online markets such as Alibaba also have them, as well as some online retailers. There are many variations on offer so make sure that the display that you purchase matches the photographs in this article. This is important – the Micromite has been extensively tested with the photographed displays so you can be sure that they will work. Other features to look out for in a compatible display are a red PCB, a resolution of 240 x 320 pixels and an SPI interface. Often, the description will emphasise that the display is for use with the Arduino but that is not relevant; they work just as well with the Micromite. On eBay, the best way to find a suitable display is to search for the phrase “ILI9341 LCD”. You should find many displays ranging in price from US$6 upwards. Note that there are some 2.4inch displays on the market that omit the touch sensitive controller so if you siliconchip.com.au A rear view of the 2.4-inch LCD panel (the 2.8-inch panel looks the same except for its slightly larger dimensions). Note the 16-pin touch controller chip to the bottom right. There are a number of different displays on the market so make sure that the display you purchase matches this photograph to ensure that it is compatible with the Micromite LCD BackPack PCB. need that feature, make sure that it is confirmed in the seller’s description. Because the 2.2-inch display does not normally include a touch panel we did not design a PCB for that size but we did design separate PCBs for the 2.4-inch and 2.8-inch displays. The only difference between the two boards is that their dimensions and mounting holes match the corresponding display; otherwise they are identical. All three display sizes will plug into either-sized PCB and will work perfectly. So your only issue with a mismatched display and PCB is that you will need to use a different physical mounting arrangement. The 14-pin female connector used for CON3 (to connect the LCD display) can be difficult to source. You can buy them on eBay or you can do what we did and cut down a longer connector to size and then use a file to smooth the rough edge so that it looks presentable. The reset pushbutton switch (S1) can be mounted on either side of the board. Mounting it on the noncomponent side may make it easier to reach when you have the board and LCD panel fastened together. Note that the 10µF and 47µF capacitors are polarised (the longer lead is the positive) so make sure that they are orientated according to the silk Construction Construction is quite simple but before you commence you need to consider a few options. If you are buying a pre-programmed chip for the Micromite you could leave out CON4 – the programming connector. Also you do not necessarily have to use an LCD panel with the Micromite BackPack. It could be just the Micromite that you need and in that case CON3 can be omitted. Finally, you may want to run wires directly to CON2. In that case, you can omit the pin header for that connector. As usual, you should start construction with the low profile components and work your way up to the bigger items such as the connectors. We recommend using a socket for IC1 as that will enable you to swap out the microcontroller if you suspect that you have damaged it. The BackPack PCB is designed so that it can be plugged into a solderless breadboard. This allows any interface circuitry to be tested and debugged before a PCB is designed. February 2016  23 2.4-Inch Micromite LCD BackPack http://geoffg.net/micromite.html MCP1700-3302E CON3 LCD S1 RESET 07102121 Backlight VR1 100Ω 2.8-Inch Micromite LCD BackPack 07102122 + 10 µF IC1 PIC32MX170F256B-50I/SP http://geoffg.net/micromite.html 1 (UNDER) 10 µF REG1 MCP1700-3302E CON3 LCD 100nF 1 ICSP CON4 100nF CON1 + + 47µF + + 100nF 1 REG1 10 µF IC1 PIC32MX170F256B-50I/SP 1 10 µF 10k 47µF 10k GND (UNDER) + 100nF CON4 CON1 (UNDER) 1 ICSP 5V TX RX CON2 5V GND 3 4 5 9 10 14 16 17 18 21 22 24 25 26 3V3 RESET (UNDER) 5V TX RX GND RESET 3 4 5 9 10 14 16 17 18 21 22 24 25 26 3V3 5V GND CON2 S1 RESET Backlight 100Ω VR1 1 Fig.2: these two diagrams show the parts layout on the BackPack PCB for the 2.4-inch LCD at left and the 2.8-inch LCD at right. Note that pin headers CON1 & CON2 at the top mount on the rear of the PCB (both versions). screen on the PCB. The 47µF capacitor is particularly critical and must be a tantalum type, not electrolytic. A multi-layer ceramic capacitor could also be used in this location but they are generally SMD types for this sort of value. The final PCBs have provision for SMD or through-hole capacitors. Pin headers CON1 (console + power) and CON2 (I/O pins) should be mounted on the underside (non-component) side of the board, as shown in the photos. Don’t mistakenly mount them on the top of the board because they would then be impossible to reach when an LCD panel is attached. Before you plug the microcontroller into its socket it would be prudent to apply power and check that 3.3V is across the correct socket pins and that +5V is on the correct pin on CON3. With that check made, you can remove the power and plug in IC1 and the LCD panel. The BackPack PCB and the LCD panel can then be fastened together on all four corners using M3 x 12mm tapped spacers and M3 x 6mm machine screws (or, as shown in the photos, 16mm machine screws with nuts). Be careful when handling the LCD panel. The ILI9341 controller is sensitive to static electricity and can be easily destroyed with careless handling. Make sure that you are grounded when handling the display and avoid touching the connecting pins. Finally, if you have a blank PIC32 microcontroller, it should be programm­ ed with the latest Micromite firmware which can be downloaded from the SILICON CHIP website. Refer to the accompanying panel for the details on how to do this. Connecting the console In order to write and debug BASIC programs on the Micromite, you use the console. This is a serial interface running at 38,400 baud and which uses TTL signal levels. This is similar to the RS-232 interface on older computers but the TTL signal level is inverted and swings from zero to 3.3V. USB-to-Serial Converters There are many USB-to-serial converters on the market, ranging in price from $2-20. One of the most popular types is based on the FTDI FT232RL chip. In fact, this chip has become so popular that some companies make clones of it, even down to the markings which imitate the genuine chip. This understandably upset FTDI and they released a new Windows device driver that not only refused to work with a clone chip but also disabled the chip so that it would not work with any other computer or driver.This driver was also included in an automatic update that Microsoft provided for Windows-based 24  Silicon Chip USB-to-serial converters based on the CP2102 chip can be found on eBay for just a few dollars. PCs, with the result that thousands of people found that their USB-to-serial converters suddenly stopped working and were worthless. The problem with this is that, at the time of purchase, there is no way of knowing if a new FT232RL-based converter uses the genuine chip or not. You will only find out when you receive There are quite a few USB-to-serial converters on the market (see the panel below). These provide a TTL level serial interface on one side and a USB interface on the other. When connected to a computer running Windows, Mac or Linux, the converter will appear as a virtual serial port. On a Windows computer, it often appears as a high numbered COM port, eg, COM12 or COM45. The serial interface side of the converter will generally have a ground pin and a 5V power output pin and these can be connected to the corresponding pins on CON1 on the Micromite BackPack. The serial converter will then provide power to the backpack and the attached LCD, which is handy when you are editing or testing a program. If you do not need the converter (perhaps you have a working program), you should use the GND and 5V pins on CON1 as the main power input. The USB-to-serial converter will also have two pins marked TX (or similar) for transmit and RX (or similar) the converter and try plugging it into a Windows computer. An alternative that does not carry this risk are converters based on the Silicon Labs CP2102 chip, as shown in the accompanying photograph. They can be found on eBay for a few dollars (search for “CP2102”). We have tested them on the Micromite with both Windows 7 and Windows 10 and can report that they work just fine. Because USB-to-serial converters based on the CP2102 are so cheap (often less than the retail price of the USB cable), you can afford to permanently connect one to the Micromite BackPack. This is handy if ever you need to come back and modify the program later. siliconchip.com.au The photo at left shows the fully-assembled PCB for a 2.4-inch LCD panel (the 2.8-inch version is nearly identical). The connector to the left is for the in-circuit programmer, the connector on the right is for the LCD panel and the two on the top are for input/output and the console. The view above right shows how the LCD panel plugs into the BackPack PCB, with the two then secured together using M3 x 12mm untapped spacers and machine screws (see text). for receive. The TX pin of the serial converter must go to the RX pin of the Micromite and the RX pin must go to the TX pin. This may sound confusing but it makes sense when you think about it. Basically, the transmit signal from the converter (the TX pin) needs to go to the receive pin (RX) on the Micromite so that the Micromite can receive data sent by the converter. Similarly, transmit from the Micromite must go to receive on the converter. When you plug the USB side of the converter into your computer you may have to load a driver to make it work with the operating system. Once this is done you should note the port number created for the virtual serial connection. In Windows, this can be done by firing up Device Manager and checking the “Ports (COM & LPT)” entry for a new COM port. Terminal emulator With this information, you can start up a terminal emulator program The USB-to-serial converter should be connected via colour-coded flying leads to a 4-way header socket, so that it can be plugged into CON1 on the underside of the BackPack PCB (see photo above right). Use a red wire for +5V, white for TX, yellow for RX and black for GND. on your desktop computer. This program acts like an old-fashioned computer terminal where it will display text received from a remote computer and any key presses will be sent to the remote computer over the serial link. For Windows, we recommend Tera Term version 4.88 which has a host of features and is free. It can be downloaded from http://tera-term. en.lo4d.com/ Once you have your terminal emulator running, you should configure it for the serial port number that you recorded previously and set the interface to 38,400 baud, 8 bits data, no parity and one stop bit. This is the standard used by the Micromite. Then you can hit the Enter key on the terminal emulator and you should see the Micromite command prompt (a “>” character). If you press the reset button on the BackPack, you should see the full copyright banner as shown in Fig.5. If you do not want to use a desktop computer you can use the ASCII Video Terminal featured in SILICON CHIP, July 2014. This will convert a PS/2 keyboard and a VGA monitor or old TV set into a full terminal emulator Fig.3: the Micromite LCD BackPack is connected to your PC using a USB-to-Serial converter. All programming and control of the Micromite is carried out via the console using a terminal emulator on the PC. Once the program is debugged and running, you can then disconnect the USBto-Serial converter. siliconchip.com.au February 2016  25 Programming The Micromite Firmware Before you can use the Micromite, you must program it with the Micromite firmware. This can be downloaded from the SILICON CHIP website and includes the MMBasic interpreter which is what you need to start programming in BASIC. The easiest option though is to purchase the chip already programmed from the SILICON CHIP Online Shop. This can either be obtained separately or as part of a kit (see parts list for further details). Alternatively, you can build the low-cost PIC32 programmer described in the November 2015 issue and program the chip yourself using the downloaded firmware. Yet another option is to use Microchip’s PICkit 3 programmer. This costs around $60 plus freight. The Micromite LCD BackPack is designed to accept the PICkit 3, even when the LCD display is attached. The accompanying photo shows just such a set-up To use the PICkit 3, you first need to download and install Microchip’s MPLAB X software development system on your personal computer. This comes in various versions for Windows, Mac OS and Linux. Unfortunately, the full install includes a lot of stuff that you don’t need (such as a full integrated development environment) but the important part is MPLAB IPE which is the programming component (IPE stands for Integrated Programming Environment). This is normally installed as an icon on your PC’s desktop. Using MPLAB IPE is reasonably intuitive. You simply select the PICkit 3 as the programmer, select the type of chip that you are programming (PIC- which will work perfectly with the Micromite. ble for download from the SILICON CHIP website) runs to just over 90 pages and we cannot cover that much detail here. So, the following is intended more to give you the “flavour” of how to program the Micromite using MMBasic. When you first connect to the Micromite with a terminal emulator you will see the command prompt, the “greater than” symbol (>). At this prompt, you can enter almost any command in the language to test features, configure options or run a program. For example, if you typed PRINT 2 + 2 and then hit the enter key, MMBasic would respond with 4 and then display the prompt again. This is immediate mode and is useful for testing commands and their effects. Most times, you will want to run a program that consists of more than one line and in this case there are three ways of getting your program into the Micromite. The first is by using the EDIT command which will start the Micromite’s built-in editor. Using the editor, you can seamlessly enter and edit programs up to the maximum size that the Micromite can handle (about 59KB). Another way to load a program is via the AUTOSAVE command. This instructs the Micromite to take anything that is sent to it over the console line and save it to program memory. The AUTOSAVE command will terminate when a Ctrl-z character is received. All terminal emulators have the ability to send a file over the serial line and when the whole file has been sent you can enter Ctrl-z on the keyboard to signal the end of the file. The third method is to use the XMODEM command on the Micromite. This will cause the Micromite to wait for an XModem transfer from the PC and then receive the program using that protocol. Many terminal emulators, including Tera Term, support the XModem protocol. MMEDIT Another convenient method of creating and testing your programs is to use MMEDIT. This program was written by SILICON CHIP reader Jim Hiley, from Tasmania. It can be installed on a Windows or Linux computer and allows you to edit your program on your PC and then, with a single button click, transfer it to the Micromite for testing. MMEDIT is easy to use, with colourcoded text, mouse-based cut and paste and many more useful features such as bookmarks and automatic indenting. Because the program runs on your PC, you can save and load your programs to and from the computer’s hard disk. It’s free and can be downladed from: http://www.c-com.com.au/MMedit.htm Driving the Micromite The Micromite User Manual (availa- Fig.4: to communicate with the Micromite LCD BackPack’s console, the terminal emulator must be set to 38,400 baud, 8 bits data, no parity and one stop bit. This example shows the serial set-up dialog box for Tera Term. 26  Silicon Chip Fig.5: when you connect the Micromite LCD BackPack to a PC and press the reset button on the BackPack, you should see the start-up banner displayed as shown here. The terminal emulator used here is Tera Term. siliconchip.com.au Parts List 32MX170F256B), load the firmware (the HEX file) and click on the “Program” button. The PICkit 3 will then program and verify the chip in less than a minute (see the article on using the PICkit 3 in the July 2010 issue for further details). MMEDIT (the free editing program mentioned earlier) automates this aspect for you. It uses a combination of AUTOSAVE and XMODEM to transfer the program at the click of a button. Inside the Micromite, the program is saved to non-volatile flash memory. This means that you can turn the power off and the program will still be there when you reapply power. With the program in memory, you can enter the RUN command which will cause the Micromite to start running it. If an error occurs, the Micromite will print an error message on the console and return to the command prompt. This is where the in-built editor is particularly useful. You can enter the command EDIT and the editor will place the cursor on the line that caused the error. When you have fixed the fault, you press F2 which will instruct the editor to save the program and run it again. This edit/run cycle is very fast and helps make programming the Micromite a breeze. when you have the Micromite LCD BackPack running and connected to the console is configure it for the LCD. To do this, type the following line at the command prompt and hit the Enter key: Configuring the LCD panel The first thing that you need to do OPTION LCDPANEL ILI9341, L, 2, 23, 6 This tells the Micromite that the LCD panel is connected and what I/O pins are used for critical signals such as reset and device select. This option only needs to be entered once because the Micromite will store the setting in its internal non-volatile memory and will automatically reapply it whenever power is applied. Following this command, the Micromite will initialise the display (which should go dark) and return to the command prompt. You can test the display by entering the following at the command prompt: GUI TEST LCDPANEL This will cause the Micromite to draw a series of rapidly overlapping coloured circles on the display. This animated test will continue until you This photo shows the display when the command GUI TEST LCDPANEL is used. It is animated, with random circles being rapidly drawn on top of each other and makes a good test of the Micromite and LCD combination. siliconchip.com.au 1 PCB, code 07102121, 77 x 45mm for 2.4-inch LCD; or code 07102122, 86 x 50mm for 2.8-inch LCD 1 ILI9341-based LCD, 320 x 240 pixels, 2.2-inch, 2.4-inch or 2.8-inch diagonal 1 4-pin tactile switch, through-hole 1 100Ω vertical mounting sideadjust trimpot (Altronics R2579, element14 9608044 or similar) 1 28-pin DIL low-profile IC socket 1 4-pin 0.1-inch male header (CON1) 1 18-pin 0.1-inch male header (CON2) 1 14-pin 0.1-inch female header socket (CON3) 1 6-pin 0.1-inch right-angle male header (CON4) 4 M3 x 12mm tapped spacers 8 M3 x 6mm machine screws OR 4 M3 x 16mm machine screws and matching nuts Semiconductors 1 PIC32MX170F256B-50I/SP microcontroller programmed with Micromite Mk2 firmware, V5.1 or later (IC1). Note: a PIC32MX170F256B-I/SP can also be used but will be limited to 40MHz 1 Microchip MCP1700-3302E/TO voltage regulator (IC2) Capacitors 1 47µF 16V tantalum or SMD ceramic (3216/1206) 2 10µF 16V tantalum or SMD ceramic (3216/1206) 2 100nF monolithic ceramic Resistors (1%, 0.25W) 1 10kΩ Where to buy parts A complete kit for the Micromite LCD BackPack will be available from the SILICON CHIP Online Shop. This includes a 2.8-inch TFT touchscreen and matching PCB, plus the programmed microcontroller and all other parts as listed above. The PCBs, the pre-programmed PIC­32MX170F256B-50I/SP microcon­troller & the MCP1700-3302E/ TO voltage regulator can also be purchased separately from the Online Shop. February 2016  27 CLS BOX 0, 0, MM.HRes-1, MM.VRes/2, 3, RGB(RED), RGB(BLUE) DO TEXT MM.HRes/2, MM.VRes/4, TIME$, CM, 1, 4, RGB(CYAN), RGB(BLUE) TEXT MM.HRes/2, MM.VRes*3/4, DATE$, CM, 1, 3, RGB(GREEN) IF TOUCH(X) <> -1 THEN END LOOP Fig.6: this simple program will display a clock/calendar on the LCD panel. press any key on the console’s keyboard and MMBasic will then return to the command prompt. To configure the touch feature you should enter the following at the command prompt: OPTION TOUCH 7, 15 This command allocates the I/O pins for the touch controller and initialises it. This option is also stored in nonvolatile memory and automatically applied on power-up. You do not have to run this command if your panel does not have a touch-sensitive screen but you must use it if your LCD does have a touch facility – even if you will not be using touch in your program. This is because the touch chip select line could “float”, causing the touch controller to respond to commands intended for the panel’s ILI9341 controller With the touch feature configured, MMBasic will know to keep the touch chip select line inactive. Before you can use the touch facility you need to calibrate it. This is done with the following command: GUI CALIBRATE This will cause MMBasic to draw a target at the top lefthand corner of the screen as shown in the accompanying photograph. Next, using a pointy but blunt object, press on the exact centre of the target. After a second, the target will disappear and when you lift your touch another target will appear on the top right. By repeating the above procedure, the target will be displayed, in turn, on all four corners of the display and the touch feature will be calibrated. When completed, the message “Done. No errors” should be displayed on the console. You also might get a message indicating that the calibration was inaccurate and in that case you should repeat it, taking more care to apply a steady press on the centre of the target. As before, these calibration details are saved in non-volatile memory and will be reapplied at power up. You can now test the touch facility with the command: GUI TEST TOUCH This will clear the screen and when you touch it, pixels will be illuminated at the touch point. This enables you to test the accuracy of the calibration. Using a stylus, touch the screen and the pixels under the touch point should light. Pressing any key will terminate the test. You can also use this test This is an example of the display when calibrating the touch screen using the command GUI CALIBRATE. 28  Silicon Chip This is the result of running the test program for a simple clock as describ­ ed in the text. Note that the font used in the photo is different from the font that you will see. feature as a simple drawing screen, rather like a high-tech version of the Etch A Sketch. Fault-finding Because it’s so simple, there’s not a lot that can go wrong with the Micromite LCD BackPack. If the display doesn’t light or perform as it should, the first thing to do is check that the correct supply voltages are on IC1’s socket and on CON3 (the LCD connector). That done, check the 5V supply current for the full module, including the LCD. It should range from 100-200mA, depending on the setting of the backlight trimpot. If it is substantially lower than this, check that the PIC32 and the LCD are correctly seated in their sockets. With the LCD removed, the power consumption should be about 25mA. If it is a lot less than this, it indicates that the PIC32 processor has not started up and in that case the 47µF capacitor is the most likely culprit. As previously stated, it must be a tantalum or multilayer ceramic type, not an electrolytic. This is an example of the display when the command GUI TEST TOUCH is used. It illuminates pixels where touched and is a good test for the touch calibration. siliconchip.com.au The rear side of the Micromite BackPack PCB is silk-screened with the functions and pin numbers of the console and I/O connectors. This makes it easy to identify the correct connector pin when the Micromite BackPack PCB and the LCD panel are fastened together. If the voltages and power consumption are correct, the problem could be with the console connection. Disconnect the USB-to-serial converter and join its TX and RX pins. Then try typing something into the terminal emulator. You should see your characters echoed back and if that doesn’t happen, it indicates a fault with the converter or the terminal emulator. If the USB-serial converter checks out, the fault could be related to the console connection to the Micromite LCD BackPack. Make sure that TX connects to RX and vice versa and that the baud rate is 38,400. If you have an oscilloscope, you should be able to see a burst of activity on the BackPack’s TX line on power up. This is the Micromite sending its start-up banner. Test program With the Micromite LCD BackPack working, you are ready to enter a test program. Using any of the three methods mentioned before (EDIT, AUTOSAVE or XMODEM), enter the sample program shown in Fig.6. This program will display a simple clock/calendar on the LCD panel as shown in an accompanying photo (note that the font used in the photo is different from the font that you will see). Touching the screen will terminate the program. The program starts by drawing a box Firmware Updates For firmware updates & manual please check the author’s website at geoffg.net/micromite.html You should also check out the Back Shed forum (www.thebackshed. com/forum/Microcontrollers) where there are many Maximite and Micromite enthusiasts who are happy to help beginners. siliconchip.com.au with red walls and a blue interior. It then enters a continuous loop where it performs three functions: (1) It displays the current time inside the previously drawn box. The string is drawn centred both horizontally and vertically in the middle of the box; (2) It draws the date centred in the lower half of the screen; and (3) It checks for a touch on the screen. This is indicated when the TOUCH(X) function returns something other than -1. In that case, the program will terminate. Interfacing The Micromite LCD Backpack interfaces to the “outside world” via CON2, the main I/O connector. This is designed so that you can plug it into a solderless breadboard or connect to a third board mounted on the back on the BackPack. The silk-screen on the PCB identifies each pin on the connector. The GND, 5V and 3.3V pins can be used to power your external interface circuitry. The maximum current that can be drawn from the 3.3V pin is 150mA, while the maximum 5V load will depend on your 5V supply. The RESET pin is normally pulled up by the onboard 10kΩ resistor to +3.3V and if you pull it low, the Micromite will reset. The other I/O pins connect directly to the Micromite and are marked with the Micromite’s pin number. Refer to the Micromite User Manual (downloadable from the SILICON CHIP website or from the author’s website) for details of what you can do with each pin. As an example, you could configure one of the analog-capable pins (say pin 4) to measure voltage. The command to do this is: SETPIN 4, AIN Measuring the voltage on that pin A test program for a lead-acid battery state of charge monitor using the Micromite LCD BackPack. The bar on the left shows the state of charge while the numbers on the right display the battery voltage, charging current in amps (from a solar panel) and the discharge current. A test program for an engine monitor using the Micromite LCD BackPack. The display updates smoothly, with the needles reacting very quickly to any change. Program courtesy Peter Mather on the Back Shed Forum. is then as simple as using the PIN() function. For example: PRINT PIN(4) This will display the voltage at pin 4 on the console. Three of the pins on CON2 (pins 3, 14 & 25) are also connected to the colour LCD for communicating with the display using the SPI protocol. For this reason, they cannot be used as generalpurpose I/O pins. However, they can still be used for SPI communications if needed; this is why they are included on this connector. The user manual (http://geoffg.net/ micromite.html) describes how to use the SPI interface simultaneously with the LCD and it’s not hard to do. However, for normal operation, you should just make sure that you do not use pins 3, 14 & 25 for general I/O. Well, that’s it – an inexpensive processor and display package with a host of possibilities. What plans do SC you have for it? February 2016  29