8 bit device kindles eBook fire: An e-reader for the microtouch.

With all the fuss over Kindle Fire I thought it might be fun to see if the humble 8-Bit microtouch hardware would do a servicable job as an e-reader. With a bit of fiddling it turns out to be a quite capable if not entirely practical eBook.

Ebook
There are hundreds of thousands of books available in the epub format. The format is essentially a collection html/css/jpeg files and xml metadata such as author/title/table of contents bundled into a zip file (If you want to look inside an epub file simply change '.epub' extension to '.zip' and double click). I thought it might be possible to build a reader for the microtouch that would directly read a standard epub but the code and memory requirements for things like jpeg/png/gif decoders, xml parsers and decompression overwhelmed the available 2.5k RAM/32k Flash. The alternative was to transcode into a format that retained all the structure of the epub in a form easily digestible by a small, 8-bit device.

 

 

 

The transcoding tool (epubgrider) reads standard epub format files and creates '.epb' files readable by the microtouch code. The transcoder has a rudimentary layout engine that formats and paginates the html content, mapping font sizes and styles to those appropriate for viewing on a 320x240 screen. It records and stores hyperlinks within the html and resizes and transcodes images from jpg/png/gif etc to a raw 16bit RGB format. The transcoder then packages text/images/links/fonts etc with a spatial index in a '.epb' file. The spatial index allows fast scrolling through books with thousands of pages - 8500 for the largest book I found. Fonts are stored along with book so in theory books can have any typeface they like - epubgrinder can generate anti-aliased bitmap fonts from outlines. '.epb' books can be bundled into '.bks' bookshelves. Both formats are based on 'blob' files, a simple hierarchical data format that is suitable for 8-bit micros with microSD cards.

(download)

The net result is a little handheld device with virtually any number of books containing any number of pages. When launched the app shows a scrolling list of available books. Touching a book opens it in the reader, touching the right edge scrolls by page, touching the black bar at the bottom returns to the book list and saves your place in the book. The reader supports illustrations, hyperlinks within books for navigation and footnotes.

 

As always code is posted at https://github.com/rossumur/microtouch. The epubgrinder tool is based on the QT framework, contains a microtouch simulator and runs on Windows, Mac and Linux. There are a number of interesting .epb books and .bks bookshelves in the microSD folder and in the books.zip file in the tools directory.

 

If you don't want to build your own microtouch, the lovely folks at adafruit will sell you a prebuilt one. 

 

until next time,

Rossum

 

A Little Atari 810 Disk Drive

A tiny working model of a retro computing icon offers a blend of nostalgia and sillyness.

Booting

My first computer was an Atari 400. My first disk drive was the magnificent Atari 810. Overwhelmed by a recent wave of nostalgia from playing Zork for the first time in 30 years I have built a working model of an Atari 810 that uses 8Gig microSD cards instead of 5 1/4 inch floppies to emulate up to 8 drives. Maintaining the relative dimensions of drive to media, the model is somewhat smaller than the original.

(download)

Some numbers

The original 810 managed 90k per disk and had a volume of about 30,000 cm3. Assuming a 8Gig card the new version can store about 90,000 disks and at 5 cm3 only takes up 0.000167 times as much space. So it is a lot bigger and a lot smaller. Progress eh?

How it works

The Atari 810 (and subsequent 1050) drives are "smart" serial peripherals. The Atari OS communicates drives, printers, modems and devices using the SIO ("Serial Input/Output") protocol. SIO devices connected to the Atari with a chunky 13 pin connector.

Sio

The Atari addresses 5 bytes commands to peripherals by lowering pin 7 (Command) and transmitting 19200 baud asynch serial on pin 5 (Data Out). If the peripheral recognises the command ('1','R',1,0 for a read from disk 1, for example) it acknowleges the command and responds with data on pin 3 (Data In) at a pokey 19200 baud by default. Pin 10 can supply 50ma of 5v.

Sioread

Hardware

The hardware is pretty simple: a LPC1114 microcontroller, a microSD slot, a 3v3 regulator, a led and some caps. I used the 1114 because they are cheap and I had them lying around after building the Wikipedia reader: just about any 3v3 micro with SPI and a UART would also work fine. 

Schematic
(download)

The enclosure is a 3D print from Shapeways. This is the first time I have used them and I have to say I was delighted bt the experience. My inexperience in 3D modeling is evident but Shapeways sent me a lovely collection of little enclosures in various materials. I tried to make it as small as possible and still accomodate the microSD card. Testors enamel completed the look (make sure you mix in some olive with the light tan and cream).

Model

Software

The microcontroller code emulates up to 8 Atari drives. At power on it checks for a microSD card, mounts a Fat16 or Fat32 file system and scans the card for .ATR and .XFD disk image files commonly used with Atari emulators. It also looks for XEX files which are Atari executables, another emulator mainstay. The code then "inserts"  the BOOT.RUR image into drive 1 and waits for the Atari to start sending commands during bootup.

BOOT.RUR is a UI app written in C and compiled with cc65. Because the drive has no input or display we use this app running on the Atari to select disk images or applications. Cursor keys select the image or xex application, moving off the left or the right edge of the screen will page the list. Keys '1' ...'8' will insert the selected item into drives '1'..'8'. The space bar will eject the disk, the return key will boot the selected image or xex. If an xex is selected, the firmware will synthesize a kboot disk image to load and execute it.

(download)

It is electrically possible to write an Atari app that can reflash the firmware but so far this is left as an exercise to the reader. The board pinout happens to be the same as a FTDI serial cable so inital firmware downloads can happen through FlashMagic.

As noted earlier, 19200 baud is pretty pokey by modern standards. Other drive and dos vendors came up with various tricks to make the serial run at 38400 or 57600 or beyond. This board supports a common 57600 baud mode so if you tire of the nostalgic thweep-thweep-thweep you can speed things up a bit by using MyPicodos or similar.

There are lots of good commercial and open source emulators and serial cables that are much more complete (and a little more practical) than this one. I am amazed at the continuing innovation on this platform: check out Yoomp and Crownland and compare them to titles released in the 80s.

3D model, PCB, schematics, NXP and Atari code on github shortly.

Until next time,

Rossum

 

Zork for the Microtouch.

When I was a boy I burned (and listened to) much midnight oil playing Zork and many other Infocom text adventures hunched over my Atari 800. I have never forgotten profound delights of the exploring the darker regions of the Great Underground Empire: clever puzzles, lurking grues and snarking 90k disk drives.

It is hard to believe it has been 30 years since I first played Zork. To mark the occasion I have ported a Z-machine interpreter to the Microtouch

Photo
Playing Zork 1 on a microtouch in the dark. I am likely to be eaten by a grue.

The Z-machine was created in 1979 to play large (100k!) adventure games on small (8K!) personal computers. Long before the Java the implementors at Infocom built a virtual machine capable of paging, loading and saving complete runtime state that ran on a wide variety of CPUs. Pretty sophisticated stuff for microcomputers 30 years ago.

Infocom published the most enduring works of interactive fiction; if you have not played one of these beginning to end you are really missing one of the great joys of computer gaming. Since building the microtouch version I have replayed the three Zorks, Trinity and Hitchhikers Guide and can't understand why anyone would waste their time with the crap on facebook when these gems are out there.

The brilliant sprite ran Zork on an AVR the hard way; by implementing a CP/M emulator and running the Zork CP/M binary. His approach used an external 128k of DRAM, a luxury not available on the microtouch. Also UI (touchscreens, pixels etc) has progressed a bit since the days of CP/M so I took a slightly different approach: the code is based on a cut down version of frotz, the gold standard for z-machine interpreters. I was forced to remove support for the V6 "graphic" games to fit in the 32k flash limit of the microtouch. No great loss here, the text-only adventures were Infocom's finest.

Because the microtouch only has 2.5k of memory, all Z-machine memory is virtual, including its stack. 3 layers of caching of different granularities were required to get reasonable performance. A page file on the microSD card ("p.pge") acts as its backing store. By default the app loads "game.z5" game but will play most non v6 games: just change their name and copy to the microSD.

The bad news is that the code is too big to fit on microtouch with the bootloader. At 32k it needs to be programmed with an ISP. I will need to abandon frotz and reimplement with more AVR friendly code to shrink it to the size of a "normal" microtouch app. The hexfile, pagefile and a game are posted here. Copy "game.z5" and "p.pge" to microSD card, burn hex file with an ISP and enjoy. Remember the app supports save, restore and scrollback. Once you get to the barrow, you can find lots of other games here.

Until next time,

Rossum

 

Tardy update:

Finally posted source for Microtouch zork/frotz at https://github.com/rossumur/microtouch .

A 28k version with an icky fonts and a 31k with a nice font can be built with 'make zork' and 'make zorkcleartype'. Enjoy.

 

microtouch from adafruit

Good news for those who always wanted a microtouch but didn't have the time to build one: they are now available from the nice folks at adafruit. If you get one be sure to use the "rossum" coupon code at checkout for a 10% discount.

Microtouch_lrg
 

This version is powered by the delightful atmega32u4. It features a 320x240 pixel touchscreen, an accelerometer, full speed usb, a microsd card reader and a support for a lithium ion battery.

It has an application framework of sorts and it is possible to run a variety of applications with varying degrees of utility. Possibilites are bounded only by your imagination (and the 8 bit cpu + 2.5k of RAM). Tools support includes a PC simulator and a live sampling profiler. Code at https://github.com/rossumur/microtouch.

Building an App

Create HelloApp.cpp in apps/demos:

#include "Platform.h"

    class HelloState
    {
    public:
        int OnEvent(Event* e)
        {
            switch (e->Type)
            {
                case Event::OpenApp:
                    Graphics.DrawString("hello",110,100,0);
                    break;
                default:
                    ;
            }
            return 0;
        }
    };

    INSTALL_APP(hello,HelloState);

Build, Flash and test. You should get a little app that says 'hello' and never quits.

Ok. What is going on here? Microtouch as an application framework of sorts that allows multiple applications to be built into the firmware. An application is 'installed' with the INSTALL_APP macro: the first parameter is the name that will appear in the shell, the second defines a c++ object that maintains the applications state.

The framework (Shell.cpp) sends events to the app thorugh the OnEvent method; in this example the app draws "hello" on the OpenApp event which will always be the first event an app will see. The most common events come from the touch screen: TouchDown, TouchMove and TouchUp.

Because there is only 2k of RAM in this device we really don't have the luxury of things like memory managers. The applications state is all the heap it will ever know; its maximum size is defined by MAX_APP_BUFFER in Platform.h and is set to 768 bytes by default. If the app state is larger thanMAX_APP_BUFFER then the application won't be visible in the ShellApp.

Lets try a slightly more complicated version:

class HelloState
    {
    public:
        void Draw(int x, int y, int color)
        {
            Graphics.DrawString("Hello",x-10,y-6,color);
        }

        int OnEvent(Event* e)
        {
            switch (e->Type)
            {
                case Event::OpenApp:
                    Draw(120,160,0);
                    break;

                case Event::TouchDown:
                    if (e->Touch->y > 320)
                        return -1;      // Quit

                case Event::TouchMove:
                    Draw(e->Touch->x,e->Touch->y,RandomBits(1));
                    break;
                default:
                    ;
            }
            return 0;
        }
    };

    INSTALL_APP(hello,HelloState);

Now we can scrawl lots of randomly colored hellos over the screen and we can even quit by touching the bottom of the screen. The Graphics.h api is fairly self explanatory: it uses 5:6:5 RGB color and supports circles, rectangles and blitting as well as text.

Stdout is connected to the USB serial port so feel free to use printf for debugging.

Sample Applications

(download)

There are a number of example applications that exercise various parts of system. They don't all fit in the device at the same time. The APPLICATIONS path in the Makefile defines which apps get built into the firmware.

Shell

The shell is the Microtouch equivalent of the Finder or Explorer. It displays a list of installed apps and files found on the microSD card, and is responsible for lauching apps and delegating file opening to the View app. It also has code for a simple serial console:

  • ls - list files on microSD if present
  • p1/p0 - turn profiling on/off
  • lcd - dump lcd registers
  • appname - launch appname if installed

Off

The simplest app. It turns the Microtouch off unless it is plugged into USB. The Microtouch will turn itself off after 5 minutes of inactivity so you don't absolutely need this one, but I find it somehow comforting.

Calibrate

Calibrates touchscreen and stores calibration data in EEPROM. You probably will only need to run this app once if at all. Click in the red circles with a stylus until the application is satisfied with the consistency of the clicks. If you have a shattered touchscreen this app may give up after half a dozen attempts.

View

Displays files with inertial scrolling, currently IM2 files created with the MicrotouchTool are supported.

HWTest

Exercises major hardware components including touchscreen, accelerometer, microSD and backlight.

Accelerate

Accelerometer demo draws XYZ values and bounces a ball depending on the orientation of the device.

View

Displays files with inertial scrolling, currently IM2 files created with the MicrotouchTool are supported.

3D

The classic 3D Microtouch engine with accelerometer support. Tilt the device to move the object, touch the screen to select diffent platonic solids.

Pacman

Omage to the greatest game ever written, demonstrates a technique for flicker free sprites at >60Fps.

Doomed

A simple raycasting demo. Touchscreen controls speed and direction of movement. Despite the humble 8 bittyness of the CPU it manages 25fps. Play with it until you find the red wall.

Flip

Try and make all the dots the same color by touching to flip a pattern of 5. I find it bloody hard, I have only managed to complete it once. Could someone please publish a deterministic solution?

Lattice

Graphics demo generates a nice infinite mesh. Looks like it is complex 3D engine with lighting, shading and geometry. It isn't.

Mines

Click. Click. Boom.

Paint

Fingerpainting with touchscreen. Press harder for a bigger brush, select one of three brushes:

  • Cycle Chroma
  • Cycle Luminance
  • Color from accelerometer XYZ

Tools

Microtouch Tool

Microtouchtool

A simple tool to create IM2 slideshow files from jpg,png or other image files. Add as many images as you like, right click to change background, image fit or remove and image. Drag to reorder. when you are satisfied save the image to a microSD card and open from the Microtouch Shell.

Microtouch Profiler

Profiler

This tool is a GUI for the built-in sampling profiler. To use:

  1. Connect Microtouch to USB
  2. Make sure the Shell is running on the Microtouch
  3. Launch MicrotouchProfiler.exe
  4. File/Open the .lss listing file that was generated when the .hex file was built
  5. Launch the target Microtouch app

The left panel displays a list of modules sorted by activity. The right panel shows the .lss file which is a mixture of source and assembly plus red bars hiliting hotspots in the code. Click on a module to move to its start in the lss file.

The built-in profiler works by sampling the PC from a timer ISR and printing it over the USB serial. If you like hexidecimal numbers you can turn the profiler on and off by typing 'p1' and 'p0' in the console.

Microtouch Simulator

Microtouchsim

A Win32 based simulator for developing Microtouch applications without the actual hardware. Simulation is pixel accurate and includes a console window that emulates usb serial stdio. The accelerometer is emulated by a series sine waves of varing period, touch pressure is selected with keys '1' thru '9' CPU performance is not accurately emulated.

 

Three OLEDs

There are a number of cheap and adorable OLED displays appearing on ebay and elsewhere. But their parallel interfaces, enigmatic driver ics and funny voltage requirements make them tricky to use. These breakout boards make it easy to connect an oled to an Arduino or any other device with a SPI interface.

Img_6990

Interfacing

All of these screens have lots of pins. Most breakout boards dutifully provide all those pins to the outside world which leads to lots of wiring up and few unused GPIO ports. Fortunately these screens can be configured to use a SPI interface saving lots of pins.

SPI has a bad rap of being slow when it comes to displays. With a bit of fiddling it is possible to get 500k pixels per second from a Arduino Duemilanove which is more than enough perf for these small screens: >30fps on 128x128.

The job of converting from 5v GPIO to 3v3 is handled by a octal buffer (74AHC244 or equivalent). They are cheap, small and a lot easier to assemble that a bunch of resistors. If you are using 3v3 IO then leave the octal buffer unstuffed and use the 3v3 holes.

(download)

Power

OLEDs require a 12v-16v supply. Although 2 out of the 3 screens actually have 'built in' DC-DC converters they still need external components to generate the required voltages. These components are often fussy or inefficient and I usually just roll my own. Here I have used a FAN5331 boost converter. It isn't expensive and because it switches at 1.6Mhz you can use a small 10uh inductor which is handy of you are cramming parts onto a small board.

The Screens

The first screen is a monochrome (actually blue) 1 bit per pixel 128x32 display based on a SSD1303 controller. These are usually $5-$8 on ebay although I have seen them in china for < $2. Because this screen is only 1bpp we can afford an actual 512 byte frame buffer on the Arduino code. Of course you don't need to use a frame buffer if you don't want to.

The second screen is 96x64 and has 65k colors. It is based on the SSD1332 and comes in 0.8mm and 0.7mm pin pitch versions. They are $6-$7 on ebay, < $2 in china and show up as caller id screens in lots of phones and in some small mp3 players. If you see a small color OLED with a 31 pin connector it is usually a SSD1332. This controller has hardware accelerated fills and line drawing (<1ms to fill a screen) which could save you some perf and power if you do that sort of thing.

The third screen is my absolute favorite. It is a 128x128 pixel 262k color Samsung PM12FC001B that uses a LD50T6160 controller. These show up as spares every now and then on taobao. They are found in lots of OLED digital picture frames and several Samsung YP MP3 players. The demo shows a little Wolfenstein thing running on a Arduino.

(download)

A note about the video. OLEDs don't look very nice on video due to their use of PWM. I assure you these look much nicer in person; crisp high contrast images on all three.

Code, schematics and pcbs posted at https://sourceforge.net/projects/smartlcd/files/ (threeOleds.zip). The OLEDs and smartLCDs will converge into something a little more coherent in the near future.

Until next time,

Rossum

A Smarter Display

Connecting display to Arduino can be expensive, complicated and unsatisfying. The smartlcd attempts to make it cheaper, simpler and more fun.
 
There are lots of interesting displays hiding in cell phones, cameras, mp3 players and various other devices. In this post we will be looking at two of my non-Nokia favorites: The iPod Nano 2G display and the so called "cheapest TFT in the world". Then we will be making a gadget that hopefully does something useful with them.

To repurpose a display we need to determine its interface mode (serial/parallel), pinout and driver ic. If the display has a nice part number printed on the side then you might get lucky and have the interwebs answer all your questions. Much more often than not you have to do it the hard way.

Count the number of pins on the connector. If there are 8-16 pins it is almost certainly a 8 or 9 bit spi interface. Find the LED supply pins (almost always the thickest traces on the flex) and give them the respect their elevated voltages deserve. Attach a logic analyzer to a live system determine the spi clk (wiggles most), the spi mosi (wiggles second most), the spi select and the reset (wiggles once). See this example.

If you have 20 or more pins you have an 8 bit parallel interface. If you have 24 or more chances are it is 16 bit parallel. Many displays have the ability to run in both serial and parallel modes that can be selected with one or more external pins. If you are short of GPIOs this is a good option.

iPod Nano 2G
The iPod Nano 2G has a lovely little 22 pin transflective 176x132 screen. It has a 0.3mm pitch connector as seen in the iFixit tear-down. Nearly all 0.3mm ffc connectors have an odd number of pins. Apple thought different and used a DDK FF12 that is very hard to come by. After buying lots of replacement LCDs ($5 ebay + many $1 auction wins) and lots of dead/dying nano2Gs it was time bust out the fine transformer winding wire and a logic analyzer.
 
(download)
The data bus is easy to find: look for 8 consecutive bits that change all at the same time. The WR, CS and CD signals are then fairly easy to spot based on decreasing activity. As it turns out there are at least two different driver ics in these screens: A narrow one that looks a lot like a ILI9163 (8 bit wide commands, sets up blits with 0x2C) and wide one that looks a lot like an ILI9320 (16 bit commands, sets up blits with 0x22).
 
(download)

Although these controllers are similar to documented controllers they still have major differences and I needed to record an initialization sequence from a live boot in order to get them to work.

Connector pinout Nano 2G
        1        LED+ 6V
        2        LED-
        3        Frame Marker
        4        GND
        5        D7
        6        D6
        7        D5
        8        D4
        9        D3
        10        D2
        11        D1
        12        D0
        13        RD        Read
        14        WR        Write
        15        CD        Command/Data
        16        CS        Chip Select
        17        Reset
        18        GND
        19        VIO        3V3
        20        VDD        3V0
        21        ID0 
        22        ID1
Preview of an upcoming project using iPod Nano 2G screens:
(download)
 
The TFT 20
If one dismembers enough mp3 players one starts to notice patterns of part usage. One display caught my eye: it was very common in cheap 128x160 mp3 players, was a crisp and high contrast TFT, and had a hot bar solder connector that looked like it could be soldered by humans.
(download)
After dismembering a very nice Insignia digital photo keyframe and applying the logic analyzer the traces look very familiar. It was a ILI9163. Other devices turned up a ILI9161 and a Samsung S6D0144. All variants seem to have a very similar physical outline; another defacto standard like the touchscreen used in microtouch.They are widely available in China for $2 making them the cheapest TFT going.

(download)

So how can we make this lovely little screen useful to say an Arduino enthusiast? It needs 3v3 io on 14 pins connected to a 1mm pitch hot bar solder connector, a 6v boost converter to supply the leds, drivers, apis etc to make it useful. Not the simplest thing to do on a breadboard.
Thats where smartlcd comes in.
 
smartlcd 
 

The smartlcd adds intelligence to a TFT 20 display. An inexpensive Arm Cortex M0 or M3 microcontroller is used to provide graphics and media processing as well as providing a high speed serial interface the 3v3 display. With additional components the smartlcd can offer a spi-flash or microSD file system and usb. One single pcb scales from bare bones serial through to a stand alone lipo battery powered device.
A minimal configuration with just the backlight boost converter and serial interface:
2010-10-18_0002
smartlcd uses a serial link to connect to Arduino and other devices The serial link runs a slip framed, software flow controlled RPC at 1MBit. 5v to 3v3 level conversion is not necessary; the smartlcd inputs are 5v tolerant and can plug directly into the Arduino RX and TX pins. Because it is connected to the serial interface, the smartlcd can reprogram the Arduino and under the right circumstances the Arduino can be reprogram the smartlcd. The smartlcd can also be configured to be reprogrammed via USB and you don't have to know anything about arm or own a arm development kit to build one.
Img_6286

The client does not have to be a Arduino; the smartlcd can connect to virtually any serial device or USB. However smartlcd makes it very easy to display text, graph values and draw graphics quickly on Arduino:
// Console demo
        int a[2];
        a[0] = analogRead(A0);
        a[1] = analogRead(A1);
        if (_mode == 0)
                Console.Write("X:%d Y:%d\n",a[0],a[1]);
        else
                Console.Graph(0,1023UL,a,2);

        // Circle demo
        int x = random(128);
        int y = random(160);
        int r = random(70);
        int c = random(0xFFFFL);
        Graphics.Circle(x,y,r,c,1);

Fully loaded versions of smartlcd can decode JPEG, PNG and will be able to decode some forms of video. Source code, schematics and Eagle files: https://sourceforge.net/projects/smartlcd/.

Until next time

 

Building the RBox.

I finally got around to assembling a stand alone version of the RBox. As some of you correctly noted building a videogame for the price of a latte that depends on a $30 dev kit is cheating a bit. This version is self contained and while not practical or useful it is at least fun to build.

(download)

The design sandwiches a lithium button cell between the psp joystick and the pcb. It adds a single button that serves as both the power switch and a fire button. 2 axis control + fire may seem a modest level of input but modern standards but if it was good enough for Atari is is good enough for me.

(download)

Thin bendy metal on top of the cpu and on the bottom of the joystick provide a suprisingly effective friction fit for the CR1632 battery. Don't try to solder directly to the metal on the bottom of the joystick. When running a game and playing audio the device uses about 28ma so I get about 4 hours of continuous use from the CR1632. Feel free to use a CR1616 or CR1620 for a slimmer look and more frequent battery replacement. 

(download)

The schematic is virtually identical to the prototype with a few exceptions. The joystick VCC line is connected to a GPIO rather than  VCC to reduce power during normal operation and especially during deep power down. The fire button is connected to the WAKEUP pin that brings the beast back from deep power down. The code will deep power down the RBox after 3 minutes of inactivity. While turned off the RBox uses about ~200na as far as I can measure on my crappy meter. The board supports both composite and s-video.

(download)

If you don't feel like making your own pcb order them from http://dorkbotpdx.org/wiki/pcb_order. This is simply the cheapest and best way of getting pcbs in small volume. Nobody else comes close. Unless you really like what ferric chloride does for your sneakers there is no reason not to use these guys.

New code, schematic and pcb posted on https://sourceforge.net/projects/rbox/. If you would like a kit post a comment and if there is lots of interest I will see if I can get one organized.

Until next time

Screen Play: Lots of other screens for microcontrollers.

If you enjoy LCDs and microcontrollers chances are that you have tinkered with the ubiquitous Nokia 6100 screen. I love the fact that a youtube search for "Nokia 6100" produces may more AVR and PIC hacks than phones. In a bit of a departure from my normal projects this is the first in a series of posts on lots of other little known display choices that are better, cheaper and just more fun.

Despite its popularity the Nokia 6100 display has a few problems:

  1. Small (132x132)
  2. It is a CSTN (passive matrix) display leading to ghosting if things move quicky. Koopas are especially lethal if nearly invisible.
  3. Limited color depth of 12 bits (4096 colors + dithering on some displays).
  4. It comes with 2 incompatible driver ics (Philips or Epson).
  5. Not cheap: $15 from sparkfun or (gasp) $35-$42 for breakout boards.
  6. A fiddly, relatively uncommon 0.5mm connector that tends to tear off expensive breakout boards rendering them useless.
  7. Needs 6V for the backlight (2 leds in series).

The Nokia 6100 first shipped in 2002. Of the hundreds of models of phones from nokia (yes, hundreds) surely there are other screens of interest? A quick check in my junk phone archive of hundres of phones (yes, hundreds) turned up a few interesting candidates.

(download)

A quick check of the schematics turned up a series of SPI driven displays connected to 10, 22 and 24 sockets.

Nokia 1600: Although the 1600 screen uses the same 10 pin connector (Hirose DF23-10DS) as the Nokia 6100 the pinout is very different - so different in fact that if you plug a 1600 screen into a 6100 phone blue smoke will be emmitted and your phone will become a purely decorative item. The screen is speced as 96x65 CSTN.

Nokia 6101: Two displays here. A 96x65 CSTN caller id screen with backlight leds on the phone pcb (fail/win) and nice big one with a 22 pin 0.5mm connector (Hirose DF23-22DS) that is a 132x162 TFT (acvtive matrix) display.

Nokia 2760: Two displays again: an oh-so-cute teeny 96x65 blue monochrome display with the 10 pin connector and a 132x162 TFT with a 24 pin 0.4mm connector. These are not the Hirose DF30 series; I am still looking for a definitive source.

We know they are SPI, so lets get them wired up to a logic analyser and see if we can identify what controller they use. Once wired up we record the traffic going two and from the LCD as the phone boots. Looking at the traces it is clear that all these phone used a fairly uncommon 3 wire mode of SPI to determine what display is attached.

(download)

After an initial 0x11 (Sleep Out) 9 bit SPI command the 0xDA,0xDB and 0xDC (Read Device ID) commands are followed by 8 extra clocks during which the MOSI line is driven by the LCD. In this 3-wire SPI mode the MISO is really SISO (slave in slave out) and is usually not supported by hardware so we will need to bitbang during this discovery phase. This is the way Nokia 6100 phones can tell the difference between the Epson controller (that does not respond to RDDID) and the Philips controller (that does).

Rddid

Looking at SPI recordings reveal that the controller on the large screen looks an awful lot like the Philips PCF8833 controller in the 6100. Searching by RDDID manufacturer id 38H turns up the Orise SPFD54124B for the 6101 screen. It has a lovely 262k frame buffer and supports a 12,16 or 18 bit color format. Ironically googling this controller led to a great site that details this and other earlier phone displays. The caller id screen seems to be a SED1565 or similar, the 1600 seems similar to the Philips.

The 22 and 24 pin displays support SPI or an 8 bit paralell interface selected by a p/s pin. SPI is usually fast enough for smaller screens unless you are really perf sensitive. SPI means fewer pins on the mcu, fewer lines you need to convert from 5v to 3.3v etc.

Now the really good news. The 6101 displays are really cheap on ebay. <$3 with free shipping much of the time. They address problems 1) thru 5) listed above. The 1600 screens are also cheap if you need something small - dealextreme has them for <$5. 1200 displays are pin and code compatible with the caller id screen an very low power if you don't use a backlight.

All these and more in action:

(download)

The breakout board above supports both 10pin pinouts as well as 22 0.5mm and 24 0.4mm pinouts. It has a built-in boost converter for generating various led supply voltages controlled by pwm from the mcu. It has a sense pin to allow you to measure the backlight current and adjust it accordingly by varying pwm duty cycle.

Click here to download:
nokiaSuperBreakout.pdf (30 KB)
(download)

The software in the demo detects when a display is attached, selects the right driver and runs an appropriate graphics app: Wireframe 3D for mono screens, the reference Rossum icosohedron and a raycast lattice for color. As always code and schematics/pcbs will be posted on Sourceforge.

In the next post, I will look at displays from several non-Nokia phones, the worlds cheapest TFT and the Ipod Nano 2G.

Until then

 

 

UPDATE: PCB, schematics and code for AVR and NXP posted at https://sourceforge.net/projects/nokiasuperbreak/.

 

 

 

RBox: A diy 32 bit game console for the price of a latte

Uses the smallest and cheapest 32 bit CPU to generate 3D graphics and sound.


The RBox is a game console that is simple enough to build on the prototype area of a dev kit; no pcb required just a crystal, a few capacitors and resistors.

Rboxproto

 
Features:
320x240 composite or s-video output generated entirely in software
256 colors with standard palette, up to 8k colors
8 bit 15khz stereo audio
~$1 Analog joystick
~$1 CPU

A bit of history...
Ever since the Atari VCS generated video by Racing the Beam i have wanted to build something that generates video on the fly. There have been lots of great diy examples of this in the intervening years (Rickard Gunee's Picpong and SX Tetris, the lovely Uzebox) but the arrival of the ARM Cortex M0 parts from NXP rekindled my interest. The NXP LPC111X family is smallest 32 bit CPU. It is an ARM Cortex M0, the same device I used in the Wikipedia reader. This family of devices starts at under $1.

The LPC111X parts have ample horsepower for black and white video, as many less powerful chips have done in the past. At a max clockspeed of 48mhz they require 2 clocks to access memory or gpio so you could write a blit loop fast enough for 320 horizontal resolution (each pixel at 320x240 takes 8 cpu clocks, enough time for read/palette lookup/write/test/loop). Add a couple of resistors for a DAC, add sync pulses and you are in business. Overclock to 57.27272 and then you are a multiple of the chroma carrier and can generate colorburst and manipulate chroma phase: Now I had nice color bars but it wasn't clear how generalize this to a practical system that could be programmed to generate interesting and useful images.

The real breakthrough came when I realized I could re purpose SPI to manipulate chroma phase while the cpu used gpio to write luma. SPI also has a 16 byte fifo on these parts which allowed chroma writes to be queued relieving pressure on the luma timing. With SPI emitting bits at 1/2 the cpu clock rate I could get 8 bits per chroma clock, enough to do 8 different phases for 8 different hues. All the other 248 combinations of those bits generated other hues and levels of saturation, suggesting a palette of some sort might be useful.

Color generation solved, now I needed graphics. A frame buffer was out of the question: at 8 bits a 320x240 frame buffer is 75k. These devices have 2k to 8k total memory so another approach is needed. After fiddling with tiles (as in Uzebox) I eventually settled on a line buffer approach where the application sends individual lines to the video driver for display, allowing code that looks and feels like it is working with a framebuffer without the actual memory.

There are 2 pixel formats supported: 5 bits of luma with 3 bits of chroma index or 4 bits of luma with a 4 bit chroma index. The chroma indexes map to the actual 8 bit value emitted by SPI. The chroma palette can be changed every line allowing up to 8k colors on the screen at the same time. With 8 bit color filling the line buffer is simply a matter of dealing with 1 byte per pixel blitting and things like smooth scrolling become very simple.

The video driver generates 3 interrupts per line: i0 at start of the line to pull hsync and emit an audio sample. 1 pcm sample gets emitted per channel per scanline at 15.7khz which is the line rate of ntsc. i1 happens at the end of hsync. The driver releases hsync and feeds the colorburst data into the SPI fifo then returns. The active video interrupt i2 actually emits the pixels and uses about 70% of the cpu.
Scope
Much as I love this CPU there were a few wrinkles. At this clockspeed, it needs 3 wait states to access flash. If you execute code from flash on this part you can never be sure when those wait states will slow you down: the same code may run at different speeds depending on its position in flash. Really bad if you are writing a blit loop that has really tight timing requirements like generating ntsc in software. The solution was to copy the critical routines to RAM where they run without any wait states.

Other devices like the Cortex M3 based LPC13XX and the LPC17XX have flash accelerators and single clock gpio writes. The LPC17XX also has DMA that makes all this sort of thing really easy - 640x480 component video should be possible. Although more expensive than the M0 parts, they are still ridiculously cheap.

About the demo video

Tile
Scrolling around a 8192x2048 map of a certain hedgehogs homeworld. The demo uses the analog joystick as input, features single pixel horizontal and vertical smooth scrolling and runs at at 60fps. The audio in the background (the music, not the leafblower) is coming from the device.

Particle
500 particles spraying at random from two sources over an animated background. The texture in the back is being generated every line by multiplying the luminance of a blob pattern by sin(y). Single cycle multiplies take a lot of getting used to; it is often faster to multiply than to use shift/add "optimizations". 60fps.

3D
Platonic solids float over an animated 3D plane with weird patterns in the sky that gratuitously change color. The 3D models are rendered scanline by scanline and composited with the dynamically generated backgound. Once again, because we don't have a frame buffer, we get 60fps with no tearing.
How to build

If you want to make your own I have included the schematic and the code. I built the prototype on a LPCXpresso devkit available at Digikey, you will need to replace the stock 12mhz with a very common 14.318mhz crystal.  I bought a reel of these so if you can't find one I will send you one. The analog joystick is a replacement part from a PSP. $1ish on ebay. The wiring photos are a little tricky to follow, check the schematics for a clearer version.
Protolayout
Protolayout2
Rbox1v0schematic
Source for the LPCXpresso/Eclipse project is posted on https://sourceforge.net/projects/rbox/

I will be doing a PCB version so for those squeamish about little green wires can hang on 'till then.

until next time,
Rossum.

 

Wikipedia Homebrew device features Cortex M0 processor, all human knowledge.

Gotta love Wikipedia. Gotta love really cheap, powerful Microcontrollers. They are even more delightful when combined.

This is a prototype of a cheap offline wikipedia reader based on a new NXP ARM Cortex M0 microcontroller. It renders offline dumps of Wikipedia or other text formats (books, html etc) with a simple touch interface. The dumps are stored on a microSD card and are rendered on a inexpensive touchscreen LCD. I will publish full schematics, PCB layout and source code to a final handheld version that looks an awful lot like the Microtouch.

The Software

An offline grinder tool converts xml dumps from wikipedia and other sources into a compressed text layout format that is digestible on a small device. The hard part is decompressing and drawing the text with few cycles and very little RAM fast enough for it to feel like a responsive little consumer electronics device rather than a lumbering PC. The keys to this turned out to be a spatial index that allowed fast rendering of segments of a page and hugely simplified compression. The text renderer uses subpixel positioning to help make teeny fonts readable without slowing down drawing.

The Hardware

NXP are onto something good with these ARM Cortex microcontrollers. The are cheap in onesies (<$2), fast (50Mhz), have plenty of memory (32K flash, 8K sram) and have a really nice dev kit (LPCXpresso) with Eclipse based tools and delightful Serial Wire Debug. Hardware breakpoints. 12K gates. Bloody amazing.

This project uses the LPC1114 Cortex M0 but the PCB will also take a LPC13XX Cortex M3 part that is faster (72Mhz) and has full speed usb. The prototype uses a LPCXpresso kit with lots 'o jumpers and a ILI9325 based LCD, the same as the Microtouch.

What about the AVR?

As it turns out, this also runs just fine on the AVR based Microtouch classic hardware. It isn't quite as zippy but still works well. The code isn't really optimized yet and there is probably room for improvement on both platfotms. You might expect the Cortex M0 version running at 48Mhz to be 4 times as fast. It isn't. The M0 always requires 2 clocks to read or write GPIO (unlike a single clock for the AVR) so the LCD blit loops are at best twice as fast. Code size is about the same as one might expect.

For those of you who have built your own Microtouch device I will make sure the classic hardware is fully supported. For those of you who have not built their own Microtouch yet I hear that there might be a kit in the works. Watch this space.

Until next time,

(download)

Update

Code and schematics posted at http://www.lpc1100challenge.com/detail/316