Jump to: navigation, search
Raspberry Pi with the MZTX-PI-EXT touchscreen.

The MZTX-PI-EXT board (also known as Tontec) is an add-on board with a 2.4 inch 240x320 tft color touchscreen with extention hooks.


A user process (mztx06a) watches changes in the frame buffer and sends them through the SPI bus to the screen. The refresh rate is not intended to display video but is correct for classical GUI. The source code is available on Github[2] with some forks[3] and in various archive files[4]. The version described in the blog works; it seems that the original Github is different and does not work[5]. The original version spent a lot of time in the while(1) loop of loadFrameBuffer_diff_320(); theimmc proposed the introduction of µsleeps in the loop[6]. Other optimisations are possible.


The 'touch' part is handled by a TSC2003[8] chip on the I2C bus and uses the J1-Pin7 (GPIO-04) for the /PenIRQ signal. Two kernel modules are required : tsc2007.ko (compatible TSC2003) and (a modified) tsc_raspi.ko[9]. Pull-up can be setup with WiringPi's gpio(1) command[10].

Two/three changes are needed to the original tsc_raspi.c :

  • i2c_get_adapter(1); /* '1' in place of '0' : the I2C bus on the J1 connector is the second one */
  • gpio_request_one(tsc2007_penirq_pin, GPIOF_IN, "PENIRQ"); /* without '| GPIOF_OUT_INIT_HIGH'; the pin is 'IN' with a pull-up */
  • tsc2007_penirq_pin = 4; /* J1-Pin7 is GPIO-04; this can also be specified while insmod'ing */

To enable the driver,

  • $ sudo insmod tsc_raspi penirq_pin=4
  • $ sudo gpio mode 7 up

Tests, Calibration and orientation

To test the touchscreen, commands like evtest (tests the Linux input driver mechanism) and xev (test the touchscreen in the 'X' environment) are usefull. xinput-calibrator could be used to calibrate the touchscreen but the result does not seem correct when used with an TransformationMatrix option in /etc/X11/xorg.conf.d/99-calibration.conf.
Mine looks like

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "TSC2007 Touchscreen"
        Option  "Calibration"   "0 4000 0 4000"
        Option  "TransformationMatrix" "0 -1 1 -1 0 1 0 0 1"

The 'handmade' quick and dirty 'calibration' is not perfect but usable in the center of the screen (xinput-calibrator makes things worse; I'll have to make it by hand, checking left/righ top/bottom and deduce some linear combination. The 'TransformationMattrix' is for the original mztx06 code (like a 'TV set' with the connectors below and on the left).

Simple GUI

Simple GUI to start/stop dump1090[11] to capture ADS-B[12] messages on a battery powered Rpi[13].

The simplest way (on Raspbian) to get some interaction is to launch a tcl/tk script at startup by adding a line to /etc/xdg/lxsession/LXDE/autostart . Something like :

@wish /home/pi/menu.tcl

with menu.tcl being a simple applet with a couple of buttons to launch some simple shell scripts :

# the next line restarts using wish \
exec wish "$0" ${1+"$@"}

button .quit -text "Quit!" -command { exit }
button .rec -text "Record" -command { exec /home/pi/ & }
button .stop -text "Stop" -command { exec /home/pi/ & }
button .shutdown -text "Shutdown" -command { exec /home/pi/ & }

pack .rec .stop .quit .shutdown

The shell scripts contain lines like ' '/home/pi/bin/dump1090 > dump1090.`/usr/local/bin/now`' (now is 'date "+%g%m%d.%H%M%S"' to give a time stamped suffix to the file); 'pkill dump1090' and 'sudo shutdown -h now'.


The board uses the J1 'GPIO' connector but offers header pins for extensions[14] :

  • An alternate power 5 volts connector (unprotected like the Pi's micro-USB one : 5 volts no more - no less[15])
  • UART (from J1)
  • SPI bus (from J1)
  • I2C bus (from J1)
  • LP3943, '16-LED Fun Light Driver'


  • It is probably easier to write a 'user mode driver' like : one reads the tsc2003's xy(z) through i2c functions and writes 'events' in /dev/uinput (you won't need to care about kernel updates). And it is probably better to emulate a touchpad with relative events as pin-pointing small controls on a resistive tablet is not easy.

Notes and references

  1. Setup Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display Monitor For Raspberry Pi blog
  5. and the following posts
  7. Tontec 2.4-inch TFT LCD forum
  13. fr :
  14. Schematic :
  15. Some kind of small voltage regulating device should be used (check it delivers 5 volts!; don't kill your RPi).