🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5StamPLC and the Backlight

    Scheduled Pinned Locked Moved Arduino
    5 Posts 2 Posters 2.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G Offline
      GermanSheepDog
      last edited by

      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 -1
      

      In 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?

      G 1 Reply Last reply Reply Quote 0
      • G Offline
        GermanSheepDog @GermanSheepDog
        last edited by GermanSheepDog

        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();
        }
        
        felmueF 1 Reply Last reply Reply Quote 0
        • felmueF Offline
          felmue @GermanSheepDog
          last edited by

          Hello @GermanSheepDog

          your my_set_backlight() function works for me and my_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
          Felix

          P.S. the AI generated code did not work for me.

          GPIO translation table M5Stack / M5Core2
          Information about various M5Stack products.
          Code examples

          felmueF 1 Reply Last reply Reply Quote 0
          • felmueF Offline
            felmue @felmue
            last edited by felmue

            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

            GPIO translation table M5Stack / M5Core2
            Information about various M5Stack products.
            Code examples

            G 1 Reply Last reply Reply Quote 0
            • G Offline
              GermanSheepDog @felmue
              last edited by

              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

              1 Reply Last reply Reply Quote 0

              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
              • First post
                Last post