├── ESP32_Deep_Sleep_Example.ino ├── ESP32_OLED_TEST_SHT22_02.ino ├── ESP32_SimpleWiFiServer.ino ├── Licence.txt ├── README.md └── images.h /ESP32_Deep_Sleep_Example.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "sys/time.h" 5 | #include "sdkconfig.h" 6 | #include "esp_deep_sleep.h" 7 | #include 8 | 9 | #define GPIO_DEEP_SLEEP_DURATION 10 // sleep 10 seconds and then wake up 10 | #define LED_PIN 2 11 | 12 | RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory 13 | 14 | void setup(){ 15 | 16 | } 17 | 18 | void loop() { 19 | WiFi.mode(WIFI_OFF); 20 | btStop(); // btStart(); 21 | struct timeval now; 22 | pinMode(LED_PIN, OUTPUT); // set the LED pin mode 23 | printf("Starting ESP32 after deep-sleep\n"); 24 | digitalWrite(LED_PIN, HIGH); 25 | delay(500); 26 | digitalWrite(LED_PIN, LOW); 27 | gettimeofday(&now, NULL); 28 | printf("deep sleep (%lds since last reset, %lds since last boot)\n",now.tv_sec,now.tv_sec-last); 29 | last = now.tv_sec; 30 | esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /ESP32_OLED_TEST_SHT22_02.ino: -------------------------------------------------------------------------------- 1 | // Include the correct display library 2 | // For a connection via I2C using Wire include 3 | #include // Only needed for Arduino 1.6.5 and earlier 4 | #include "DHT.h" //https://github.com/adafruit/DHT-sensor-library 5 | #include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` 6 | // or #include "SH1106.h" alis for `#include "SH1106Wire.h"` 7 | // For a connection via I2C using brzo_i2c (must be installed) include 8 | // #include // Only needed for Arduino 1.6.5 and earlier 9 | // #include "SSD1306Brzo.h" 10 | // #include "SH1106Brzo.h" 11 | // For a connection via SPI include 12 | // #include // Only needed for Arduino 1.6.5 and earlier 13 | // #include "SSD1306Spi.h" 14 | // #include "SH1106SPi.h" 15 | 16 | // Initialize the OLED display using Wire library 17 | SSD1306 display(0x3c, 5,4); 18 | 19 | // SH1106 display(0x3c, 5,4); 20 | // Create the DHT temperature and humidity sensor object 21 | DHT dht1(0, DHT22); 22 | 23 | float DHT22_t, DHT22_h; 24 | int xpos = 0; 25 | 26 | void setup() { 27 | Serial.begin(115200); 28 | Serial.println(); 29 | dht1.begin(); 30 | DHT22_t = dht1.readTemperature(); 31 | DHT22_h = dht1.readHumidity(); 32 | 33 | Serial.print("DHT22 "); 34 | Serial.print(DHT22_t,1); Serial.print(String(char(176))+"C "); 35 | Serial.print(DHT22_h,1); Serial.println("%RH"); 36 | Serial.println(); 37 | 38 | // Initialising the UI will init the display too. 39 | display.init(); 40 | display.flipScreenVertically(); 41 | display.setFont(ArialMT_Plain_16); 42 | } 43 | 44 | void drawTempHumiDemo() { 45 | DHT22_t = dht1.readTemperature(); 46 | DHT22_h = dht1.readHumidity(); 47 | display.setFont(ArialMT_Plain_24); 48 | display.setTextAlignment(TEXT_ALIGN_CENTER); // The coordinates define the center of the screen! 49 | display.drawString(64,0,String(DHT22_t,1)+"°C"); 50 | display.drawString(64,30,String(DHT22_h,1)+"% rh"); 51 | display.setTextAlignment(TEXT_ALIGN_LEFT); // The coordinates define the center of the screen! 52 | display.drawString(xpos%128,40,"-"); 53 | } 54 | 55 | void loop() { 56 | display.clear(); // clear the display 57 | display.setTextAlignment(TEXT_ALIGN_RIGHT); 58 | drawTempHumiDemo(); 59 | display.display(); 60 | delay(1500); 61 | xpos = xpos + 2; 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /ESP32_SimpleWiFiServer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WiFi Web Server LED Blink 3 | 4 | A simple web server that lets you blink an LED via the web. 5 | This sketch will print the IP address of your WiFi Shield (once connected) 6 | to the Serial monitor. From there, you can open that address in a web browser 7 | to turn on and off the LED on pin 2 on the ESP32 VROOM board. 8 | 9 | If the IP address of your shield is yourAddress: 10 | http://yourAddress/H turns the LED on 11 | http://yourAddress/L turns it off 12 | 13 | This example is written for a network using WPA encryption. For 14 | WEP or WPA, change the Wifi.begin() call accordingly. 15 | 16 | Circuit: 17 | * WiFi shield attached 18 | * LED attached to pin 2 19 | */ 20 | 21 | #include 22 | 23 | const char* ssid = "SSID"; 24 | const char* password = "PASSWORD"; 25 | 26 | WiFiServer server(80); 27 | #define LED_PIN 2 28 | 29 | void setup() 30 | { 31 | Serial.begin(115200); 32 | pinMode(LED_PIN, OUTPUT); // set the LED pin mode 33 | delay(10); 34 | // We start by connecting to a WiFi network 35 | Serial.println(); 36 | Serial.println(); 37 | Serial.print("Connecting to "); 38 | Serial.println(ssid); 39 | //esp_wifi_start(); 40 | WiFi.begin(ssid, password); 41 | 42 | while (WiFi.status() != WL_CONNECTED) { 43 | delay(500); 44 | Serial.print("."); 45 | } 46 | 47 | Serial.println(""); 48 | Serial.println("WiFi connected"); 49 | Serial.println("IP address: "); 50 | Serial.println(WiFi.localIP()); 51 | 52 | server.begin(); 53 | 54 | } 55 | 56 | int value = 0; 57 | 58 | void loop(){ 59 | WiFiClient client = server.available(); // listen for incoming clients 60 | 61 | if (client) { // if you get a client, 62 | Serial.println("new client"); // print a message out the serial port 63 | String currentLine = ""; // make a String to hold incoming data from the client 64 | while (client.connected()) { // loop while the client's connected 65 | if (client.available()) { // if there's bytes to read from the client, 66 | char c = client.read(); // read a byte, then 67 | Serial.write(c); // print it out the serial monitor 68 | if (c == '\n') { // if the byte is a newline character 69 | 70 | // if the current line is blank, you got two newline characters in a row. 71 | // that's the end of the client HTTP request, so send a response: 72 | if (currentLine.length() == 0) { 73 | // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) 74 | // and a content-type so the client knows what's coming, then a blank line: 75 | client.println("HTTP/1.1 200 OK"); 76 | client.println("Content-type:text/html"); 77 | client.println(); 78 | 79 | // the content of the HTTP response follows the header: 80 | client.print("Click here turn the LED on pin 2 ON
"); 81 | client.print("Click here turn the LED on pin 2 OFF
"); 82 | 83 | // The HTTP response ends with another blank line: 84 | client.println(); 85 | // break out of the while loop: 86 | break; 87 | } else { // if you got a newline, then clear currentLine: 88 | currentLine = ""; 89 | } 90 | } else if (c != '\r') { // if you got anything else but a carriage return character, 91 | currentLine += c; // add it to the end of the currentLine 92 | } 93 | 94 | // Check to see if the client request was "GET /H" or "GET /L": 95 | if (currentLine.endsWith("GET /H")) { 96 | digitalWrite(LED_PIN, HIGH); // GET /H turns the LED on 97 | } 98 | if (currentLine.endsWith("GET /L")) { 99 | digitalWrite(LED_PIN, LOW); // GET /L turns the LED off 100 | } 101 | } 102 | } 103 | // close the connection: 104 | client.stop(); 105 | Serial.println("client disconnected"); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Licence.txt: -------------------------------------------------------------------------------- 1 | This software, the ideas and concepts is Copyright (c) David Bird 2014 and beyond. 2 | 3 | All rights to this software are reserved. 4 | 5 | It is prohibited to redistribute or reproduce of any part or all of the software contents in any form other than the following: 6 | 7 | 1. You may print or download to a local hard disk extracts for your personal and non-commercial use only. 8 | 9 | 2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material. 10 | 11 | 3. You may not, except with my express written permission, distribute or commercially exploit the content. 12 | 13 | 4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes. 14 | 15 | 5. You MUST include all of this copyright and permission notice ('as annotated') and this shall be included in all copies or substantial portions of the software and where the software use is visible to an end-user. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. 18 | 19 | FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | 21 | IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP32-X1-Examples 2 | Example code for the Lolin ESP32 X1 board 3 | -------------------------------------------------------------------------------- /images.h: -------------------------------------------------------------------------------- 1 | #define WiFi_Logo_width 60 2 | #define WiFi_Logo_height 36 3 | const char WiFi_Logo_bits[] PROGMEM = { 4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 6 | 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 7 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 8 | 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 9 | 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 10 | 0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 11 | 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, 12 | 0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C, 13 | 0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00, 14 | 0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C, 15 | 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00, 16 | 0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 17 | 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 18 | 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C, 19 | 0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00, 20 | 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F, 21 | 0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00, 22 | 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 23 | 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 24 | 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 25 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 27 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 28 | }; 29 | --------------------------------------------------------------------------------