tft display ili9481 4th dimensional innovations for sale
I decided to integrate a Cortex M0 MCU with the 640×360 TFT LCD from the Sony U5 Vivaz mobile phone. If you haven’t already done so then you can read all about my prior efforts in reverse engineering that display in this article. The graphical user interface will be supported by an 8Mbit SPI flash device from Spansion.
TFTs always need two voltage inputs, one for the digital interface and one for the analog display driver. If you’re lucky they’re both the same and fit the same range as your MCU. We’re not so lucky with the R61523. The digital interface will take 3.3V but the analog voltage requires 2.8V. That’s no problem, we just drop in this small and cheap regulator.
There’s three words you don’t often see used together. Surely a 1-bit interface is never going to be fast enough for interactive graphics? Well, it is. By running the SPI interface at the fastest 24MHz rate offered by the MCU and utilising DMA to transfer big blocks at once we achieve bursts of 1.5 megapixels/sec. This is more than fast enough to update just the changing parts of the display in real-time.
Assuming the user hits go then the action starts. The PID algorithm will be repeatedly run to select a low-frequency PWM signal for the halogen lamp as the algorithm attempts to track the reflow profile. The actual temperature will be displayed in orange just below the desired temperature. A red-line will plot across the chart to show how the oven is performing.
Here it is switched on. The front panel buttons are illuminated and the control page is being displayed. It’s notoriously difficult to photograph an LCD display and this photograph does little to convey just how bright and colourful it is in reality. The controller box feels very light in the hand, maybe I should glue a brick inside to give it that ‘quality’ feel
By the way, besides its performance, the large colour display is a good reason to consider purchasing an MSO5000series scope rather than one of its smaller cousins.
for its size. We found the screen pleasant to look at. Although there are settings to adjust trace intensity and graticule brightness, the various other display elements do not
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
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
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
2 The Pi-cromite is a new addition to the Micromite family using the Raspberry Pi. The Pi-cromite firmware implements most of the features of the standard Micromite and the Micromite Plus as described in the Micromite User Manual and the Micromite Plus Manual. It has a number of differences and additional features and they are described in this document. The focus of this manual is to describe just the features that are unique to the Pi-cromite. For general Micromite programming you should refer to the Micromite User Manual and the Micromite Plus Manual in addition to this manual. Contents Introduction... 3 Micromite Family Summary... 4 Suitable Raspberry Pi and Installation Requirements pin Pi-cromite Pinout... 7 Unique Pi-cromite Features... 8 Commands (Pi-cromite Only)... 9 Functions (Pi-cromite Only) Appendix A - Sensor Fusion Appendix B - Socket Use Appendix C - Code Examples Appendix D - Using an I2S DAC with MMBasic Appendix E - Using an HDMI Display with MMBasic Appendix F - Sprites Appendix G - Running a program at boot Pi-cromite Manual Page 2
3 Introduction This section provides an introduction for users who are familiar with the Micromite and the Micromite Plus and need a summary of the extra features in the Pi-cromite. The Pi-cromite is an extension of the standard Micromite and the Micromite Plus; most of the features of these two versions are also in the Pi-cromite. This includes features of the BASIC language, input/output, communications, etc. Some commands have changed slightly but for the main part Micromite programs will run unchanged on the Pi-cromite. The following summarises features of the Pi-cromite as compared to the standard Micromite and the Micromite Plus: Raspberry Pi The Pi-cromite is based on the Raspberry Pi. The Raspberry Pi is available a number of versions and has up to fifteen times the program space of the MX series used in the standard Micromite and is many times faster. The Pi3 is 5x faster than even a 252MHz PIC32MZ. High Speed Double Precision Floating Point The Pi-cromite uses the built in hardware floating point capability of the Broadcom processor which is much faster than floating point on the standard Micromite and uses double precision floating point. I/O Pins The Pi-cromite has 26 free I/O pins. The Broadcom chip does not support analogue input. The Pi-cromite has one I 2 C port which can be implemented on any pair of pins, one SPI port, one high speed PWM channel (low speed PWM and servo control can be implemented on any/all I/O pins) and two serial COM ports. High Speed LCD Panels The Pi-cromite supports eleven different sized LCD display panels from 1.44" to 8 Socket I/O The Pi-cromite can support opening a socket which allows network based applications to be programmed directly in Basic. The TRANSMIT command will automatically create valid HTTP headers including file lengths making web programming simple Pi-cromite Manual Page 3
4 Micromite Family Summary The Micromite Family consists of three major types, the standard Micromite, the Micromite Plus and the Pi-cromite. All use the same BASIC interpreter and have the same basic capabilities however they differ in the number of I/O pins, the amount of memory, the displays that they support and their intended use. Standard Micromite Micromite Plus Micromite extreme Pi-cromite Comes in a 28-pin or 44-pin package and is designed for small embedded controller applications and supports small LCD display panels. The 28-pin version is particularly easy to use as it is easy to solder and can be plugged into a standard 28-pin IC socket. This uses a 64-pin and 100-pin TQFP surface mount package and supports a wide range of touch sensitive LCD display panels from 1.44" to 8" in addition to the standard features of the Micromite. It is intended as a sophisticated controller with easy to create on-screen controls such as buttons, switches, etc. This comes in 64, 100-pin and 144-pin TQFP surface mount packages. The extreme version has all the features of the other two Micromites but is faster and has a larger memory capacity plus the ability to drive a VGA monitor for a large screen display. It works as a powerful, self contained computer with its own BASIC interpreter and instant start-up. Runs on all versions of the Raspberry Pi with a 40-pin I/O connector. No analogue input capability but 5x faster than a Micromite extreme when running on a Pi 3. Micromite Micromite Plus Micromite extreme Pi-cromite pin 64-pin 144-pin pin pin pin 64-pin Raspberry SMD SMD SMD DIP SMD SMD SMD Pi Maximum CPU Speed MH MHz MHz MHz MHz MHz z MHz MHz Maximum BASIC KB 100 KB 100 KB 540 KB 540 KB 540 KB 1024KB Program Size KB RAM Memory Size KB 108 KB 108 KB 460 KB 460 KB 460 KB 1024KB KB Clock Speed (MHz) 5 to 5 to 5 to 5 to 200 to 200 to 200 to Total Number of I/O pins Number of Analog Inputs Number of Serial I/O or 4 3 or 4 3 or 4 3 or 4 3 or 4 2 ports Number of SPI Channels Number of I 2 C Channels RTC RTC RTC RTC RTC Number of 1-Wire I/O pins PWM or Servo Channels Serial Console Native Linux USB Console Native Linux PS2 Keyboard and LCD Console Native Linux SD Card Interface Native Linux Supports ILI9341 LCD Displays Supports Ten LCD + Pi-cromite Manual Page 4
5 Panels from 1.44" to 8" ILI9481 (diameter) Supports VGA Displays Sound Output (WAV/tones) Native Linux Supports PS2 Mouse Input Native Linux Floating Point Precision Singl Single Single Single Double Double Double Double e Power Requirements 3.3V 30 ma 3.3V 30 ma 3.3V 80 ma 3.3V 80 ma 3.3V 160 ma 3.3V 160 ma 3.3V 160 ma 5V 100mA 1.6A Pi-cromite Manual Page 5
8 Pi-cromite Features Double Precision Floating Point The Pi-cromite uses the hardware floating point capability of the Broadcom chip and can therefore process floating point calculations faster than the Micromite and Micromite Plus. All floating point uses double precision calculations. Twenty Six PWM Channels All pins can be used for PWM output up to 20KHz as well as for driving servos. In addition pin 12 can be used for PWM output up to 25MHz MM.DEVICE$ On the Pi-cromite the read only variable MM.DEVICE$ will return " Pi-cromite running on H/W version: hhhhhh ". CPU command The Pi-cromite does not support dynamically changing the CPU speed or the sleep function. Accordingly the commands CPU speed and CPU SLEEP are not available. However the Pi-cromite does support CPU SLEEP time where time is specified in seconds. OPTION CONTROLS command The Pi-cromite does not support the OPTION CONTROLS command instead the maximum number of GUI controls is set to 500. Longstring handling The Pi-cromite supports a comprehensive set of commands and functions for handling long strings stored in integer arrays Mouse control in editor While in the editor the left mouse button can be used to position the cursor. Just click on any character and the edit point will move to just before that character with the cursor on the character. Click just after the last character in a line to go to the end of that line. Click well past the end of a line to go to the start of the next line. The mouse wheel can be used to scroll up and down the file. Delete and Backspace Teraterm, Putty, and the Raspian desktop console window generate different codes for backspace and delete. The Pi-cromite defaults to support the console window and Putty. Use OPTION TERATERM ON to accept the default codes from Teraterm. Alternatively configure teraterm in the Keyboard setup window Ctrl-C and Ctrl-Z Use Ctrl-C to terminate a running program, to exit GUI TEST LCDPANEL, to exit GUIT TEST TOUCH or to exit from auto input mode. Use Ctrl-Z at the command prompt to exit MMBasic and return to the Linux command prompt I2C Before using I2C the pins to be used must be selected with OPTION I2C SDApinno, SCLpinno Then you can use I2C exactly the same as the Micromite with the following limitations: The implementation does not support 10-bit addressing (i.e. options 0 and 1 only) The implementation is Master only. DATE$ and TIME$ Date$ and Time$ are derived from the Linux system clock. They are returned in standard MMBasic format when read but cannot be set by MMBasic (except by using the SYSTEM command with the requisite Linux syntax) VAR command The Pi-cromite does not support the VAR command. On the Pi-cromite variables can be saved and restored from a file as the SDcard is always available SETPIN command The Pi-cromite does not support analogue input so SETPIN nnn,ain is not allowed but see function ADC and command OPTION ADC Automatic Console re-sizing The Pi-cromite does not support the OPTION DISPLAY command. Instead the code will automatically set the display width and height based on the size of the terminal window FONTS The Pi-cromite does not support loadable fonts but includes an additional small 6x8 font as #7 Pi-cromite Manual Page 8
10 FORK unix_command Executes the unix_command as a new process. Non-blocking. Output from the process is directed to the null device. Only one process may be started at any one time. Returns an error if a second process is attempted to be started before the first terminates e.g. FORK aplay sound.wav The status of the process may be tested with MM.FORK (see below) Note that the unix command does not need quotes or specific field separators but commas may be used instead of spaces if preferred. Note also that the C-library parser does not accept "-" characters in filenamesas these are treated as specific to command syntax. FORK KILL GUI STARTLINE n LINE x1, y1, x2, y2 [, LW [, C]] LONGSTRING APPEND array%(), string$ LONGSTRING CLEAR array%() LONGSTRING COPY dest%(), src%() LONGSTRING CONCAT dest%(), src%() Stops execution of any forked process. Returns an error if no forked process exists. Sets the row in the graphics memory which will appear at the top of the screen (landscape or reverse landscape) or left of the screen (portrait or reverse portrait) for a 4.3 SSD1963 display initialised with OPTION LCDPANEL SSD1963_4P All parameters can now be expressed as arrays and the software will plot the number of boxes as determined by the dimensions of the smallest array. x1, y1, x2, and y2 must all be arrays or all be single variables /constants otherwise an error will be generated. lw and c can be either arrays or single variables/constants. See the Micromite User manual for full details of parameter usage. Append a normal MMBasic string to a long string variable. array%() is a long string variable while string$ is a normal MMBasic string expression. Will clear the long string variable array%(). ie, it will be set to an empty string. Copy one long string to another. dest%() is the destination variable and src%() is the source variable. Whatever was in dest%() will be overwritten. Concatenate one long string to another. dest%() is the destination variable and src%() is the source variable. src%() will the added to the end of dest%() (the destination will not be overwritten). LONGSTRING LCASE array%() Will convert any uppercase characters in array%() to lowercase. array%() must be long string variable. LONGSTRING LEFT dest%(), src%(), nbr LONGSTRING LOAD array%(), nbr, string$ LONGSTRING MID dest%(), src%(), start, nbr Will copy the left hand "nbr" characters from src%() to dest%() overwriting whatever was in dest%(). ie, copy from the beginning of src%(). src%() and dest%() must be long string variables. "nbr" must be an integer constant or expression. Will copy "nbr" characters from string$ to the long string variable array%() overwriting whatever was in array%(). Will copy "nbr" characters from src%() to dest%() starting at character position "start" overwriting whatever was in dest%(). ie, copy from the middle of src%(). "nbr" is optional and if omitted the characters Pi-cromite Manual Page 10
12 OPTION I2C SDApin, SCLpin OPTION LCDPANEL HDMI OPTION LCDPANEL SSD1963_4P OPTION LCDPANEL spidisplay, orientation, DCpin, RESETpin, CSpin, SPIspeed OPTION PINS pinmask OPTION SERIAL CONSOLE n Specifies which pins are to be used for I2C. Any valid pin may be selected. They can be changed by using OPTION I2C DISABLE and then re-defining them. Must be run once before I2C can be used. The values are permanently stored in the.options file. This option is automatically set if OPTION ADC is in use Sets up an HDMI display for graphics/gui output. The code automatically reads in the display size and MM.HRES and MM.VRES are set automatically for you. The display must be set up in full 32-bit colour (RGBA). See Appendix E for more information. Sets the 4.3 SSD1963 display up in 480 x 864 (landscape or reverse landscape) or 864x480 (portrait or reverse portrait) pixel mode. The screen viewport is 480x272 or 272x480 and the position of the viewport is controlled by GUI STARTLINE n. This mode of operation allows display updates to be done on a non-visible part of the graphics memory and then the viewport moved to see the updated image. The 4P display controller is fully compatible with TOUCH, MOUSE, CURSOR and GUI controls Initialises a SPI TFT. Additional display types include the ILI9481 and ILI9486. A new parameter SPIspeed can be used to set the transfer rate. Valid values are 1,000,000 to 30,000,000. The ILI9481 defaults to 16,000,000 all other displays default to 30,000,000. See the Micromite User manual, ILI9341 section, for further details of parameter usage. Specify pins to be excluded from MMBasic e.g. OPTION PINS &B10100 will exclude pins 3 and 5 from use by MMBasic OPTION LIST will report the pinmask if non-zero SETPIN reservedpin,dout will report a reserved on boot error See Appendix D for an example of usage. Sets the device to be used as the MMbasic console device. By default this is 0 which is the terminal used to start the process. Alternatives are 1 and 2. Selecting one of these sets the console to use the COM1 or COM2 port. Changing the selection will automatically terminate MMBasic and it can be restarted. With the console set to COM1 or COM2 it is possible to run MMBasic as a background process using the Linux command: sudo./mmbasic &>/dev/null & This could be included as part of the boot process by adding the following lines to /etc/rc.local echo starting MMBasic cd /home/pi sudo./mmbasic &>/dev/null & OPTION SOCKET sockno OPTION TERATERM mode This will automatically run MMBasic on a Pi as a pseudo embedded application and if OPTION AUTORUN is set and the file AUTORUN.BAS exists then the user application will also start automatically. A standard USB/Uart can be used to connect to the COM port at anytime to access the MMBasic console. Sets the socket number to use when opening a socket. This defaults to 80 but can be anything between 1 and Sets the treatment of backspace and delete characters. Default mode is OFF. Setting mode to ON will allow teraterm to be used properly in the editor. Default should suit Putty and the Linux console window Pi-cromite Manual Page 12
14 SENSORFUSION type ax, ay, az, gx, gy, gz, mx, my, mz, pitch, roll, yaw [,p1] [,p2] SPRITE Calculates pitch, roll and yaw angles from accelerometer and magnetometer inputs. Valid fusion types are MAHONY and MADGWICK. Usage is described in Appendix A The BLIT and SPRITE commands can be used interchangeably. The command is available on all display types. SPRITE x1, y1, x2, y2, w, h SPRITE CLOSE [#]n SPRITE CLOSE ALL SPRITE COPY [#]n, [#]m, nbr SPRITE HIDE [#]n Copies the memory area specified by top right coordinate x1, y1 and of width w and height h to a new location where the top right coordinate is x2, y2. Closes sprite n and releases all memory resources. Updates the screen (see SPRITE HIDE). Sprites which have been copied cannot be closed until all copies have been closed Closes all sprites and releases all memory resources. It does not change the screen. Makes a copy of sprite n to nbr of new sprites starting a number m. Copied sprites share the same loaded image as the original to save memory Removes sprite n from the display and replaces the stored background. To restore a screen to a previous state sprites should be hidden in the opposite order to which they were written "LIFO" SPRITE INTERRUPT sub SPRITE LOAD [#]n, fname$ [,colour] SPRITE MOVE SPRITE NEXT [#]n, x, y SPRITE NOINTERRUPT SPRITE READ [#]n, x, y, w, h SPRITE SCROLLH n [,col] Specifies the name of the subroutine that will be called when a sprite collision occurs. See Appendix C for how to use the function SPRITE to interrogate details of what has collided Loads the file fname$ as a sprite into buffer number n. The file must be in PNG format RGB888 or RGBA888. If the file extension.png is omitted then it will be automatically added. The parameter colour specifies the background colour for the sprite. Pixels in the background colour will not overwrite the background when the sprite is displayed. Colour defaults to zero Actions a single atomic transaction that re-locates all sprites which have previously had a location change set up using the SPRITE NEXT command. Collisions are detected once all sprites are moved and reported in the same way as from a scroll Sets the X and Y coordinate of the sprite to be used when the screen is next scrolled or the SPRITE MOVE command is executed. Using SPRITE NEXT rather than SPRITE SHOW allows multiple sprites to be moved as part of the same atomic transaction. Disables collision interrupts Reads the display area specified by coordinates x and y, width w and height h into buffer number n. If the buffer is already in use and the width and height of the new area are the same as the original then the new command will overwrite the stored area. Scrolls the background and any sprites on layer 0 n pixels to the right. n can be any number between -31 and 31. Sprites on any layer other than zero will remain fixed in position on the screen. By default the scroll wraps the image round. If col is specified the colour will Pi-cromite Manual Page 14
15 replace the area behind the scrolled image SPRITE SCROLLR x, y, w, h, delta_x, delta_y [,col] SPRITE SCROLLV n [,col] Scrolls the region of the screen defined by top-right coordinates x and y and width and height w and h by delta_x pixels to the right and delta_y pixels up. By default the scroll wraps the background image round. If col is specified the colour will replace the area behind the scrolled image. Sprites on any layer other than zero will remain fixed in position on the screen. Sprites in layer zero where the centre of the sprite (x+ w/2, y+ h/2) falls within the scrolled region will move with the scroll and wrap round if the centre moves outside one of the boundaries of the scrolled region. Scrolls the background, and any sprites on layer 0, n pixels up. n can be any number between -MM.VRES-1 and MM.VRES-1. Sprites on any layer other than zero will remain fixed in position on the screen.. By default the scroll wraps the image round. If col is specified the colour will replace the area behind the scrolled image SPRITE SHOW [#]n, x, layer, [orientation] SPRITE WRITE [#]n, x y Displays sprite n on the screen with the top left at coordinates x, y. Sprites will only collide with other sprites on the same layer, layer zero, or with the screen edge. If a sprite is already displayed on the screen then the SPRITE SHOW command acts to move the sprite to the new location. The display background is stored as part of the command such that it can be replaced when the sprite is hidden or moved further. The orientation is an optional parameter, valid values are: 0 - normal display (default if omitted) 1 - mirrored left to right 2 - mirrored top to bottom 3 - rotated 180 degrees (= 1+2) Overwrites the display with the contents of sprite buffer n with the top left at coordinates x, y. SPRITE WRITE overwrites the complete area of the display. The background that is overwritten is not stored so SPRITE WRITE is inherently higher performing than SPRITE SHOW but with greater functional limitations. SYSTEM string$ [,array%()] Executes the Linux operating system command in string$. If the optional parameter is specified, the output from the system command will be directed to the long string array%() otherwise output will appear on the console (stdout). Output can also be directed to a file using standard Linux notation. See Appendix C for examples of usage. Pi-cromite Manual Page 15
19 equal in length and content and +1 if array1%() is greater than array2%(). The comparison uses the ASCII character set and is case sensitive. LGETSTR$(array%(), start, length) LINSTR(array%(), search$ [,start]) LLEN(array%()) MM.DEVICE$ MM.DISPLAY(X) MM.DISPLAY(Y) MM.DISPLAY(XMAX) MM.DISPLAY(YMAX) MM.FORK SPRITE( ) SPRITE(C, [#]n ) SPRITE(C, [#]n, m) SPRITE(H,[#]n) SPRITE(L, [#]n) SPRITE(N) SPRITE(N,n) SPRITE(S) Returns part of a long string stored in array%() as a normal MMBasic string. The parameters start and length define the part of the string to be returned. Returns the position of a search string in a long string. The returned value is an integer and will be zero if the substring cannot be found. array%() is the string to be searched and must be a long string variable. Search$ is the substring to look for and it must be a normal MMBasic string or expression (not a long string). The search is case sensitive. Normally the search will start at the first character in "str" but the optional third parameter allows the start position of the search to be specified. Returns the length of a long string stored in array%() Returns "Pi-cromite running on H/W version: hhhhhh" where hhhhhh is the version ID of the Raspberry Pi Gives the current X cursor position on the console (0
20 SPRITE(W, [#]n) SPRITE(X, [#]n) SPRITE(Y, [#]n) Returns the width of sprite n. This function is active whether or not the sprite is currently displayed (active). Returns the X-coordinate of sprite n. This function is only active when the sprite is currently displayed (active). Returns otherwise. Returns the Y-coordinate of sprite n. This function is only active when the sprite is currently displayed (active). Returns otherwise Pi-cromite Manual Page 20