ESP32-LCD
This commit is contained in:
parent
cbc3331482
commit
8efa0966df
52
esp32-lcd/README.md
Normal file
52
esp32-lcd/README.md
Normal file
@ -0,0 +1,52 @@
|
||||
# ESP32-LCD
|
||||
|
||||
A status LCD for your homelab.
|
||||
|
||||
![ESP32-LCD prototype](../images/esp32-lcd.jpg)
|
||||
|
||||
## BOM
|
||||
|
||||
- Any HD44780-based character LCD display, up to 20x4 characters. The most common are 16x2 characters (16 characters per row, 2 rows).
|
||||
- An ESP-32 board
|
||||
- A potentiometer, usually a 10 or 100k one, for controlling contrast (a couple of resistances arranged as a voltage divider may also be fine)
|
||||
|
||||
## Assembly
|
||||
|
||||
Connect the LCD to the board:
|
||||
|
||||
LCD Pin ESP32 Pin
|
||||
____________________________________
|
||||
PIN01-VSS GND
|
||||
PIN02-VDD 5V
|
||||
PIN03 V0 10K Pot (Middle pin)
|
||||
PIN04 RS GPIO19
|
||||
PIN05 RW GND
|
||||
PIN06 E GPIO23
|
||||
PIN07 D0 NOT USED
|
||||
PIN08 D1 NOT USED
|
||||
PIN09 D2 NOT USED
|
||||
PIN10 D3 NOT USED
|
||||
PIN11 D4 GPIO18
|
||||
PIN12 D5 GPIO17
|
||||
PIN13 D6 GPIO16
|
||||
PIN14 D7 GPIO15
|
||||
PIN15 A 5V
|
||||
PIN16 K GND
|
||||
|
||||
Open config.h file and set display size and your wifi data.
|
||||
|
||||
Flash the code to the ESP32. If you use the Arduino ide to do it, just open the esp32-lcd.ino file with the Arduino ide and follow [this instructions](https://randomnerdtutorials.com/getting-started-with-esp32/)
|
||||
|
||||
Restart the ESP32. The display shows "Conn to wifi..." with the WIFI name in the second line (if using a two or more lines display) and then will show the IP address.
|
||||
|
||||
## Use
|
||||
|
||||
- Turn on the circuit, wait for connection and note down the IP address shown on the screen.
|
||||
- Make a GET request to the same IP address with a parameter "message" containing some text
|
||||
|
||||
> Example: to make the request using CURL from command line, try something along this lines (replace the IP addr with the one shown in the display):
|
||||
> curl -G http://192.168.1.78 --data-urlencode "message=Something interesting happened!"
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
The ESP32 logs are written in the serial monitor at 115200 baud. Just open the Arduino ide Serial Monitor from Tools menu and look at the logs.
|
2
esp32-lcd/esp32-lcd/.gitignore
vendored
Normal file
2
esp32-lcd/esp32-lcd/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
config.h
|
||||
|
15
esp32-lcd/esp32-lcd/config.h.example
Normal file
15
esp32-lcd/esp32-lcd/config.h.example
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
CONFIGURATION FILE
|
||||
Change the values in this file and rename it "config.h" before uploading the code to the board.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
const char* WIFI_SSID = "Squicky";
|
||||
const char* WIFI_PASSWORD = "SediaChinita@Terrazzo2017";
|
||||
const unsigned int DISPLAY_WIDTH = 16;
|
||||
const unsigned int DISPLAY_HEIGHT = 2;
|
||||
|
||||
#endif
|
||||
|
@ -3,9 +3,12 @@
|
||||
#include <WebServer.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <LiquidCrystal.h>
|
||||
#include "config.h"
|
||||
|
||||
const char* ssid = "ichibi";
|
||||
const char* password = "uffobaruffo";
|
||||
// ------- Configuration is in config.h file -------
|
||||
|
||||
const int WEBSERVER_PORT = 80;
|
||||
const char* WEBSERVER_MESSAGE_PARAM = "message";
|
||||
|
||||
/*
|
||||
|
||||
@ -30,19 +33,25 @@ LCD Pin –>ESP32 Pins
|
||||
|
||||
*/
|
||||
|
||||
WebServer server(80);
|
||||
|
||||
// Init lcd
|
||||
WebServer server(WEBSERVER_PORT); // Server on port 80
|
||||
LiquidCrystal lcd(19, 23, 18, 17, 16, 15);
|
||||
|
||||
const int led = 13;
|
||||
|
||||
void lcdPrintMultilineMessage(String message) {
|
||||
lcd.clear();
|
||||
int startFrom = 0;
|
||||
for (int i=0; i<DISPLAY_HEIGHT; i++) {
|
||||
lcd.setCursor(0,i);
|
||||
lcd.print(
|
||||
message.substring(startFrom, startFrom + DISPLAY_WIDTH)
|
||||
);
|
||||
startFrom += DISPLAY_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
void handleRoot() {
|
||||
digitalWrite(led, 1);
|
||||
lcd.clear();
|
||||
for (uint8_t i = 0; i < server.args(); i++) {
|
||||
lcd.print(server.arg(i));
|
||||
}
|
||||
lcdPrintMultilineMessage(server.arg(WEBSERVER_MESSAGE_PARAM));
|
||||
server.send(200, "text/plain", "ok");
|
||||
digitalWrite(led, 0);
|
||||
}
|
||||
@ -65,18 +74,25 @@ void handleNotFound() {
|
||||
}
|
||||
|
||||
void setup(void) {
|
||||
// set up the LCD's number of columns and rows:
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("Connecting to wifi...");
|
||||
// LCD: set up
|
||||
lcd.begin(DISPLAY_WIDTH, DISPLAY_HEIGHT);
|
||||
|
||||
// Init
|
||||
// SERIAL: set up
|
||||
Serial.begin(115200);
|
||||
Serial.println("");
|
||||
|
||||
// STATUS LED: set up
|
||||
pinMode(led, OUTPUT);
|
||||
digitalWrite(led, 0);
|
||||
Serial.begin(115200);
|
||||
|
||||
// LCD: Show SSID
|
||||
lcd.print("Conn to wifi...");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print(WIFI_SSID);
|
||||
|
||||
// Connect to wifi
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
Serial.println("");
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
|
||||
// Wait for connection
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
@ -85,12 +101,14 @@ void setup(void) {
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(ssid);
|
||||
Serial.println(WIFI_SSID);
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// Print to LCD
|
||||
// Print IP addr to LCD
|
||||
lcd.clear();
|
||||
lcd.print("Connected! IP:");
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print(WiFi.localIP());
|
||||
|
||||
if (MDNS.begin("esp32")) {
|
||||
@ -108,13 +126,4 @@ void setup(void) {
|
||||
void loop(void) {
|
||||
server.handleClient();
|
||||
delay(2);//allow the cpu to switch to other tasks
|
||||
|
||||
|
||||
|
||||
|
||||
// set the cursor to column 0, line 1
|
||||
// (note: line 1 is the second row, since counting begins with 0):
|
||||
lcd.setCursor(0, 1);
|
||||
// print the number of seconds since reset:
|
||||
lcd.print(millis() / 1000);
|
||||
}
|
||||
|
BIN
images/esp32-lcd.jpg
Normal file
BIN
images/esp32-lcd.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
Loading…
Reference in New Issue
Block a user