ESP32 WROOM – Pinout, Wi-Fi and Bluetooth
FunduinoLast updated on
Pinbelegung, WiFi, Bluetooth und Einrichtung in der Arduino IDE
You need this
0.96-inch OLED display - 128x64 pixels, I2C, SSD1306
4,19 € *Item no. FUN-1010561About the product — 0.96-inch OLED display - 128x64 pixels, I2C, SSD1306
LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V
6,21 € *Item no. F23107181About the product — LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V
DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V
5,10 € *Item no. F23106657About the product — DS3231 RTC module - real-time clock with I2C, 3.3-5.5 V
All 3 parts together 15,50 € *
* All prices include statutory VAT, plus shipping costs.
What can the ESP32-Wroom do?
I2C pins
1 / 4
Random numbers on the 20x4 LCD
# include "LCDIC2.h"
// 4-zeiliges LCD
LCDIC2 lcd(0x27, 20, 4);
// 2-zeiliges LCD
// LCDIC2 lcd(0x3f, 16, 2);
void setup()
{
// Zufallsgenerator starten
randomSeed(analogRead(0));
// LCD starten
lcd.begin();
// Cursor verbergen
lcd.setCursor(false);
// Ausgabe auf dem LCD
// Cursor auf Position 0 in Zeile 0 setzen
lcd.setCursor(0, 0);
lcd.print("Zufallszahlen:");
// Cursor auf Position 0 in Zeile 0 setzen
lcd.setCursor(0, 1);
// // 6 Zufallszahlen anzeigen
for (int i = 1; i <= 6; i++)
{
int Zahl = random(1, 7);
lcd.print(String(Zahl));
lcd.print(" ");
}
}
void loop()
{
// bleibt leer, Programm läuft nur einmal
}SPI pins
Touch pins
1 / 3
Read touch pin 32
void setup()
{
// Serielle Kommunikation starten
Serial.begin(9600);
delay(1000);
}
void loop()
{
Serial.print("Wert: ");
// gemessenen Wert am Touch-Pin 32 anzeigen
Serial.print(touchRead(32));
// wenn der Wert < 20 -> Pin wurde berührt
if (touchRead(32) < 20) Serial.println(" -> Pin berührt");
// bei größeren Werten wurde der Pin nicht berührt
else Serial.println(" -> Pin nicht berührt");
delay(1000);
}Digital pins
1 / 2
Make the LED on pin 33 blink
int LED = 33;
void setup()
{
pinMode(LED, OUTPUT);
}
void loop()
{
digitalWrite(LED, HIGH);
delay(1000);
digitalWrite(LED, LOW);
delay(1000);
}Analog pins
1 / 3
Read potentiometer on pin 35
// Potentiometer an Pin 35
int Potentiometer = 35;
// Variable für den gelesenen Wert
int GelesenerWert = 0;
void setup()
{
Serial.begin(9600);
delay(1000);
}
void loop()
{
// analogen Wert lesen
GelesenerWert = analogRead(Potentiometer);
Serial.println(GelesenerWert);
delay(500);
}DAC pins
Dim the LED on pin 25 (DAC)
void setup()
{
// no setup required
}
void loop()
{
// Increase brightness in steps of 5
for (int i = 50; i < 255; i+=5)
{
dacWrite(25, i);
delay(20);
}
// Decrease brightness in steps of 5
for (int i = 255; i > 50; i-=5)
{
dacWrite(25, i);
delay(20);
}
}WiFi
1 / 2
Display random numbers in the browser (WiFi)
#include "WiFi.h"
// Router SSID and password
char Router[] = "Router_SSID";
char Passwort[] = "xxxxxxxx";
WiFiServer Server(80);
WiFiClient Client;
// Minimum and maximum random numbers
int Minimum = 1;
int Maximum = 49;
void setup()
{
Serial.begin(9600);
// Wait for serial connection
while (!Serial);
// Start WiFi
WiFi.begin(Router, Passwort);
// Establish connection
while (WiFi.status() != WL_CONNECTED)
{
delay(200);
Serial.print(".");
}
Server.begin();
// Display router SSID
Serial.println();
Serial.print("Connected to ");
Serial.println(WiFi.SSID());
// Display IP
Serial.println(WiFi.localIP());
// Initialize random number generator with the signal on A0
randomSeed(analogRead(0));
}
void loop()
{
Client = Server.available();
if (Client)
{
// Build page if SeiteAufbauen is true
boolean SeiteAufbauen = true;
// While the client is connected ...
while (Client.connected())
{
if (Client.available())
{
// Read request from client ...
char Zeichen = Client.read();
// return (\n) sent
if (Zeichen == '\n')
{
// If SeiteAufbauen has the value true
if (SeiteAufbauen)
{
/*
Build HTML page
the following instructions must
be sent with print or println
println "beautifies" the source code
(creates a line break in the source code)
*/
// Build HTML page
Client.println("HTTP/1.1 200 OK");
Client.println("Content-type:text/html");
// Blank line is required
Client.println();
Client.println("<!doctype html>");
Client.println("<html>");
Client.println("<body>");
// Refresh every 60 seconds with a meta tag
Client.println("<meta http-equiv=\"refresh\" content=\"60\">");
// <h2> H2 heading
Client.println("<h2>Random numbers</h2>");
// <hr> horizontal line
Client.println("<hr>");
// Display random numbers
for (int i = 0; i < 7; i++ )
{
int Zahl = random(Minimum, Maximum);
Client.println(Zahl);
Client.println(" ");
}
Client.print("<hr>");
// Display IPs
Client.print("Own IP (server): ");
Client.print(Client.remoteIP());
// <br> break = newline
Client.print("<br>Client DHCP IP address ");
Client.print(WiFi.localIP());
// Close the page
Client.println("</h2></body>");
Client.println("</html>");
// The HTTP response ends with a newline
Client.println();
// Page fully loaded -> exit loop
break;
}
// If a newline (\n) was sent -> build the page
if (Zeichen == '\n') SeiteAufbauen = true;
else if (Zeichen != '\r') SeiteAufbauen = false;
delay(1);
Client.stop();
}
}
}
}
}Bluetooth BLE
Switch LED via Bluetooth BLE
# include "ArduinoBLE.h"
/*
determine unique UUID:
https://www.guidgenerator.com/online-guid-generator.aspx
https://www.uuidgenerator.net/
BLERead | BLEWrite | BLENotify
-> write, read, info
*/
// BLE service name
BLEService LEDSchalten("19b10000-e8f2-537e-4f6c-d104768a1214");
BLEUnsignedCharCharacteristic Auswahl("19b10000-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite | BLENotify);
// LED on pin 18
int LED = 18;
void setup()
{
Serial.begin(9600);
// wait for serial connection
while (!Serial);
delay(1000);
// set pinMode
pinMode(LED, OUTPUT);
// start BLE
if (!BLE.begin()) Serial.println("Bluetooth module could not be started!");
else Serial.println("Bluetooth module started successfully!");
// set name (displayed in the app) and assign the service (LEDSchalten)
BLE.setLocalName("Switch LED");
BLE.setAdvertisedService(LEDSchalten);
// Auswahl as a placeholder for the value selected in the app
LEDSchalten.addCharacteristic(Auswahl);
// add service LEDSchalten
BLE.addService(LEDSchalten);
// write initial value for communication
Auswahl.writeValue(0);
// start advertising
BLE.advertise();
}
void loop()
{
// wait for connection to devices
BLEDevice Verbindung = BLE.central();
// if the ESP32 is connected to a device ...
if (Verbindung)
{
Serial.println("Connected ... ");
// while the controller is connected to a device ...
while (Verbindung.connected())
{
if (Auswahl.written())
{
// turn on LED
if (Auswahl.value() == '1')
{
Serial.print(char(Auswahl.value()));
Serial.println(" -> LED on");
digitalWrite(LED, HIGH);
}
// turn off LED
if (Auswahl.value() == '0')
{
Serial.print(char(Auswahl.value()));
Serial.println(F(" -> LED off"));
digitalWrite(LED, LOW);
}
}
}
}
}Install board
1 / 2
Select board
1 / 2
Rate the instructions