| 93 | } |
| 94 | |
| 95 | void LiquidCrystal_I2C::begin(uint8_t cols __attribute__((unused)), uint8_t lines, uint8_t dotsize) { |
| 96 | if (lines > 1) { |
| 97 | _displayfunction |= LCD_2LINE; |
| 98 | } |
| 99 | _numlines = lines; |
| 100 | |
| 101 | // for some 1 line displays you can select a 10 pixel high font |
| 102 | if ((dotsize != 0) && (lines == 1)) { |
| 103 | _displayfunction |= LCD_5x10DOTS; |
| 104 | } |
| 105 | |
| 106 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! |
| 107 | // according to datasheet, we need at least 40ms after power rises above 2.7V |
| 108 | // before sending commands. Arduino can turn on way before 4.5V so we'll wait 50 |
| 109 | delay(50); |
| 110 | |
| 111 | // Now we pull both RS and R/W low to begin commands |
| 112 | expanderWrite(_backlightval); // reset expander and turn backlight off (Bit 8 =1) |
| 113 | delay(1000); |
| 114 | |
| 115 | //put the LCD into 4 bit mode |
| 116 | // this is according to the hitachi HD44780 datasheet |
| 117 | // figure 24, pg 46 |
| 118 | |
| 119 | // we start in 8bit mode, try to set 4 bit mode |
| 120 | write4bits(0x03 << 4); |
| 121 | delayMicroseconds(4500); // wait min 4.1ms |
| 122 | |
| 123 | // second try |
| 124 | write4bits(0x03 << 4); |
| 125 | delayMicroseconds(4500); // wait min 4.1ms |
| 126 | |
| 127 | // third go! |
| 128 | write4bits(0x03 << 4); |
| 129 | delayMicroseconds(150); |
| 130 | |
| 131 | // finally, set to 4-bit interface |
| 132 | write4bits(0x02 << 4); |
| 133 | |
| 134 | // set # lines, font size, etc. |
| 135 | command(LCD_FUNCTIONSET | _displayfunction); |
| 136 | |
| 137 | // turn the display on with no cursor or blinking default |
| 138 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; |
| 139 | display(); |
| 140 | |
| 141 | // clear it off |
| 142 | clear(); |
| 143 | |
| 144 | // Initialize to default text direction (for roman languages) |
| 145 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; |
| 146 | |
| 147 | // set the entry mode |
| 148 | command(LCD_ENTRYMODESET | _displaymode); |
| 149 | |
| 150 | home(); |
| 151 | |
| 152 | } |