MZTX-PI-EXT
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.
Contents
Display[1]
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.
Touch[7]
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" EndSection
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
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 :
#!/bin/sh
# the next line restarts using wish \
exec wish "$0" ${1+"$@"}
button .quit -text "Quit!" -command { exit }
button .rec -text "Record" -command { exec /home/pi/rec.sh & }
button .stop -text "Stop" -command { exec /home/pi/stop.sh & }
button .shutdown -text "Shutdown" -command { exec /home/pi/shutdown.sh & }
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'.
Extensions
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'
Aftertough
- It is probably easier to write a 'user mode driver' like https://github.com/xofc/tsc2uinput : 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
- ↑ Setup Tontec 2.4-inch TFT LCD 240x320 RGB Pixels Touch Screen Display Monitor For Raspberry Pi blog
- ↑ https://github.com/yaolet/mztx06a
- ↑ https://github.com/yaolet/mztx06a/network
- ↑ https://s3.amazonaws.com/tontec/24usingmanual.zip
- ↑ http://www.raspberrypi.org/forums/viewtopic.php?p=533391#p533391 and the following posts
- ↑ http://www.raspberrypi.org/forum/viewtopic.php?p=505908#p505908
- ↑ Tontec 2.4-inch TFT LCD forum
- ↑ http://www.ti.com/lit/ds/symlink/tsc2003.pdf
- ↑ https://github.com/osandov/raspi/blob/master/tsc2007/tsc_raspi.c
- ↑ https://projects.drogon.net/raspberry-pi/wiringpi/
- ↑ http://www.satsignal.eu/raspberry-pi/dump1090.html
- ↑ https://en.wikipedia.org/wiki/Automatic_dependent_surveillance-broadcast
- ↑ fr : http://chipotons.blogspot.be/2014/04/ads-b-sur-piles.html
- ↑ Schematic : https://www.dropbox.com/s/hz2mo7cgmhxmo49/pi-mztx-ext-v10-sch.pdf
- ↑ Some kind of small voltage regulating device should be used (check it delivers 5 volts!; don't kill your RPi).