├── .gitignore ├── photo.jpg ├── web ├── image.png └── data.php ├── README.md ├── LICENSE └── badge └── badge.ino /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronpk/esp-badge/master/photo.jpg -------------------------------------------------------------------------------- /web/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aaronpk/esp-badge/master/web/image.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Wifi Badge 2 | ========== 3 | 4 | This project will load an image from a web server and display it on an TTGO T5 ESP32 display. 5 | 6 | ![photo](photo.jpg) 7 | 8 | ## Badge 9 | 10 | The file in "badge" is an Arduino project that downloads an image and writes all the pixels to the e-paper display. 11 | 12 | You'll need to install the GxEPD library into to your Arduino environment: 13 | 14 | * [GxEPD](https://github.com/lewisxhe/GxEPD) 15 | 16 | 17 | ## Server 18 | 19 | The file in "web" will convert a png image to a byte stream that the badge reads from. 20 | You will need to generate a greyscale png image of the appropriate dimensions for the display. 21 | 22 | 23 | -------------------------------------------------------------------------------- /web/data.php: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | // https://github.com/lewisxhe/GxEPD 6 | #include 7 | #include // 2.13" b/w 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | 14 | 15 | 16 | // Define the URL to pull the image data from 17 | String imageURL = ""; 18 | 19 | // Define your WiFi 20 | char wifiSSID[] = ""; 21 | char wifiPassword[] = ""; 22 | 23 | // Refresh the image every 5 minutes 24 | #define TIME_TO_SLEEP 60 * 5 25 | 26 | 27 | 28 | 29 | // These pins depend on the specific TTGO board you have 30 | #define ELINK_BUSY 4 31 | #define ELINK_RESET 16 32 | #define ELINK_DC 17 33 | #define ELINK_SS 5 34 | const int buttonPin = 39; 35 | const int ledPin = 19; 36 | 37 | WiFiMulti WiFiMulti; 38 | 39 | GxIO_Class io(SPI, ELINK_SS, ELINK_DC, ELINK_RESET); 40 | GxEPD_Class display(io, ELINK_RESET, ELINK_BUSY); 41 | 42 | #define uS_TO_S_FACTOR 1000000 43 | 44 | void wifiStart() 45 | { 46 | WiFiMulti.addAP(wifiSSID, wifiPassword); 47 | 48 | Serial.println(); 49 | Serial.print("Waiting for WiFi... "); 50 | 51 | while(WiFiMulti.run() != WL_CONNECTED) { 52 | Serial.print("."); 53 | delay(500); 54 | } 55 | 56 | Serial.println(""); 57 | Serial.print("WiFi connected: "); 58 | Serial.println(WiFi.SSID()); 59 | Serial.print("IP address: "); 60 | Serial.println(WiFi.localIP()); 61 | } 62 | 63 | 64 | void displayImage() { 65 | digitalWrite(ledPin, HIGH); 66 | delay(100); 67 | 68 | HTTPClient http; 69 | http.begin(imageURL); 70 | int httpCode = http.GET(); 71 | String imageData; 72 | if(httpCode > 0) { 73 | imageData = http.getString(); 74 | Serial.print("Downloaded image: "); 75 | Serial.print(imageData.length()); 76 | Serial.println(" bytes"); 77 | } else { 78 | Serial.print("[HTTP] GET... failed, error:"); 79 | Serial.println(http.errorToString(httpCode).c_str()); 80 | return; 81 | } 82 | 83 | int i; 84 | int x = 0; 85 | int y = 0; 86 | 87 | Serial.println("Attempting to display image"); 88 | delay(500); 89 | 90 | // display.init(115200); 91 | display.init(); 92 | 93 | for(int c = 0; c < imageData.length(); c++) { 94 | char ch = imageData.charAt(c); 95 | for(i = 7; i >= 0; i--) { 96 | int bit = bitRead(ch, i); 97 | if(bit == 1) { 98 | display.drawPixel(x, y, GxEPD_WHITE); 99 | } else { 100 | display.drawPixel(x, y, GxEPD_BLACK); 101 | } 102 | x++; 103 | if(x == 122) { 104 | y++; 105 | x = 0; 106 | } 107 | } 108 | } 109 | 110 | display.update(); 111 | 112 | digitalWrite(ledPin, LOW); 113 | } 114 | 115 | void setup() { 116 | pinMode(buttonPin, INPUT); 117 | pinMode(ledPin, OUTPUT); 118 | 119 | Serial.begin(115200); 120 | delay(100); 121 | 122 | wifiStart(); 123 | 124 | delay(500); 125 | 126 | if(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) 127 | { 128 | // Woke up from sleep 129 | wifiStart(); 130 | displayImage(); 131 | } 132 | else 133 | { 134 | // First launch 135 | wifiStart(); 136 | displayImage(); 137 | } 138 | 139 | esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); 140 | 141 | Serial.println("Going to sleep now"); 142 | 143 | esp_deep_sleep_start(); 144 | } 145 | 146 | void loop() { 147 | // This isn't run because the device sleeps after the setup() function 148 | 149 | /* 150 | int buttonState = 0; 151 | buttonState = digitalRead(buttonPin); 152 | if(buttonState == LOW) { 153 | Serial.println("Button PRESSED"); 154 | displayImage(); 155 | } else { 156 | Serial.println("Button not pressed"); 157 | } 158 | */ 159 | 160 | } 161 | --------------------------------------------------------------------------------