├── README.md ├── font.h └── ESP_Messenger_v1.0 /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266-I2C-OLED 2 | A I2C screen to show messages received from a client-browser. 3 | 4 | Copy the ESP_Messenger into your Arduino IDE and save as a new file. 5 | Also copy the font.h file in the same folder. 6 | 7 | Make sure you installed ARDUINO-ESP-IDE addon. https://github.com/sandeepmistry/esp8266-Arduino 8 | In the Arduino IDE you choose generic ESP module as boardtype it will compile without errors. 9 | 10 | On start-up the local-IP is shown on the OLED. 11 | In your browser type the local-IP of the ESP server, it will open a simple page where you can submit a string of text. 12 | This text will be shown on the oled that is connected to the ESP. 13 | 14 | Connections Oled - ESP8266: 15 | 16 | Oled-SDA connected to GPIO0 of ESP 17 | 18 | Oled-SCL connected to GPIO2 of ESP 19 | The I2C Oled board used has a SDD1306 controller. I did not (yet) test this sketch different controllers line SH1106. 20 | 21 | -------------------------------------------------------------------------------- /font.h: -------------------------------------------------------------------------------- 1 | // Small 8x8 font 2 | const char myFont[][8] PROGMEM = { 3 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, 4 | {0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00}, 5 | {0x00,0x00,0x07,0x00,0x07,0x00,0x00,0x00}, 6 | {0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x00}, 7 | {0x00,0x24,0x2A,0x7F,0x2A,0x12,0x00,0x00}, 8 | {0x00,0x23,0x13,0x08,0x64,0x62,0x00,0x00}, 9 | {0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00}, 10 | {0x00,0x00,0x05,0x03,0x00,0x00,0x00,0x00}, 11 | {0x00,0x1C,0x22,0x41,0x00,0x00,0x00,0x00}, 12 | {0x00,0x41,0x22,0x1C,0x00,0x00,0x00,0x00}, 13 | {0x00,0x08,0x2A,0x1C,0x2A,0x08,0x00,0x00}, 14 | {0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00}, 15 | {0x00,0xA0,0x60,0x00,0x00,0x00,0x00,0x00}, 16 | {0x00,0x08,0x08,0x08,0x08,0x08,0x00,0x00}, 17 | {0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00}, 18 | {0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00}, 19 | {0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00}, 20 | {0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00}, 21 | {0x00,0x62,0x51,0x49,0x49,0x46,0x00,0x00}, 22 | {0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00}, 23 | {0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00}, 24 | {0x00,0x27,0x45,0x45,0x45,0x39,0x00,0x00}, 25 | {0x00,0x3C,0x4A,0x49,0x49,0x30,0x00,0x00}, 26 | {0x00,0x01,0x71,0x09,0x05,0x03,0x00,0x00}, 27 | {0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00}, 28 | {0x00,0x06,0x49,0x49,0x29,0x1E,0x00,0x00}, 29 | {0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00}, 30 | {0x00,0x00,0xAC,0x6C,0x00,0x00,0x00,0x00}, 31 | {0x00,0x08,0x14,0x22,0x41,0x00,0x00,0x00}, 32 | {0x00,0x14,0x14,0x14,0x14,0x14,0x00,0x00}, 33 | {0x00,0x41,0x22,0x14,0x08,0x00,0x00,0x00}, 34 | {0x00,0x02,0x01,0x51,0x09,0x06,0x00,0x00}, 35 | {0x00,0x32,0x49,0x79,0x41,0x3E,0x00,0x00}, 36 | {0x00,0x7E,0x09,0x09,0x09,0x7E,0x00,0x00}, 37 | {0x00,0x7F,0x49,0x49,0x49,0x36,0x00,0x00}, 38 | {0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x00}, 39 | {0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x00}, 40 | {0x00,0x7F,0x49,0x49,0x49,0x41,0x00,0x00}, 41 | {0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x00}, 42 | {0x00,0x3E,0x41,0x41,0x51,0x72,0x00,0x00}, 43 | {0x00,0x7F,0x08,0x08,0x08,0x7F,0x00,0x00}, 44 | {0x00,0x41,0x7F,0x41,0x00,0x00,0x00,0x00}, 45 | {0x00,0x20,0x40,0x41,0x3F,0x01,0x00,0x00}, 46 | {0x00,0x7F,0x08,0x14,0x22,0x41,0x00,0x00}, 47 | {0x00,0x7F,0x40,0x40,0x40,0x40,0x00,0x00}, 48 | {0x00,0x7F,0x02,0x0C,0x02,0x7F,0x00,0x00}, 49 | {0x00,0x7F,0x04,0x08,0x10,0x7F,0x00,0x00}, 50 | {0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,0x00}, 51 | {0x00,0x7F,0x09,0x09,0x09,0x06,0x00,0x00}, 52 | {0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x00}, 53 | {0x00,0x7F,0x09,0x19,0x29,0x46,0x00,0x00}, 54 | {0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x00}, 55 | {0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x00}, 56 | {0x00,0x3F,0x40,0x40,0x40,0x3F,0x00,0x00}, 57 | {0x00,0x1F,0x20,0x40,0x20,0x1F,0x00,0x00}, 58 | {0x00,0x3F,0x40,0x38,0x40,0x3F,0x00,0x00}, 59 | {0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00}, 60 | {0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00}, 61 | {0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00}, 62 | {0x00,0x7F,0x41,0x41,0x00,0x00,0x00,0x00}, 63 | {0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00}, 64 | {0x00,0x41,0x41,0x7F,0x00,0x00,0x00,0x00}, 65 | {0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x00}, 66 | {0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00}, 67 | {0x00,0x01,0x02,0x04,0x00,0x00,0x00,0x00}, 68 | {0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x00}, 69 | {0x00,0x7F,0x48,0x44,0x44,0x38,0x00,0x00}, 70 | {0x00,0x38,0x44,0x44,0x28,0x00,0x00,0x00}, 71 | {0x00,0x38,0x44,0x44,0x48,0x7F,0x00,0x00}, 72 | {0x00,0x38,0x54,0x54,0x54,0x18,0x00,0x00}, 73 | {0x00,0x08,0x7E,0x09,0x02,0x00,0x00,0x00}, 74 | {0x00,0x18,0xA4,0xA4,0xA4,0x7C,0x00,0x00}, 75 | {0x00,0x7F,0x08,0x04,0x04,0x78,0x00,0x00}, 76 | {0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x00}, 77 | {0x00,0x80,0x84,0x7D,0x00,0x00,0x00,0x00}, 78 | {0x00,0x7F,0x10,0x28,0x44,0x00,0x00,0x00}, 79 | {0x00,0x41,0x7F,0x40,0x00,0x00,0x00,0x00}, 80 | {0x00,0x7C,0x04,0x18,0x04,0x78,0x00,0x00}, 81 | {0x00,0x7C,0x08,0x04,0x7C,0x00,0x00,0x00}, 82 | {0x00,0x38,0x44,0x44,0x38,0x00,0x00,0x00}, 83 | {0x00,0xFC,0x24,0x24,0x18,0x00,0x00,0x00}, 84 | {0x00,0x18,0x24,0x24,0xFC,0x00,0x00,0x00}, 85 | {0x00,0x00,0x7C,0x08,0x04,0x00,0x00,0x00}, 86 | {0x00,0x48,0x54,0x54,0x24,0x00,0x00,0x00}, 87 | {0x00,0x04,0x7F,0x44,0x00,0x00,0x00,0x00}, 88 | {0x00,0x3C,0x40,0x40,0x7C,0x00,0x00,0x00}, 89 | {0x00,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00}, 90 | {0x00,0x3C,0x40,0x30,0x40,0x3C,0x00,0x00}, 91 | {0x00,0x44,0x28,0x10,0x28,0x44,0x00,0x00}, 92 | {0x00,0x1C,0xA0,0xA0,0x7C,0x00,0x00,0x00}, 93 | {0x00,0x44,0x64,0x54,0x4C,0x44,0x00,0x00}, 94 | {0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00}, 95 | {0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00}, 96 | {0x00,0x41,0x36,0x08,0x00,0x00,0x00,0x00}, 97 | {0x00,0x02,0x01,0x01,0x02,0x01,0x00,0x00}, 98 | {0x00,0x02,0x05,0x05,0x02,0x00,0x00,0x00} 99 | }; 100 | -------------------------------------------------------------------------------- /ESP_Messenger_v1.0: -------------------------------------------------------------------------------- 1 | /* 2 | Version 1.0 supports OLED display's with either SDD1306 or with SH1106 controller 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include "font.h" 9 | //#define offset 0x00 // SDD1306 // offset=0 for SSD1306 controller 10 | #define offset 0x02 // SH1106 // offset=2 for SH1106 controller 11 | #define OLED_address 0x3c // all the OLED's I have seen have this address 12 | #define SSID "........" // insert your SSID 13 | #define PASS "........" // insert your password 14 | // ******************* String form to sent to the client-browser ************************************ 15 | String form = 16 | "

" 17 | "

" 18 | "

Talk to me :-)

" 19 | "" 20 | "

Wassup?

" 21 | "
"; 22 | 23 | ESP8266WebServer server(80); // HTTP server will listen at port 80 24 | long period; 25 | 26 | /* 27 | handles the messages coming from the webbrowser, restores a few special characters and 28 | constructs the strings that can be sent to the oled display 29 | */ 30 | void handle_msg() { 31 | clear_display(); // clears oled 32 | 33 | server.send(200, "text/html", form); // Send same page so they can send another msg 34 | 35 | // Display msg on Oled 36 | String msg = server.arg("msg"); 37 | Serial.println(msg); 38 | String decodedMsg = msg; 39 | // Restore special characters that are misformed to %char by the client browser 40 | decodedMsg.replace("+", " "); 41 | decodedMsg.replace("%21", "!"); 42 | decodedMsg.replace("%22", ""); 43 | decodedMsg.replace("%23", "#"); 44 | decodedMsg.replace("%24", "$"); 45 | decodedMsg.replace("%25", "%"); 46 | decodedMsg.replace("%26", "&"); 47 | decodedMsg.replace("%27", "'"); 48 | decodedMsg.replace("%28", "("); 49 | decodedMsg.replace("%29", ")"); 50 | decodedMsg.replace("%2A", "*"); 51 | decodedMsg.replace("%2B", "+"); 52 | decodedMsg.replace("%2C", ","); 53 | decodedMsg.replace("%2F", "/"); 54 | decodedMsg.replace("%3A", ":"); 55 | decodedMsg.replace("%3B", ";"); 56 | decodedMsg.replace("%3C", "<"); 57 | decodedMsg.replace("%3D", "="); 58 | decodedMsg.replace("%3E", ">"); 59 | decodedMsg.replace("%3F", "?"); 60 | decodedMsg.replace("%40", "@"); 61 | //Serial.println(decodedMsg); // print original string to monitor 62 | unsigned int lengte = decodedMsg.length(); // length of received message 63 | for (int i=0;i>4)&0x0f)); //set high col address 212 | } 213 | 214 | 215 | //==========================================================// 216 | // Prints a string regardless the cursor position. 217 | static void sendStr(unsigned char *string) 218 | { 219 | unsigned char i=0; 220 | while(*string) 221 | { 222 | for(i=0;i<8;i++) 223 | { 224 | SendChar(pgm_read_byte(myFont[*string-0x20]+i)); 225 | } 226 | *string++; 227 | } 228 | } 229 | 230 | //==========================================================// 231 | // Prints a string in coordinates X Y, being multiples of 8. 232 | // This means we have 16 COLS (0-15) and 8 ROWS (0-7). 233 | static void sendStrXY( const char *string, int X, int Y) 234 | { 235 | setXY(X,Y); 236 | unsigned char i=0; 237 | while(*string) 238 | { 239 | for(i=0;i<8;i++) 240 | { 241 | SendChar(pgm_read_byte(myFont[*string-0x20]+i)); 242 | } 243 | *string++; 244 | } 245 | } 246 | 247 | 248 | //==========================================================// 249 | // Inits oled and draws logo at startup 250 | static void init_OLED(void) 251 | { 252 | sendcommand(0xae); //display off 253 | sendcommand(0xa6); //Set Normal Display (default) 254 | // Adafruit Init sequence for 128x64 OLED module 255 | sendcommand(0xAE); //DISPLAYOFF 256 | sendcommand(0xD5); //SETDISPLAYCLOCKDIV 257 | sendcommand(0x80); // the suggested ratio 0x80 258 | sendcommand(0xA8); //SSD1306_SETMULTIPLEX 259 | sendcommand(0x3F); 260 | sendcommand(0xD3); //SETDISPLAYOFFSET 261 | sendcommand(0x0); //no offset 262 | sendcommand(0x40 | 0x0); //SETSTARTLINE 263 | sendcommand(0x8D); //CHARGEPUMP 264 | sendcommand(0x14); 265 | sendcommand(0x20); //MEMORYMODE 266 | sendcommand(0x00); //0x0 act like ks0108 267 | 268 | //sendcommand(0xA0 | 0x1); //SEGREMAP //Rotate screen 180 deg 269 | sendcommand(0xA0); 270 | 271 | //sendcommand(0xC8); //COMSCANDEC Rotate screen 180 Deg 272 | sendcommand(0xC0); 273 | 274 | sendcommand(0xDA); //0xDA 275 | sendcommand(0x12); //COMSCANDEC 276 | sendcommand(0x81); //SETCONTRAS 277 | sendcommand(0xCF); // 278 | sendcommand(0xd9); //SETPRECHARGE 279 | sendcommand(0xF1); 280 | sendcommand(0xDB); //SETVCOMDETECT 281 | sendcommand(0x40); 282 | sendcommand(0xA4); //DISPLAYALLON_RESUME 283 | sendcommand(0xA6); //NORMALDISPLAY 284 | 285 | clear_display(); 286 | sendcommand(0x2e); // stop scroll 287 | //----------------------------REVERSE comments----------------------------// 288 | sendcommand(0xa0); //seg re-map 0->127(default) 289 | sendcommand(0xa1); //seg re-map 127->0 290 | sendcommand(0xc8); 291 | delay(1000); 292 | //----------------------------REVERSE comments----------------------------// 293 | // sendcommand(0xa7); //Set Inverse Display 294 | // sendcommand(0xae); //display off 295 | sendcommand(0x20); //Set Memory Addressing Mode 296 | sendcommand(0x00); //Set Memory Addressing Mode ab Horizontal addressing mode 297 | // sendcommand(0x02); // Set Memory Addressing Mode ab Page addressing mode(RESET) 298 | } 299 | 300 | 301 | --------------------------------------------------------------------------------