how to change library in order to use SLEEP MODE with ST7735 1.8 TFT

Hello,

I found online that this functions can be used to make a 1.8 ST7735 TFT display sleep and wake up (with Adafruit library):

void sleep(void) { writecommand(ST77XX_SLPIN); }
void wake(void) { writecommand(ST77XX_SLPOUT); }

Unfortunately, I really cannot understand where to put them in the library. I tried to insert them in the file: Adafruit_ST7735.h in the "public" section, but if I do that, the code does not compile even if I do not call those functions.

You can write your own class that inherits from Adafruit_ST7735.

Or you could hack the Adafruit_ST7735 class by adding a sleep() and a wake() method.

In practice, you are never going to use tft.sleep() and tft.wake()
And it is simpler to just call tft.writeCommand(ST77XX_SLPIN);

Adding extra class methods is pretty easy.
Personally, I would only write a super class if writeCommand() was protected.

Note that your spelling of writecommand() is WRONG.

David.

Thank you David,

I tried tft.writeCommand(ST77XX_SLPIN), but the display is still on...?

You have to wrap the writeCommand() between a startwrite() and an endwrite()

You would be better off with sendCommand() which comes from the Adafruit_SPITFT class.
And it looks as if it handles the transactions.

Read the library code in Adafruit_SPITFT.cpp

Note that the full-fat method expects an array of arguments
But from the Adafruit_SPITFT.h

  void sendCommand(uint8_t commandByte, const uint8_t *dataBytes = NULL,
                   uint8_t numDataBytes = 0);

So you could use the short form e.g.

tft.sendCommand(ST77XX_SLPIN);

Do everything at your own risk. Adafruit changes stuff at random.

David.

Ok, now the screen becomes all white, I guess because the chip is off??... is there a way through the code to turn off the backlight?

As I said in #1

In practice, you are never going to use tft.sleep() and tft.wake()

Post a link to the actual board that you have bought. Make sure that any photos of the pcb in the link match exactly.

David.

You were right David.

Here the link of the display I bought. It is really exactly the same:

Also, I would like to add that I am using it at 3.3 volts since I am controlling it with the Nano BLE 33 sense, so, both VCC and LED pin are connected to 3V3 pin of Arduino.

The LED pin has no transistor. Just R4 which looks like 3R3. 3R3 will be fine for 3.3V but you probably need 39R or 47R if you want to connect LED pin to 5V.

An AVR would need two GPIO pins to switch the LED on or off.
Or you add an external transistor.

David.

Dear David,

thank you a lot. I tried both options:

  • using t GPIO pins set to OUTPUT HIGH
  • using a bc547b transistor where I connected the 3V to the collector, the emitter to the LED pin of the display and a GPIO pin to the base passing through a resistor of 220 Ohm.

Both options work, but both give a super dimmed brightness...

Go on. Draw the schematic on paper. Put in the necessary voltages. Calculate currents, resistors, ...

You would normally switch a PNP transistor with a GPIO pin in regular common emitter mode. With the emitter at 3V and 3V logic. (or emitter at 5V and 5V logic)
Or a NPN in emitter follower mode with collector at 5V. And 5V GPIO logic.

The load is a white LED operating at 2.8V - 3.0V drawing 20 - 40mA.

Now you can see why 3R3 is on the pcb (for 3.3V operation).

David.