DustinWatts / FreeTouchDeck

For interfacing with Windows/macOS/Linux using an ESP32, a touchscreen and BLE.
https://www.youtube.com/dustinwatts
MIT License
617 stars 124 forks source link

Backlight brightness control not working? #113

Closed DustinWatts closed 1 year ago

DustinWatts commented 1 year ago

Got a report that on the -master (Version 0.9.18a) BL control does not work. Have to check.

DustinWatts commented 1 year ago

I just checked and also on the ESP32 TouchDown S3 BL control isn't working. I have to investigate why not. Something goes wrong here:

  ledcSetup(0, 5000, 8);
#ifdef TFT_BL
  ledcAttachPin(TFT_BL, 0);
#else
  ledcAttachPin(backlightPin, 0);
#endif // defined(TFT_BL)
  ledcWrite(0, ledBrightness); // Start @ initial Brightness

In Action.h, this is where the actions are to increase and decrease the brightness. But from memory, nothing has changed here since 0.9.17.

case 2: // Display Brightness Down
      if (ledBrightness > 25)
      {
        ledBrightness = ledBrightness - 25;
        ledcWrite(0, ledBrightness);
        savedStates.putInt("ledBrightness", ledBrightness);
      }
      break;
    case 3: // Display Brightness Up
      if (ledBrightness < 230)
      {
        ledBrightness = ledBrightness + 25;
        ledcWrite(0, ledBrightness);
        savedStates.putInt("ledBrightness", ledBrightness);
      }
      break;

I have a feeling that due to the if statements, no pins are attached to the ledc channel.

DustinWatts commented 1 year ago

This is from 0.9.17, that is working:

  ledcSetup(0, 5000, 8);
#ifdef TFT_BL
  ledcAttachPin(TFT_BL, 0);
#else
  ledcAttachPin(32, 0);
#endif
  ledcWrite(0, ledBrightness); // Start @ initial Brightness

I have a feeling that it always skips ifdef TFT_BL and just attaches pin 32. Which on the ESP32 TouchDown as wel as on the DevKit version is the same and correct pin.

I made the changes to facilitate the BL control on the ESP32-S3 where pin 48 is used. I'm going to try with some Serial.print()'s to see what TFT_BL actually is.

XXGOD123 commented 1 year ago

This is from 0.9.17, that is working:

  ledcSetup(0, 5000, 8);
#ifdef TFT_BL
  ledcAttachPin(TFT_BL, 0);
#else
  ledcAttachPin(32, 0);
#endif
  ledcWrite(0, ledBrightness); // Start @ initial Brightness

I have a feeling that it always skips ifdef TFT_BL and just attaches pin 32. Which on the ESP32 TouchDown as wel as on the DevKit version is the same and correct pin.

I made the changes to facilitate the BL control on the ESP32-S3 where pin 48 is used. I'm going to try with some Serial.print()'s to see what TFT_BL actually is.

so, just change from ledcAttachPin(backlightPin, 0); to ledcAttachPin(32, 0);?

DustinWatts commented 1 year ago

so, just change from ledcAttachPin(backlightPin, 0); to ledcAttachPin(32, 0);?

Correct, this is a quick fix, but not a permanent fix for it to work across all boards.

XXGOD123 commented 1 year ago

so, just change from ledcAttachPin(backlightPin, 0); to ledcAttachPin(32, 0);?

Correct, this is a quick fix, but not a permanent fix for it to work across all boards.

What will happen if always use this method?

DustinWatts commented 1 year ago

On the DevKit version as well as on the ESP32 TouchDown, nothing. Edit: I mean nothing bad. It will work just fine :)

But, on the new (to be released, but not ETA) ESP32 TouchDown S3, the backlight pin is not 32 but 48. So I was trying to get the BL pin from the User_Setup.h of the the TFT_eSPI library. But this does not seem to work.

Raycast7373 commented 1 year ago

Backlight works fine for me (although the board i use isn't officially supported)

Raycast7373 commented 1 year ago

And i implemented auto brightness which runs in the main loop so there's that too

DustinWatts commented 1 year ago

Backlight works fine for me (although the board i use isn't officially supported)

Yes, if you define the correct pin for the brightness it should work.

But, let's stay on topic. This is about something not working, not about things that do work after a custom implementation :)

github-actions[bot] commented 1 year ago

This issue has been stale for a while now

OpossumTinte commented 2 weeks ago

Hello, I jus came across this problem, but I don't know how to solve it.

'ledcSetup' was not declared in this scope

this is in the same exact Code that you have posted. I would appreciate your help. Thank you in advance

DustinWatts commented 1 week ago

Hi! Check out Issue https://github.com/DustinWatts/FreeTouchDeck/issues/126 for a quick solution.