M5StamPLC and the Backlight
-
Hello,
I would like to turn off the backlight of the M5StamPLC when there's nothing to see.
The set_backlight function from the M5 library doesn't seem to work. The reason
is probably that there is no "normal" LCD_BL pin:// Display #define STAMPLC_PIN_LCD_MOSI 8 #define STAMPLC_PIN_LCD_MISO 9 #define STAMPLC_PIN_LCD_SCLK 7 #define STAMPLC_PIN_LCD_DC 6 #define STAMPLC_PIN_LCD_CS 12 #define STAMPLC_PIN_LCD_RST 3 #define STAMPLC_PIN_LCD_BUSY -1 #define STAMPLC_PIN_LCD_BL -1In the M5StamPLC, the PI4IOE5V6408 is responsible for the backlight, and pin 7 is responsible for it.
Unfortunately, my own routine doesn't work either:
void my_set_backlight(bool o) { PI4IOE5V6408_Class p; // false input, true output p.setDirection(7, true); // false off, true on ? p.digitalWrite(7, o); }Does anyone have an idea, or even better, a solution?
-
The solution from Chat.M5Stack.com didn't work either:
#include <M5StamPLC.h> #include <Wire.h> #define PI4IOE5V6408_ADDR 0x43 // I2C-address #define DIR_REG 0x06 #define OUTPUT_REG 0x02 void setup() { M5StamPLC.begin(); // Initialisiert I2C-Bus (G15=SCL, G13=SDA) // P7 (LCD_BL) is output, Set Bit 7 of DIR_REG = 0 Wire.beginTransmission(PI4IOE5V6408_ADDR); Wire.write(DIR_REG); Wire.write(0x7F); // 0b01111111 (only P7=output) Wire.endTransmission(); } void setBacklight(bool on) { Wire.beginTransmission(PI4IOE5V6408_ADDR); Wire.write(OUTPUT_REG); Wire.write(on ? 0xFF : 0x7F); // P7=1 (on) or 0 (off) Wire.endTransmission(); } -
Hello @GermanSheepDog
your
my_set_backlight()function works for me andmy_set_backlight(true)turns the backlight off (inverted logic).void my_set_backlight(bool o) { PI4IOE5V6408_Class p; // false input, true output p.setDirection(7, true); // false off, true on ? p.digitalWrite(7, o); } void setup() { auto cfg = M5.config(); cfg.serial_baudrate = 115200; M5.begin(cfg); M5StamPLC.begin(); } void loop() { M5.update(); if(M5.BtnA.wasClicked() == true) { Serial.println("BtnA clicked - backlight on"); my_set_backlight(false); } if(M5.BtnC.wasClicked() == true) { Serial.println("BtnC clicked - backlight off"); my_set_backlight(true); } }Thanks
FelixP.S. the AI generated code did not work for me.
-
Hello @GermanSheepDog
below is an alternative function which works for me too:
#define PI4IOE5V6408_ADDR 0x43 #define OUTPUT_REG 0x05 void my_set_backlight(bool o) { uint8_t data = M5.In_I2C.readRegister8(PI4IOE5V6408_ADDR, OUTPUT_REG, 200000); if(o == true) data |= 0b10000000; else data &= ~0b10000000; M5.In_I2C.writeRegister8(PI4IOE5V6408_ADDR, OUTPUT_REG, data, 200000); }Thanks
Felix -
Hello @felmue,
thank you very much for your quick support, it really helped me.
It didn't work in my "big" program, but I wrote a small test program, and it fully meets the requirements:
#include <M5StamPLC.h> void my_set_backlight(bool o) { PI4IOE5V6408_Class p; p.setDirection(7, true); // false input, true output p.digitalWrite(7, !o); // false on, true off } void printAndWait(String s) { M5StamPLC.Display.println(" " + s); delay(4000); } void setup() { Serial.begin(115200); M5StamPLC.begin(); M5StamPLC.Display.setTextSize(3); } void loop() { M5StamPLC.Display.fillScreen(TFT_BLACK); M5StamPLC.Display.setCursor(0, 10); printAndWait("Test 1"); printAndWait("Test 2"); my_set_backlight(false); printAndWait("Test 3"); my_set_backlight(true); printAndWait("Test 4"); }You can see it not only in the dark screen, but also in the power consumption, which is reduced by about 20%.
I suspect that in my "big" program, someone is turning the lights back on (and working against me).
Best regards,
Uwe
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login