Hi,
I’m working on GUI project using Hydra and CP7. It has become pretty big project and looks really nice with this display. Now I have to add monitoring of data sent by Arduino board connected to serial port (COM1). Arduino sends 174 bytes each second.
After adding the serial port reading I have a problem with CP7 touch starting to read invalid X/Y coordinates at some point and becoming unusable.
The project is big, but I managed to reproduce with simple example. Here is zip or check the code below:
https://drive.google.com/file/d/0B1zHz__652kNaW1ORXlrMXVkb3c/edit?usp=sharing
It’s easy to reproduce by holding finger on the LCD for 1-2s, then releasing and holding on different spot, repeating this several times. Or just touch fast many times.
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.Presentation.Shapes;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using System.IO.Ports;
namespace CP7_UART_Test
{
public partial class Program
{
SerialPort uart;
Thread uartReceiveThread;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
display_CP7.ScreenPressed += new Display_CP7.TouchEventHandler(display_CP7_ScreenPressed);
display_CP7.ScreenReleased += new Display_CP7.TouchEventHandlerTouchReleased(display_CP7_ScreenReleased);
uart = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.One);
uart.Open();
uartReceiveThread = new Thread(new ThreadStart(UartReceiveThreadMethod));
uartReceiveThread.Start();
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
}
void display_CP7_ScreenReleased(Display_CP7 sender)
{
Debug.Print("Screen released");
}
void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
{
Debug.Print("Screen pressed, num points: " + touchStatus.numTouches + ", x: " + touchStatus.touchPos[0].xPos + ", y: " + touchStatus.touchPos[0].yPos);
}
void UartReceiveThreadMethod()
{
while (true)
{
while (uart.BytesToRead == 0)
Thread.Sleep(10);
Debug.Print("Serial port bytes: " + uart.BytesToRead);
while (uart.BytesToRead > 0)
uart.ReadByte();
}
}
}
}
Check also the log from VS Output window:
https://drive.google.com/file/d/0B1zHz__652kNekFXdF94a3NtdVk/edit?usp=sharing
See lines after 341.
[quote]Screen pressed, num points: 1, x: 129, y: 2560
Screen released
Screen released
Serial port bytes: 174
Screen released
…
Screen released
Screen pressed, num points: 1, x: 65, y: 3328
Screen pressed, num points: 7, x: 65, y: 3328
Screen pressed, num points: 15, x: 65, y: 3328
Screen pressed, num points: 15, x: 65, y: 3328
Screen pressed, num points: 15, x: 65, y: 3328
Screen released[/quote]
After the problem happens I start to get a lot of screen released events while holding finger on the LCD (instead of screen pressed event). I very rarely get screen pressed event anymore and if I do get it, then it’s with wrong coordinates and many touch points.
In the full project I tried several things. Like reading from serial port using event, but it made touch unresponsive and also I often get “Buffer OverFLW” message in upper left screen corner in this case. I tried opening, reading and closing the com port when I expect data - still breaks touch. Tried adding and removing the screenPressed/Released event handlers dynamically (with += and -=) - didn’t help. It happens even if I just discard the incoming data with uart.DiscardInBuffer() instead of reading it.
Maybe a clue - when problem happens project restart from inside Visual Studio does not fix it (with CTRL+SHIFT+F5).
Hydra is with Ethernet firmware v4.2.6.1 and TinyBooter v4.2.6.1.
Tried to power it from PC usb and from usb power adapter 5v/1A.
Please, how can I avoid this problem? Any idea is appreciated.
edit:
- it happens also with uart baudrate of 9600.
- tested with arduino sending only 9-10 bytes per second - still happens.
- no problem if Arduino does not send any data (without change to Hydra side code).