TE35 touch problem on EMX module

Hi,
I have a T35 display module connected to EMX. Everything is working except touch. I can show images on the display with the right X,Y positions…etc. But the touch event gives wrong Y values. Around 120 more then actual value.
I tried with the Example 1: Non-Gadgeteer Test Code
and C:\Users\deniz\Documents\Microsoft .NET Micro Framework 4.2\Samples\TouchCalibration example aswell.
Can it be pin or hardware problem on the TE35?

Any suggestions?
Thanks

I have the same problem with the glide examples aswell.
How can I solve this issue? How can I calibrate?
running 4.2 sdk.
Need help please.

What happens when using the calibration example?

@ denizalp -

Brett posted this sometime back

See:
C:\Users<YourUserName>\Documents\Microsoft .NET Micro Framework 4.1\Samples\TouchCalibration

or NET Micro Framework 4.2

Hi,
Nothing happens at the end of calibration, keeps asking for a new point to touch.

Unfortunately, we don’t have a great example for screen calibration and there is the issue a to whether values are retained across application reboots. Although calibration for the current running application boils down to a call to

Microsoft.SPOT.Touch.Touch.ActiveTouchPanel.SetCalibration()

The Microsoft example involves GPIO button input processing which is probably over-the-head of many just getting starting on Gadgeteering. It also makes no attempts to make the values persistent, so to take advantage of the code, you would need to extract the portion (mostly program.cs) that does calibration and have it run as part of your applications start-up everytime.

The Glide example makes an attempt to save the configuration values in EWR (flash ram http://www.ghielectronics.com/community/forum/topic?id=916&page=1 ) on boards that support it (EMX based boards do). But for those retained values to be used either you stick with Glide, or you extract the code from Glide that attempts to read the values from EWR and use them in the SetCalibration call. The EWR code is in the Glide library in the file GlideTouch.cs.

Neither program uses GHI drivers to access the LCD you are using, this means that if your mainbooard is configured for a different LCD chances are neither example will work until you first reconfigure LCD parameters. The easiest way to do that is with a small gadgeteer example with just the display & the board that does hello world and exits as this will cause the drivers to reconfigure the parameters (the example code in https://www.ghielectronics.com/docs/133/display-t35-module#1298 shows setting parameters without the drivers).

I’ve taken all the GPIO button triggers out of the Microsoft Sample C:\Users\GHI\Documents\Microsoft .NET Micro Framework 4.2\Samples/TouchCalibration. This version uses a swipe of the screen as the trigger to do calibration. You would want to modify it to use some sort of trigger that suits your code.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation.  All rights reserved.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;

namespace TouchCalibrationSample
{
    /// <summary>
    /// Touch calibration demo for touch panel.
    /// </summary>
    public class MyTouchCalibration : Microsoft.SPOT.Application
    {
        /// <summary>
        /// The main window class, based on the standard Window class.
        /// </summary>
        public class MyWindow : Window
        {
            Microsoft.SPOT.Presentation.Media.SolidColorBrush brush =
                new Microsoft.SPOT.Presentation.Media.SolidColorBrush(
                    Microsoft.SPOT.Presentation.Media.Color.Black);
            Microsoft.SPOT.Presentation.Media.Pen pen =
                new Microsoft.SPOT.Presentation.Media.Pen(
                    Microsoft.SPOT.Presentation.Media.ColorUtility.ColorFromRGB(
                    255, 0, 0));
            Text text = new Text();
            Panel panel = new Panel();

            // Structure to hold a point.
            struct point
            {
                public int x;
                public int y;
            }

            /// <summary>
            /// The default constructor.
            /// </summary>
            public MyWindow()
            {
                text.Font = Resources.GetFont(Resources.FontResources.small);
                text.TextContent = "Press [Select] button to start calibration";
                text.HorizontalAlignment =
                    Microsoft.SPOT.Presentation.HorizontalAlignment.Center;
                text.VerticalAlignment =
                    Microsoft.SPOT.Presentation.VerticalAlignment.Center;

                // Add the text control to the window.
                this.Child = panel;
                panel.Children.Add(text);
            }

            int centerx = 0;
            int centery = 0;
            int r = 6;

            /// <summary>
            /// Handles the touch down event.
            /// </summary>
            /// <param name="e"></param>

            protected override void OnTouchDown(TouchEventArgs e)
            {
                base.OnTouchDown(e);

                int x;
                int y;

                e.GetPosition((UIElement)this, 0, out x, out y);


                // If we are in calibrating mode...
                ++currentCalPoint;
                if (calibrating)
                {
                    // Cycle through all of the calibration points.
                    int index = currentCalPoint - 1;

                    cx[index] = (short)x;
                    cy[index] = (short)y;

                    text.TextContent = "{("                    +
                        sx[index].ToString() + "," +
                        sy[index].ToString() + ")=(" +
                        cx[index].ToString() + "," +
                        cy[index].ToString() + ")}";
                        
                    if (currentCalPoint == calPoints.Length)
                    {
                        // The last point has been reached , so set the 
                        // calibration.
                        Microsoft.SPOT.Touch.Touch.ActiveTouchPanel.SetCalibration(
                            calPoints.Length,
                            sx,
                            sy,
                            cx,
                            cy);

                        // Show the calibration points.
                        int i = 0;
                        string str = "";
                        for (i = 0; i < calPoints.Length; i++)
                        {
                            str += i.ToString() + "=" + cx[i].ToString() + "," + cy[i].ToString() + " ";
                        }
                        text.TextContent = str;

                        calibrating = false;
                    }
                }
                else
                {
                    // We are not calibrating, so just show the point.
                    r = 10;
                    centerx = x;
                    centery = y;

                    text.TextContent = x.ToString() + "," + y.ToString();
                }

                Invalidate();
            }

            /// <summary>
            /// Handles the touch up event.
            /// </summary>
            /// <param name="e"></param>

            protected override void OnTouchUp(TouchEventArgs e)
            {
                base.OnTouchUp(e);

                int x;
                int y;

                e.GetPosition((UIElement)this, 0, out x, out y);

                r = 6;

                text.TextContent = x.ToString() + "," + y.ToString();

                Invalidate();
            }

            /// <summary>
            /// Handles the touch move event.
            /// </summary>
            /// <param name="e"></param>
            private Boolean doCal = true;
            protected override void OnTouchMove(TouchEventArgs e)
            {
                if (doCal)
                {
                    CalibrateScreen();
                    doCal = false;
                }
            }

            point[] calPoints = null;
            int currentCalPoint = 0;
            short[] sx = null;
            short[] sy = null;
            short[] cx = null;
            short[] cy = null;
            bool calibrating = false;

            /// <summary>
            /// Helper function to calibration the screen.
            /// </summary>
            public void CalibrateScreen()
            {
                // If we are already calibrating, don't start calibration again.
                if (!calibrating)
                {
                    text.TextContent = "                                                                     ";

                    calibrating = true;

                    // Ask the touch system how many points are needed to 
                    // calibrate.
                    int calibrationPointCount = 0;
                    Microsoft.SPOT.Touch.Touch.ActiveTouchPanel.GetCalibrationPointCount(
                        ref calibrationPointCount);

                    // Create the calibration point array.
                    calPoints = new point[calibrationPointCount];
                    sx = new short[calibrationPointCount];
                    sy = new short[calibrationPointCount];
                    cx = new short[calibrationPointCount];
                    cy = new short[calibrationPointCount];

                    int i = 0;
                    int x = 0;
                    int y = 0;

                    // Get the points for calibration.
                    for (i = 0; i < calibrationPointCount; i++)
                    {
                        Microsoft.SPOT.Touch.Touch.ActiveTouchPanel.GetCalibrationPoint(
                            i, ref x, ref y);
                        calPoints[i].x = x;
                        calPoints[i].y = y;

                        sx[i] = (short)x;
                        sy[i] = (short)y;
                    }

                    // Start the calibration process.
                    currentCalPoint = 0;
                    Microsoft.SPOT.Touch.Touch.ActiveTouchPanel.StartCalibration();

                    Invalidate();
                }
            }

            /// <summary>
            /// Handles the render event.
            /// </summary>
            /// <param name="dc"></param>
            public override void OnRender(
                Microsoft.SPOT.Presentation.Media.DrawingContext dc)
            {
                base.OnRender(dc);

                if (calibrating)
                {
                    DrawCrossHair(dc, calPoints[currentCalPoint].x,
                        calPoints[currentCalPoint].y);
                }
                else
                {
                    dc.DrawEllipse(brush, pen, centerx, centery, r, r);
                }
            }

            /// <summary>
            /// Helper function to draw a crosshair.
            /// </summary>
            /// <param name="dc"></param>
            /// <param name="x"></param>
            /// <param name="y"></param>
            private void DrawCrossHair(
                Microsoft.SPOT.Presentation.Media.DrawingContext dc, int x,
                int y)
            {
                dc.DrawLine(pen, x - 10, y, x - 2, y);
                dc.DrawLine(pen, x + 10, y, x + 2, y);

                dc.DrawLine(pen, x, y - 10, x, y - 2);
                dc.DrawLine(pen, x, y + 10, x, y + 2);
            }

        }

        static MyTouchCalibration myApplication;


        /// <summary>
        /// Execution entry point.
        /// </summary>
        public static void Main()
        {
            myApplication = new MyTouchCalibration();

            // Touch notifications are not turned on by default.  You need to 
            // explicitly inform the Touch engine that you want touch events to 
            // be pumped to your direction, and you want to work with the rest 
            // of the architecture.

            Microsoft.SPOT.Touch.Touch.Initialize(myApplication);

            Window mainWindow = myApplication.CreateWindow();

 
            // Start the application.
            myApplication.Run(mainWindow);
       
            
        }

 
        private MyWindow mainWindow;

        /// <summary>
        /// Creates a window that has button focus.
        /// </summary>
        /// <returns></returns>
        public Window CreateWindow()
        {
            // Create a window object and set its size to the size of the 
            // display.
            mainWindow = new MyWindow();
            mainWindow.Height = SystemMetrics.ScreenHeight;
            mainWindow.Width = SystemMetrics.ScreenWidth;

            //// Connect the button handler to all of the buttons.
            mainWindow.AddHandler(Buttons.ButtonUpEvent,
                new RoutedEventHandler(OnButtonUp), false);

            // Set the window visibility to Visible.
            mainWindow.Visibility = Visibility.Visible;

            // Attach the button focus to the window.
            Buttons.Focus(mainWindow);

            return mainWindow;
        }

        /// <summary>
        /// Handles a button click.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnButtonUp(object sender, RoutedEventArgs evt)
        {
            ButtonEventArgs e = (ButtonEventArgs)evt;
            
            // Any button will start the calibration process.
            mainWindow.CalibrateScreen();

            // Print the button code to the Visual Studio output window.
            Debug.Print(e.Button.ToString());
        }
    }
}

I just used @ andre.m 's codeshare on a t43 and spider and it work great

Thanks for the replies.
I managed to calibrate succesfully.
I am having difficulties to add it to my main code.
Touch.ActiveTouchPanel.SetCalibration(5, sx, sy, cx, cy); raising execption.
So I added the code Microsoft.SPOT.Touch.Touch.Initialize( );
But what parameter shall I pass?


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Microsoft.SPOT.Input;

namespace GadgeteerApp2
{
    public partial class Program
    {
        private DispatcherTimer tmrIdleTimer;
        private Window window;
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
                 short[] sx = null;
            short[] sy = null;
            short[] cx = null;
            short[] cy = null;
            sx = new short[5];
            sy = new short[5];
            cx = new short[5];
            cy = new short[5];
            sx[0] = (short)160;
            sx[1] = (short)32;
            sx[2] = (short)32;
            sx[3] = (short)288;
            sx[4] = (short)288;

            sy[0] = (short)120;
            sy[1] = (short)24;
            sy[2] = (short)216;
            sy[3] = (short)216;
            sy[4] = (short)24;

            cx[0] = (short)464;
            cx[1] = (short)185;
            cx[2] = (short)177;
            cx[3] = (short)761;
            cx[4] = (short)773;

            cy[0] = (short)673;
            cy[1] = (short)476;
            cy[2] = (short)828;
            cy[3] = (short)837;
            cy[4] = (short)533;
      
            window = display_TE35.WPFWindow;
              Microsoft.SPOT.Touch.Touch.Initialize( );
            Touch.ActiveTouchPanel.SetCalibration(5, sx, sy, cx, cy);

            
            window.Background = new SolidColorBrush(GT.Color.White);
            window.Child = WindowsManager.StartupScreen;
           
            tmrIdleTimer = new DispatcherTimer();
            
            tmrIdleTimer.Tick += new EventHandler(tmrIdleTimer_Tick);
            tmrIdleTimer.Start();
        }
        void tmrIdleTimer_Tick(object sender, EventArgs e)
        { tmrIdleTimer.Stop();
           System.Threading.Thread.Sleep(5000);
          window.Child = WindowsManager.MainWindow;
          WindowsManager.MainWindow.TouchDown +=
                     new TouchEventHandler(MainWindow_TouchDown);
           
        }

      

        void MainWindow_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        { 
            
        }
    }
}






//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.1008
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace GadgeteerApp2 {
    using Gadgeteer;
    using GTM = Gadgeteer.Modules;
    
    
    public partial class Program : Gadgeteer.Program {
        
        private Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClient;
        
        private Gadgeteer.Modules.GHIElectronics.Display_TE35 display_TE35;
        
        public static void Main() {
            // Important to initialize the Mainboard first
            Program.Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
            Program p = new Program();
            p.InitializeModules();
           
            p.ProgramStarted();
         
            // Starts Dispatcher
            p.Run();
        }
        
        private void InitializeModules() {
            this.usbClient = new GTM.GHIElectronics.UsbClientDP(1);
            this.display_TE35 = new GTM.GHIElectronics.Display_TE35(14, 13, 12, 10);
        }
    }
}



/* Copyright 2012 Marco Minerva, marco.minerva@ gmail.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.Runtime.CompilerServices;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation;
using GadgeteerApp2.Extensions;
using GT = Gadgeteer;
using Microsoft.SPOT.Input;


namespace GadgeteerApp2.Windows
{
    public class MainWindow : BaseWindow
    {
        private Text txtIPAddress;
        private Text txtTime;

        private DispatcherTimer tmrUpdate;

        public  Canvas canvasMenu;
        private Canvas temperatureHumidityCanvas;
        private Canvas switchesCanvas;
        private Image cameraImage;

        private Text txtTemperature;
        private Text txtHumidity;

        private Image imgSwitch1;
        private Image imgSwitch2;
        private Image imgSwitch3;
        private Image imgSwitch4;

        private static Bitmap OnBitmap = Resources.GetBitmap(Resources.BitmapResources.On);
        private static Bitmap OffBitmap = Resources.GetBitmap(Resources.BitmapResources.Off);

        public MainWindow()
        {
            AddTitleBar("Thuraya ", FontManager.NinaB,
                GT.Color.White, GT.Color.Blue, GT.Color.White);

            var statusCanvas = new Canvas();
            txtIPAddress = new Text()
            {
                Font = FontManager.NinaB,
                TextContent = "Teknomobil Uydu Haberlesme AS. " 
            };
            statusCanvas.Children.Add(txtIPAddress);

            txtTime = new Text()
            {
                Font = FontManager.NinaB,
                Width = 310,
                TextAlignment = TextAlignment.Right,
               
            };
            statusCanvas.Children.Add(txtTime);

            this.AddStatusBar(statusCanvas, GT.Color.Gray);

            // Creates menu item icons.
            canvasMenu = new Canvas() { Height = 240, Width = 320 };

  this.CreateMenuItem(Resources.GetBitmap(Resources.BitmapResources.address_book_icon ),
                new TouchEventHandler(rehber1_TouchDown),25,
                "Rehber", 0,0);

            this.CreateMenuItem(Resources.GetBitmap(Resources.BitmapResources.call ),
                new TouchEventHandler(arama1_TouchDown), 120,
                "Arama", 80,0);

          
 this.CreateMenuItem(Resources.GetBitmap(Resources.BitmapResources.Temp_Humidity_Menu),
              new TouchEventHandler( sensor_TouchDown), 25,
              "Sicaklik/Nem", 0,100);

           
           // this.AddChild(canvasMenu, 30, 0);
          
            this.CreateMenuItem(Resources.GetBitmap(Resources.BitmapResources.sms ),
               new TouchEventHandler( sms_TouchDown), 220,
               "SMS", 190,0);

           
            this.AddChild(canvasMenu, 30, 0);
            // Creates panels.
            this.CreateTemperatureHumidityPanel();



            //tmrUpdate = new DispatcherTimer();
            //tmrUpdate.Tick += new EventHandler(tmrUpdate_Tick);
            //tmrUpdate.Interval = TimeSpan.FromTicks(500 * TimeSpan.TicksPerMillisecond);
            //tmrUpdate.Start();
        }

        private void CreateMenuItem(Bitmap bitmap, TouchEventHandler handler,
            int iconMarginLeft, string labelContent, int labelMarginLeft,int top)
        {
            var image = new Image(bitmap);
            image.TouchDown += handler;
            canvasMenu.Children.Add(image, top , iconMarginLeft);

            var label = new Text()
            {
                Font = FontManager.Arial10Bold,
                Width = 120,
                TextAlignment = TextAlignment.Center,
                TextWrap = true,
                TextContent = labelContent
            };
            label.TouchDown += handler;
            canvasMenu.Children.Add(label, top+ 54, labelMarginLeft);
        }

        private void CreateTemperatureHumidityPanel()
        {
            temperatureHumidityCanvas = new Canvas() { Height = 240, Width = 320 };
            CreateBackButton(temperatureHumidityCanvas,
                "Geri",
                new TouchEventHandler(geri_TouchDown));

            var imgTemperature =
                new Image(Resources.GetBitmap(Resources.BitmapResources.Temperature  ));
            txtTemperature = new Text() { Font = FontManager.Arial16Bold };
            temperatureHumidityCanvas.Children.Add(imgTemperature, 63, 20);
            temperatureHumidityCanvas.Children.Add(txtTemperature, 83, 80);

            var imgHumidity =
                new Image(Resources.GetBitmap(Resources.BitmapResources.Humidity));
            txtHumidity = new Text() { Font = FontManager.Arial16Bold };
            temperatureHumidityCanvas.Children.Add(imgHumidity, 70, 200);
            temperatureHumidityCanvas.Children.Add(txtHumidity, 83, 255);

            temperatureHumidityCanvas.Visibility = Visibility.Collapsed;
            this.AddChild(temperatureHumidityCanvas, 30, 0);
        }

       

       
        

        
       

       

        private void CreateBackButton(Canvas canvas, string labelContent,
            TouchEventHandler handler)
        {
            StackPanel panel = new StackPanel(Orientation.Horizontal);
            var image = new Image(Resources.GetBitmap(Resources.BitmapResources.Back));
            image.TouchDown += handler;
            image.SetMargin(5, 3, 0, 0);
            panel.Children.Add(image);

            var label = new Text()
            {
                Font = FontManager.Arial14Bold,
                TextContent = labelContent
            };
            label.SetMargin(10, 8, 0, 0);
            panel.Children.Add(label);

            canvas.Children.Add(panel);
        }

        void TemperatureHumidity_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            temperatureHumidityCanvas.Visibility = Visibility.Visible;
            canvasMenu.Visibility = Visibility.Hidden;
        }


        void arama1_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            temperatureHumidityCanvas.Visibility = Visibility.Visible;
            canvasMenu.Visibility = Visibility.Hidden;
        }
        void rehber1_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            temperatureHumidityCanvas.Visibility = Visibility.Visible;
            canvasMenu.Visibility = Visibility.Hidden;
        }
        void sms_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            temperatureHumidityCanvas.Visibility = Visibility.Visible;
            canvasMenu.Visibility = Visibility.Hidden;
        }
        void sensor_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
        {
            temperatureHumidityCanvas.Visibility = Visibility.Visible;
            canvasMenu.Visibility = Visibility.Hidden;
        }


        void geri_TouchDown(object sender, TouchEventArgs e)
        {
            canvasMenu.Visibility = Visibility.Visible;
            temperatureHumidityCanvas.Visibility = Visibility.Collapsed;
        }

        void tmrUpdate_Tick(object sender, EventArgs e)
        {
           
        }

       
    }
}


Thanks a lot . its solved.
I am ready to order 20 more TE35 and EMX.