• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Testing the touchscreen – about orientation

Q&A Forum › Category: ESP32 › Testing the touchscreen – about orientation
0 Vote Up Vote Down
Gilbert Hersschens asked 5 months ago

The demo mentions that one may have to change the orientation to 0 if the touchscreen appears to be upside down. Technically this is correct, but may still be misunderstood. The setting only applies to the touch panel, not to the display panel. To avoid any confusion I changed my sketch to set the orientation for BOTH the display and the touch panel to the orientation I want, using this:

// LV_DISPLAY_ROTATION_0:   portrait, USB bottom side
// LV_DISPLAY_ROTATION_90:  landscape, USB right side
// LV_DISPLAY_ROTATION_180: portrait, USB top side
// LV_DISPLAY_ROTATION_270: landscape USB left side

#define TFT_ROTATION  LV_DISPLAY_ROTATION_270

// swap height and width according to rotation setting

#if ((TFT_ROTATION == LV_DISPLAY_ROTATION_0) || (TFT_ROTATION == LV_DISPLAY_ROTATION_180))
  #define SCREEN_WIDTH  240
  #define SCREEN_HEIGHT 320
#else                                                                                   
  #define SCREEN_WIDTH  320
  #define SCREEN_HEIGHT 240
#endif

 
and this:
 

touchscreen.setRotation(TFT_ROTATION);

lv_display_set_rotation(disp, TFT_ROTATION);

 
the LV_DISPLAY_ROTATION enum values are defined in lv_display.h
 
Now, my display and touch screen always have the same orientation and screen width and height are always correct for the selected orientation.
Just one little side effect (not sure if this is also the case in the original sketch): when I get close to the bottom and/or left edge of the screen, I get a warning in the serial monitor that x and/or y have a negative value. That’s because the screen is not calibrated. This can be avoided by either calibrating the touch screen or by adding constraints to the map function to get x and y of the touched point.

Question Tags: set orientation
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 months ago

That’s valuable information.
Thanks for sharing.
 
Yes, you must calibrate the display to avoid that behavior.
 
Thanks again.
 
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.