• Hi,
    As a complement, I used the following code on the Pixl.js.
    It allows to switch On/Off the display thus saving the few uA it consumes.
    Unfortunatelly, I do not have an oscilloscope and can't measure the real reduction of power consumption, nor any short peak of power when switched on back from deep sleep.

    It is a very quick C++ to espruino translation and still contains unused constants... I was about to add this to the standard ST7565 module, when I understood that, indeed, the Pixl.js is using an integrated version probably in C++.

    The source github repo is mentionned in the comments.

    // handle lcd on/off deep sleep
    // extracted from 
    // https://github.com/boseji/Rpi-ST7565-SPI­-LCD/blob/master/lcdST7565.c#L729
    
    /***************************************­*********************************/
    /* Commands    */
    /***************************************­*********************************/
    /*
    BLACK 1
    WHITE 0
    */
    
    var ST7565_LCD_CMD_DISPLAY_OFF = 0xAE;
    var ST7565_LCD_CMD_DISPLAY_ON = 0xAF;
    var ST7565_LCD_PARAM_BRIGHTNESS = 0x0;
    
    /* Unused constants from github
    ST7565_LCD_CMD_SET_DISP_START_LINE   0x40
    ST7565_LCD_CMD_SET_PAGE  0xB0
    
    ST7565_LCD_CMD_SET_COLUMN_UPPER   0x10
    ST7565_LCD_CMD_SET_COLUMN_LOWER   0x00
    
    ST7565_LCD_CMD_SET_ADC_NORMAL  0xA0
    ST7565_LCD_CMD_SET_ADC_REVERSE 0xA1
    
    ST7565_LCD_CMD_SET_DISP_NORMAL 0xA6
    ST7565_LCD_CMD_SET_DISP_REVERSE   0xA7
    */
    
    var ST7565_LCD_CMD_SET_ALLPTS_NORMAL = 0xA4;
    
    var ST7565_LCD_CMD_SET_ALLPTS_ON = 0xA5;
    
    /* Unused constants from github
    ST7565_LCD_CMD_SET_BIAS_9   0xA2
    ST7565_LCD_CMD_SET_BIAS_7   0xA3
    
    ST7565_LCD_CMD_RMW    0xE0
    ST7565_LCD_CMD_RMW_CLEAR 0xEE
    */
    
    var ST7565_LCD_CMD_INTERNAL_RESET = 0xE2;
    
    /* Unused constants from github
    ST7565_LCD_CMD_SET_COM_NORMAL  0xC0
    ST7565_LCD_CMD_SET_COM_REVERSE 0xC8
    ST7565_LCD_CMD_SET_POWER_CONTROL  0x28
    ST7565_LCD_CMD_SET_RESISTOR_RATIO 0x20
    */
    
    var ST7565_LCD_CMD_SET_VOLUME_FIRST = 0x81;
    var ST7565_LCD_CMD_SET_VOLUME_SECOND = 0x0;
    
    var ST7565_LCD_CMD_SET_STATIC_OFF = 0xAC;
    
    var ST7565_LCD_CMD_SET_STATIC_ON = 0xAD;
    
    var ST7565_LCD_CMD_SET_STATIC_REG = 0x0;
    
    /* Unused constants from github
    ST7565_LCD_CMD_SET_BOOSTER_FIRST  0xF8
    ST7565_LCD_CMD_SET_BOOSTER_234 0
    ST7565_LCD_CMD_SET_BOOSTER_5   1
    ST7565_LCD_CMD_SET_BOOSTER_6   3
    ST7565_LCD_CMD_NOP    0xE3
    ST7565_LCD_CMD_TEST   0xF0
    */
    
    /**
     *  Function to control the Contrast and brightness ratio
     *  - This is generally a fixed value for a given LCD.
     */
    function lcd_bright ( bValue ) {
      retcode = 0;
      retcode = Pixl.lcdw(ST7565_LCD_CMD_SET_VOLUME_FIRS­T);
      if(retcode !== 0) return retcode;
      return Pixl.lcdw(ST7565_LCD_CMD_SET_VOLUME_SECO­ND | (bValue & 0x3f));
    }
    
    /**
     * @brief Function to Put the LCD into Deep Sleep mode
     * 
     */
    function lcd_sleep ( ){
      // * WORKS displays is wiped, so you have to g.flip() afterward
      Pixl.lcdw(ST7565_LCD_CMD_SET_STATIC_OFF)­;
      Pixl.lcdw(ST7565_LCD_CMD_DISPLAY_OFF);
      Pixl.lcdw(ST7565_LCD_CMD_SET_ALLPTS_ON);­
    }
    
    /**
     * @brief Function to bring back the LCD from Deep Sleep mode
     * All display contents are cleared and need to reinitalize
     * 
     * WARNING SO FAR DISPLAY IS SET UPSIDE DOWN
     */
    function lcd_wakeup ( ) {
      Pixl.lcdw(ST7565_LCD_CMD_INTERNAL_RESET)­;
      lcd_bright(ST7565_LCD_PARAM_BRIGHTNESS);­
      Pixl.lcdw(ST7565_LCD_CMD_SET_ALLPTS_NORM­AL);
      Pixl.lcdw(ST7565_LCD_CMD_DISPLAY_ON);
      Pixl.lcdw(ST7565_LCD_CMD_SET_STATIC_ON);­
      Pixl.lcdw(ST7565_LCD_CMD_SET_STATIC_REG | 0x03);
    }
    
    /**
     * @brief Function to Put and wakup the LCD in Standby mode
     *   In this mode the display contents are not lost
     *   its only not visible
     * @param bWakeUp Used to decide that if we need to enter or exit standby
     *  0 - Enters into the Standby mode
     *  1 - Exits the Standby mode
     */
    function lcd_standby ( bWakeUp ) {
      if (bWakeUp === 0) { /* Enter standby mode */
        Pixl.lcdw(ST7565_LCD_CMD_SET_STATIC_ON);­
        Pixl.lcdw(ST7565_LCD_CMD_SET_STATIC_REG | 0x03);
        Pixl.lcdw(ST7565_LCD_CMD_DISPLAY_OFF);
        Pixl.lcdw(ST7565_LCD_CMD_SET_ALLPTS_ON);­
      }
      else { /* Wake from standby */
        Pixl.lcdw(ST7565_LCD_CMD_SET_ALLPTS_NORM­AL);
        Pixl.lcdw(ST7565_LCD_CMD_DISPLAY_ON);
      }
    }
    
    var lcdstatus = 0;
    
    function lcdonoff() {
      lcd_standby(lcdstatus);
      if (lcdstatus === 0) lcdstatus = 1;
      else lcdstatus = 0;
    }
    
    setWatch(lcdonoff,BTN1,{edge:"rising", debounce:50, repeat:true});
    
    
About

Avatar for asez73 @asez73 started