AN-00124 Serial Arduino Touch Detection

 

Description This Application Note explores the possibilities provided by the Serial environment in Workshop for a 4D display module to work with an Arduino host. In this example, the host is an Arduino Uno board. The host can also be an Arduino Mega 2560 or Due. Ideally, the application described in this document should work with any Arduino board that supports software serial or with at least one UART serial port.
Supported Processor PICASO, DIABLO16
Supported Environment Serial
Difficulty

Medium

 

File Downloads
Files

Application Overview

This application note discusses the commands available for touch detection:

  • Touch Detect Region
  • Touch Set
  • Touch Get

Setup Procedure

The display must be configured as a slave device first before it can be controlled by a host. For instructions on how to launch Workshop 4, how to connect the display module to the PC, and how to configure the display as a slave device, kindly refer to the section “Setup Procedure” of any of the application notes below. Choose according to your display module’s processor.

Serial Goldelox Getting Started - The SPE Application

Serial Picaso Getting Started - The SPE Application

Serial Diablo16 Getting Started - The SPE Application

These application notes also introduce the user to the Serial Protocol thru the use of the Serial Commander.

 

Program the Arduino Host

A thorough understanding of the application note Serial Connection to an Arduino Host is required before attempting to proceed further beyond this point. Serial Connection to an Arduino Host provides all the basic information that a user needs to be able to get started with the Serial Environment and Arduino. The following is a list of the topics discussed in Serial Connection to an Arduino Host.

  • How to download and install the Serial-Arduino library (choose a library according to your display module’s processor)
  • How to modify the library for Arduino Due (due to a Due bug reported by a forum user)
  • How to define the serial port to be used for talking to the display
  • How to set the baud rate
  • The Error Handling Routine
  • How to set the Timeout Limit
  • How to reset the Arduino Host and the Display
  • How to let the Display Start Up
  • How to set the Screen Orientation
  • How to Clear the Screen
  • The uSD Card Mount Routine
  • How to enable message logging to the Serial Monitor of the Arduino IDE

 

Discussion of any of these topics is avoided in other Serial-Arduino application notes unless necessary. Users are encouraged to read Serial Connection to an Arduino Host first.

 

Main Loop

Touch Detect Region, Touch Set, and Touch Get

 

The Touch Detect Region specifies a new touch detect region on the screen. This setting will filter out any touch activity outside the region and only touch activity within that region will be reported by the status poll “Touch Get” command. The variable ‘touch’ stores various touch screen parameters to caller, based on the touch detect region on the screen set by the “Touch Detect Region” command.

 

The function

touch_DetectRegion (x1, y1, x2, y2)

requires four parameters. The x1 parameter specifies the horizontal position of the top left corner of the region. The y1 parameter specifies the vertical position of the top left corner of the region. The x2 parameter specifies the horizontal position of the bottom right corner of the region. The y2 parameter specifies the vertical position of the bottom right corner of the region.

 

The function

touch_Get (mode)

requires one parameter. The mode 0 or TOUCH_STATUS returns the various states of the touch screen. The values are 0 if INVALID/NOTOUCH, 1 if PRESS, 2 if RELEASE, and 3 if MOVING. The TOUCH_GETX or mode 1 returns the X coordinates of the touch reported by mode 0. The mode 2 or TOUCH_GETY returns the Y coordinates of the touch reported by mode 0.

 

The function

touch_Set(mode)

requires one parameter. The mode 0 or TOUCH_ENABLE enables and initialises Touch Screen hardware. The mode 1 or TOUCH_DISABLE disables Touch Screen. The mode 2 or TOUCH_REGIONDEFAULT will reset the current active region to default which is the full screen area.

 

Moving

 

After the variable ‘touch’ receives the touch status, it can be determined if it is moving by comparing it to TOUCH_MOVING or 3. Then to get the current x and y coordinates where the screen is touched, the touch_Get(TOUCH_GETX) and touch_Get(TOUCH_GETY) returns the x and y coordinates respectively.

Output:

Pressed

 

After the variable ‘touch’ receives the touch status, it can be determined if it is pressed by comparing it to TOUCH_PRESSED or 1. Then to get the x and y coordinates where the screen is touched, the touch_Get(TOUCH_GETX) and touch_Get(TOUCH_GETY) returns the x and y coordinates respectively.

 

Output:

 

Released

 

After the variable ‘touch’ receives the touch status, it can be determined if it is released by comparing it to TOUCH_RELEASED or 2.

Output:

 

Not Pressed

 

After the variable ‘touch’ receives the touch status, it can be determined if it is not pressed by comparing it to NOTOUCH or 0.

 

 

Connect the 4D Display Module to the Arduino Host

Refer to the section “Connect the Display Module to the Arduino Host” of the application note Serial Connection to an Arduino Host for the following topics:

  • Using the New 4D Arduino Adaptor Shield (Rev 2.00)
    • Definition of Jumpers and Headers
    • Default Jumper Settings
    • Change the Arduino Host Serial Port
    • Power the Arduino Host and the Display Separately
  • Using the Old 4D Arduino Adaptor Shield (Rev 1)

Connection Using Jumper Wires

Share: