adafruit / Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
http://www.adafruit.com/category/63_98
Other
1.78k stars 977 forks source link

Turn on and off? #106

Open qietrosu opened 6 years ago

qietrosu commented 6 years ago

Is there any way to turn on and off the oled display? I have a mini weather station and i want the display to turn completly off and then back on if there is motion detected.

BillyDonahue commented 6 years ago

The SSD1306 has a sleep state, accessible through a raw ssd1306_command, so you can sleep and wake the display with:

void sleepDisplay(Adafruit_SSD1306* display) {
  display->ssd1306_command(SSD1306_DISPLAYOFF);
}

void wakeDisplay(Adafruit_SSD1306* display) {
  display->ssd1306_command(SSD1306_DISPLAYON);
}
XAS-712 commented 6 years ago

Try to debug it with a logic analyzer, and you may find out what is wrong.

dhalbert commented 6 years ago

These displays need a hardware reset by toggling their Reset pin after power-on. The library will do that if you supply a reset pin number. The OLED Featherwing gets around this with some circuitry that resets on power-up. The DISPLAYON/DISPLAYOFF does not do a full reset. See https://github.com/adafruit/Adafruit_CircuitPython_SSD1306/issues/7#issuecomment-355622748 and the rest of that issue for background.

Electronlibre2012 commented 5 years ago

The SSD1306 has a sleep state, accessible through a raw ssd1306_command, so you can sleep and wake the display with:

void sleepDisplay(Adafruit_SSD1306* display) {
  display->ssd1306_command(SSD1306_DISPLAYOFF);
}

void wakeDisplay(Adafruit_SSD1306* display) {
  display->ssd1306_command(SSD1306_DISPLAYON);
}

Hello,

is it possible to use thoses commands in hassio please?

Thanks!

Electronlibre2012 commented 5 years ago

If someone is intersting one day... i found the solution 👍

sensor: 
  - platform: adc
    pin: A0
    name: "Luminosite Salon"
    id: illumination_salon
    unit_of_measurement: lux
    update_interval: 10s
    filters:
      - lambda: return (( x * 3.3 / 10000.0) * 3000000.0);
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda:  |-
      it.printf(30, 3, id(five8), "Capteurs Salon");
      it.printf(30, 3, id(five8), "___________");
      it.printf(0, 20, id(five8), "Temperature ......... %.1f °C", id(temperature).state);
      it.printf(0, 30, id(five8), "Humidite .............. %.1f RH", id(humidite).state);
      it.printf(0, 40, id(five8), "Pression ........... %.1f hPa", id(pressure).state);
      it.printf(0, 50, id(five8), "Luminosite........... %.1f lm", id(illumination_salon).state);
      it.printf(0, 60, id(five8), "Wifi : %s", id(etatW).state ? "Online" : "Offline");
      it.printf(85, 60, id(five8), "%.1f", id(signalW).state);
      it.printf(115, 60, id(five8), "dB");

      if (id(illumination_salon).state < 50) {
        it.fill(COLOR_OFF);
      } else {
      }
vogt31337 commented 4 years ago

@Electronlibre2012 sorry you didn't find a solution. Your code snippet dosn't turn off the oled, it'll simply fills it with black. But the display driver and controller is still consuming power...

Sadly the only real way to solve this issue is to hard reset the display, after SSD1306_DISPLAYOFF...

Electronlibre2012 commented 4 years ago

Hello @vogt31337 ,

yes i know its not a real good solution to just fill off the screen but as you can see my post is from August 2019 and nobody respond.

Not sure i can use SSD1306_DISPLAYOFF in ESpHome?

Hard reset, you mean i put the power in VCC OFF and then i put back ON? Because there is no RST pin on the SSD1306 .

Thanks

BillyDonahue commented 4 years ago

On Mon, Mar 23, 2020 at 3:28 AM Oli notifications@github.com wrote:

Hello @vogt31337 https://github.com/vogt31337 ,

yes i know its not a real good solution to just fill off the screen but as you can see my post is from August 2019 and nobody respond.

Not sure i can use SSD1306_DISPLAYOFF in ESpHome?

Hard reset, you mean i put the power in VCC OFF and then i put back ON? Because there is no RST pin on the SSD1306 .

There is, though. Some boards bring it out, and other boards don't. I believe the Adafruit boards all bring it out. It's in the SSD1306 data sheet as RES#, documented unsurprisingly as:

"This pin is reset signal input. When the pin is pulled LOW,

initialization of the chip is executed. Keep this pin HIGH (i.e. connect to VDD) during normal operation."

I don't know how you're supposed to reset the breakout boards from other manufacturers that don't have a reset pin. I wish I did, because I have a handful of them and they don't always come up when they should.

-- ǝnɥɐuop ʎllıq

vogt31337 commented 4 years ago

@BillyDonahue, well that's the whole discussion about. Sadly not all adafruit boards bring this pin out. For example the oled feather is missing it. But has instead a brown out detector attached to it.

So one possibility would be to toggle such boards with a transistor. Or try finding the corresponding line on the on solder flex connector and solder a small wire to it.

Both options are somewhat meh...

AGeovany commented 4 years ago

Olá amigos! Não sou nenhum Expert, mas consegui utilizar as rotinas acima mencionadas da seguinte forma:

wakeDisplay(&display); //para acordar o display

sleepDisplay(&display);//para fazer dormir o display

desta forma o meu projeto funcionou perfeitamente com um OLED 128x64 I2C (SSD1306) espero ter ajudado!

SkullKill commented 4 years ago

just tested, for 2.23" SSD1305 this works

display.oled_command(SSD1305_DISPLAYOFF);

for 0.96" SSD1306 this works

display.ssd1306_command(SSD1306_DISPLAYOFF);

vogt31337 commented 4 years ago

@SkullKill, have you tried turning the oled on after issuing these commands? For example with: display.oled_command(SSD1305_DISPLAYON);

Won't work (on all Displays). Because like @dhalbert wrote, the display needs a hard reset and not all displays support this.

SkullKill commented 4 years ago

@vogt31337 i am issuing this before putting the ESP32 to deepsleep. then on wakeup, it reinitialize it. it is turning back on fine for me. (when it turn off, i can see that the back-light goes off, but i have not actually measured the power consumption).

i have not tried the "DISPLAYON" command.

i have the ones with the auto reset APX803S on it, but that should only activate with a cold boot off the 3.3v line. on mine, the 3.3v is always up.

i am not using the auto reset pin either.

maybe i am just lucky to have one that works fine?

the issue i do have however, is if i try display things under a task (xTaskCreate) , it does not work, and i just get gibberish on the screen. but i will have to open a separate issue for that...

alexd321 commented 3 years ago

On an ssd1306_i2c I am able to call:

- lambda: |-
              id(my_display).turn_off();

and

- lambda: |-
              id(my_display).turn_on();
mattcollier commented 3 years ago

Present day, there are sleep and wake APIs.

Blakout007 commented 11 months ago

in ESPHOME turn_off and turn_on works fine for SSD1306: on_press: then: lambda: |- id(oled).turn_on(); sleep(7); id(oled).turn_off();

But can't find a way to do the same in Arduino with C++!!

Sorry, did also get sleepDisplay and wakeDisplay to work. yeah...

tsb-i854v commented 8 months ago

Olá amigos!

Não sou nenhum Expert, mas consegui utilizar as rotinas acima mencionadas da seguinte forma:

wakeDisplay(&display); //para acordar o display

sleepDisplay(&display);//para fazer dormir o display

desta forma o meu projeto funcionou perfeitamente com um OLED 128x64 I2C (SSD1306)

espero ter ajudado!

EUREKA!!! Muchas gracias amigo On & Off oled display now works!!

AGeovany commented 8 months ago

Disponha meu amigo! É um prazer colaborar.

Alex.

Em dom., 4 de fev. de 2024 17:52, tsb-i854v @.***> escreveu:

Olá amigos!

Não sou nenhum Expert, mas consegui utilizar as rotinas acima mencionadas da seguinte forma:

wakeDisplay(&display); //para acordar o display

sleepDisplay(&display);//para fazer dormir o display

desta forma o meu projeto funcionou perfeitamente com um OLED 128x64 I2C (SSD1306)

espero ter ajudado!

EUREKA!!! Muchas gracias amigo On & Off oled display now works!!

— Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_SSD1306/issues/106#issuecomment-1925910875, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQE74GHKF7CVLQ3Z66M6ZBDYR7YKVAVCNFSM4EJZHHJ2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJSGU4TCMBYG42Q . You are receiving this because you commented.Message ID: @.***>