Nesso N1: touch inconsistencies

I hope this is just a mistake on my part... but...
My issues are:

// Notes:
// - text always orients correctly for all setRotation(x)
// - printed coordinates are correct to the touch-ed location for all setRotation(x)
// Issues: 
// - in setRotation(), same as setRotation(0)
// - in setRotation(0), KEY1 bottom, "left-right" and "up-down" are correct
// - in setRotation(1), KEY1 right, "left-right" registers as "top(0)-bottom(off screen 239)" and "top-bottom" registers as "right(134)-left(0)"
// - in setRotation(2), KEY1 top, "left-right" registers inversely as "right(135)-left(0)" and "top-bottom" registers inversely as "bottom(239)-top(0)"
// - in setRotation(3), KEY1 left, "left-right" registers as "bottom(off screen 239)-top(0)" and "top-bottom" registers "left-right(134)"
// - swapping coordinates by changing touch.read(x, y) to touch.read(y, x)...
// - in setRotation(0), KEY1 bottom, "left-right" registers incorrectly as "top-half(134)" and "top-bottom" registers incorrectly as "left(0)-right(off screen 239)"
// - in setRotation(1), KEY1 right, "left-right" registers correctly as "left-right" but "top-bottom" registers inversely as "bottom-top"
// - in setRotation(2), KEY1 top, "left-right" registers incorrectly as "top(0)-half-down(134)" and "top-bottom" registers as "lright(offscreen 239)-left(0)"
// - in setRotation(3), KEY1 left, "left-right" registers inversely as "right-left" BUT "top-bottom" registers correctly as "top-bottom"

My board support and libraries are this:

// BOARD: Arduino Nesso N1
// CORE: esp32 by Espressif Systems v. 3.3.6
// LIBRARY: Arduino_Nesso_N1 by Arduino v. 1.0.0

Using this Arduino copy/pasted code from here: https://docs.arduino.cc/tutorials/nesso-n1/user-manual/#handling-touch-input

// https://docs.arduino.cc/tutorials/nesso-n1/user-manual/#handling-touch-input
// BOARD: Arduino ESP32 Boards by Arduino v. 2.0.18-arduino 5
// LIBRARY: Arduino_Nesso_N1 by Arduino v. 1.0.0

// Issues: 
// - text always orients correctly for all setRotation(x)
// - in setRotation(), same as setRotation(0)
// - in setRotation(0), KEY1 bottom, "left-right" and "up-down" are correct
// - in setRotation(1), KEY1 right, "left-right" registers as "top(0)-bottom(off screen 239)" and "top-bottom" registers as "right(134)-left(0)"
// - in setRotation(2), KEY1 top, "left-right" registers inversely as "right(135)-left(0)" and "top-bottom" registers inversely as "bottom(239)-top(0)"
// - in setRotation(3), KEY1 left, "left-right" registers as "bottom(off screen 239)-top(0)" and "top-bottom" registers "left-right(134)"
// - swapping coordinates by changing touch.read(x, y) to touch.read(y, x)...
// - in setRotation(0), KEY1 bottom, "left-right" registers incorrectly as "top-half(134)" and "top-bottom" registers incorrectly as "left(0)-right(off screen 239)"
// - in setRotation(1), KEY1 right, "left-right" registers correctly as "left-right" but "top-bottom" registers inversely as "bottom-top"
// - in setRotation(2), KEY1 top, "left-right" registers incorrectly as "top(0)-half-down(134)" and "top-bottom" registers as "lright(offscreen 239)-left(0)"
// - in setRotation(3), KEY1 left, "left-right" registers inversely as "right-left" BUT "top-bottom" registers correctly as "top-bottom"

#include <Arduino_Nesso_N1.h>

NessoDisplay display;
NessoTouch touch;

void setup() {
  display.begin();
  touch.begin();
  display.setRotation(1);  // 0 = KEY1 bottom, 3 = KEY1 left
  display.fillScreen(TFT_BLACK);
  display.setTextDatum(MC_DATUM);
  display.setTextColor(TFT_WHITE);
  display.setTextSize(1);
  display.drawString("Touch the screen", display.width() / 2, display.height() / 2);
}

void loop() {
  int16_t x, y;
  if (touch.read(x, y)) {                    // Check for screen touch
    display.fillScreen(TFT_BLACK);           // Clear screen
    display.fillCircle(x, y, 5, TFT_WHITE);  // Draw circle at touch point
    String coords = "X:" + String(x) + " Y:" + String(y);
    display.drawString(coords, display.width() / 2, display.height() / 2);  // Display coordinates
  }
  delay(20); // ?
}

I tried drawing the problems, but the arrows, dots, and words became a rats nest soup. A video was even worse (gnarled knuckles).

Did ESP32 core update break again?
Did Arduino_Nesso_N1 library update break?
Did NessoTouch break?

Note: M5 and M5Unified libraries work as expected.

I will use M5 library for touch ): to continue with Nesso things.

I had the same issue on the last release of mazes when i switched to the new nesso n1 lib..

i did work it though..

try this..


void loop() {
  int16_t x, y;
   //flip x and y
  if (touch.read(y, x)) {                    // Check for screen touch
   y = (135 - y); //reverse y..
    display.fillScreen(TFT_BLACK);           // Clear screen
    display.fillCircle(x, y, 5, TFT_WHITE);  // Draw circle at touch point
    String coords = "X:" + String(x) + " Y:" + String(y);
    display.drawString(coords, display.width() / 2, display.height() / 2);  // Display coordinates
  }
  delay(20); //?
}  

had to flip the x and y, then y had to be reversed..

i did mention the cords were off but i’ve also seen this before with other libs when rotating the screen..

good luck.. ~q

Thanks for figuring that out...

Is this with any setRotation() or just the default setRotation(no argument)?

(I imagine this will break when "the fix" arrives)

[edit] I will stay with Arduino_Nesso_N and NessoTouch... thanks again.

I like KEY1 on the left, setRotation(3) so I am guessing I need to invert x.
[edit]oops... that's not it...
[edit]oops... yes it is... I just can't type when excited.

  if (touch.read(y, x)) {                    // swapped x, y for NessoTouch problem // if (touch.read(x, y)) {
    x = display.width() - x;                 // added to correct setRotation(3)

Thank you, again.

I would imagine any but the default but i only tried setRotation(1)..

~q

You may use the method display.convertRawXY() to convert between touch and display coordinate systems. It handles the rotation.

#include <Arduino_Nesso_N1.h>

NessoDisplay display;
NessoTouch touch;

void setup() {
  display.begin();
  display.setRotation(1); // Set to landscape mode
  display.fillScreen(TFT_BLACK);

  // Set text properties that will be used for all text in this sketch
  display.setTextDatum(MC_DATUM); // Middle-Center datum for text alignment
  display.setTextColor(TFT_WHITE);
  display.setTextSize(2);

  // Display the initial message centered on the screen
  display.drawString("Touch the screen", display.width() / 2, display.height() / 2);

  touch.begin();
}

void loop() {
  // Variables to hold touch point
  int16_t tp_x, tp_y;

  // Check if the screen is being touched
  if (touch.isTouched()) {
    // Get coordinates of touch point
    touch.read(tp_x, tp_y);
    // Convert coordinates from touchscreen to screen, taking rotation into account
    display.convertRawXY(&tp_x, &tp_y);

    // Clear the screen to update both the circle and the text
    display.fillScreen(TFT_BLACK);
    
    // Draw a white circle at the current touch coordinates
    display.fillCircle(tp_x, tp_y, 5, TFT_WHITE);

    // Create a string with the updated coordinates
    String coords = "X:" + String(tp_x) + " Y:" + String(tp_y);

    // Draw the coordinates string at the FIXED center of the screen
    display.drawString(coords, display.width() / 2, display.height() / 2);
  }

Thank you... and interesting... does convertRawXY() configure and use the IMU?

No.
It uses the rotation of the display that was set with display.setRotation().
Because display.setRotation() affects only the display coordinates but not the coordinates returned by touch.read(x, y), you need a method to convert between display coordinates and touch coordinates. This is what convertRawXY() does for you.