Feb 27 2013
ARDUINO PROJECT: TOUCH screen LCD
see herefor the first steps of a power monitor,
now looking for a local operation / visualisation for a power monitoring / emon version
i buy a arduino mega 2560 ( china copy ), arduino mega shield
and a 3.2" TFT LCD screen from ThaiDuino,all for 1923THB / 48EURO.
ITDB02-3.2WD module is 3.2" TFT LCD with 65K color 400 x 240 resolutions (16:9 widescreen). The controller of this LCD module is HX8352-A, it supports 16bit data interface with 4 wires control interface. Moreover, this module includes the touch screen and SD card socket.
ITDB02-3.2WD is supported by UTFT Library.
because it use much of the I/O of a arduino UNO i use a arduino MEGA
and i plan only to use a ( hardware ) serial link to create a serial touch-graphic terminal.

testing the example UTFT_Demo_400x240 (C)2012 Henning Karlsen
1 change for use with mega required,

GOOD SHOW
now first get newest version of the lib at henningkarlsen and found UTOUCH
I test the touchscreen with
UTouch_ButtonTest.pde / UTouch_Calibration.pde and use:
UTFT myGLCD(ITDB32WC, 38,39,40,41); ( so its a different display as i was thinking )
UTouch myTouch(6,5,4,3,2);
and here i got some issues, the right 1cm wide area can not read by touch,
and right and left seems switched.
after 3 step of calibration / examples UTouch_Calibration.pde
and change arduino-1.0.3\libraries\UTouch\UTouchCD.h
display and touch area seems to fit, but
as you see in above picture, there still is on the left side a about 7mm inactive area.
thanks to Henning Karlsen for help me out here, now i can start to work.
- first i use my updated (USB) menu program
- include the button touch LCD program modified for input int and real numbers
- include a qwerty keyboard ( can only be used with stylus )
- start with layout and menu structure of main LCD screen
- include event structure for string input from hardware serial T1
what later will be other mega with power monitoring tools
- - still have small problems with touch calibration
- - and a text / back ground color problem.
in the examples the buttons have blue background, and the text also,
but sometimes ( even with clear screen.. ) of loading a other page,
suddenly the text background is black.
solverd: forget the ! setBackColor !
here the snapshots of
* numeric keypad,
** qwerty keyboard with shift toggle
*** main menu / intro screen




[M4] menu function is HOME
[M1] the second is T1 ( later EMON )
to show the text lines from other MEGA with EMON ( power monitoring toolbox )
with only 13 lines and 21 chars each not much space,
and also not more buffer / history programmed.
if a line from 21 to 42 chars long comes in, one wrap is possible,
if longer, the rest is lost.
that terminal part with (in)string to array conversion and pointer to arrays,
line scroll and wrap logic is tricky.
[M2] next is USB stream
here you can see what the PC is sending,
but as there is a USB menu dialog, so the first character what is send is also interpreted
by the menu selection.
testing also about memory usage of the library, esp. how far i could go with UNO,
i found a major adjustment you should try first:
in memorysaver.h you can disable all display you not use,
and the code is more easy to be loaded into UNO. ( about 10kB less ).
a major flash consumer is the FONT and print command. ( about 9kB )
but i think that is unavoidable?
after i could load the QWERTY keyboard also into the UNO ( about 25kB ),
there is not much space left for a user code.
its a pity that ( that ) TFT not have internal fonts like a LCD.
but still its a little bit like to try to use the operator panel of the washing machine
( ! mine has a fuzzy control button ! )
to fly the space shuttle.
now next i need that "partner" to connect to T1,
a modified version of POWER MONITOR TOOLBOX
my most bad example of using compiler switches.
use arduino MEGA,
+ with up to 5 current line
+ ( full wave ) EMON version
+ FFT
+ line chart tool
+ raw volt measurement
(- not operable via LCD, only from USB )
- menu
- EEprom setup and tuning
- diagnostic prints
- alarming and limit tuning
- GPRS modem with SMS ( ALARM / DATA SMS ) by software serial / tricky wiring for MEGA
after setup the EMON in a MEGA, compile current 4 lines and output of EMON to T1
connect to LCD MEGA
GND - GND
RXD1 19 - TXD1 18
TXD1 18 - RXD1 19

and show only 2 values ( Volt and Amp )

and show all values ( 2 lines ) is unreadable.

That version ( T1 / USB / HOME ) terminal function only, pls find in download area.
so, after the terminal function works its time to think about a more nice way to show the EMON values, here we will use the R1 .. R7 menu.
my power meter toolbox is setup ( by compiler switches ) to do Volt A0 and A1 ..A5 Amp
( 5 separate (one phase ) AC measurements ( with a common Volt signal ).
While in the terminal window [EMON] [T1] see the stream of all enabled lines,
with selection [A1] ... [A5] show one line values only.
For this first i need to use that stream ( series of strings ) and put it to a array of floats .
At the one_line_display i mix BIG and 7 segment Font,
what makes it tricky, because the 7 segment Font can not make a dot for the numF floating point print function, now use num I, a small o instead and an other numI.

until now was easy because it was just some different ways to show the default data stream from EMON.
For the next MENU it is required to operate the EMON device by sending characters via the T1 line, to make EMON send different kind of data like FFT or CHART.
The new M2 OSCI menu button first gives you that new right menu buttons. L for start/stop line chart.

and thats the CHART with 2 channel and 38 samples

and the first results of a FFT

with terminal now in small font and menu select colors changed.
add. i build in a menu [HOME][RST] software reset of BOTH boards.
this revision PMT V1.6Ma and LCD V2.5 pls find at download area
One more test: i need a MEGA for the LCD, ( >60kB code )
but for the EMON it should be possible to run 4 LINES, CHART and FFT ( and NO shield /ethernet/GPRS/WIFLY)
in a UNO and connect the LCD MEGA by UNO's D0,D1, GND only.
but for this the stream ( to USB ) must be formatted for LCD ( like for T1 of MEGA )
see rev 1.6b

As the LCD shield has a SD card slot i would like to test it too.
But the SD code is in the EMON PMT and need to be transferred to the LCD project.
2 years later work again with this touchscreen on a update for USB menu here