This week's objective is to establish communication between two processors or devices. I decided to tackle both wired and wireless protocols using the powerful ESP32-C6 microcontroller. The mission involves configuring an I2C bus to extract data from a sensor and setting up an HTTP web server to stream that data directly to my laptop over Wi-Fi.
01. THE I2C NETWORK (WIRED)
The I2C (Inter-Integrated Circuit) protocol is perfect for connecting multiple devices using just a few pins on the microcontroller. It works like a shared bus where the ESP32 acts as the "Master" and calls out to different "Slave" devices using unique hexadecimal addresses.
For my setup, I routed a total of 4 wires in parallel (2 SDA and 2 SCL) directly to the same I2C bus on the ESP32-C6. This allowed me to hook up two completely different devices simultaneously: an SH1106G OLED display (Address: 0x3C) and an SHT31 Temperature/Humidity Sensor (Address: 0x44). The ESP32 first asks the SHT31 for the environmental data, translates the raw bytes into Celsius and percentage, and then immediately routes that data to the OLED display for real-time visualization.
I2C IN ACTION: ESP32 fetching data from the SHT31 and routing it to the SH1106 OLED.
02. HTTP WIRELESS PROTOCOL
Moving from wires to invisible waves, I used the ESP32-C6's built-in Wi-Fi capabilities to create a local HTTP server on port 80. This allows me to communicate with the microcontroller directly from my laptop's web browser.
The Process: First, the ESP32 connects to my local Wi-Fi router. Once authenticated, the router assigns it a unique local IP address. The code prints this IP to the Serial Monitor. I simply copied that IP address and pasted it into my laptop's browser URL bar.
To make the interface look professional, I used a C++ rawliteral string to inject custom HTML and CSS directly from the microcontroller. I styled it with dark mode colors, rounded cards, and added a crucial <meta http-equiv="refresh" content="2"> tag so the webpage auto-refreshes every 2 seconds to show live updates!
WIRELESS ACCESS: Entering the local IP to load the live-refreshing Web Server.
PART C
Upper Wings Geometry.
03. THE CODE VAULT
Below is the complete mission code separated into two crucial protocols: the Dual-Device I2C system and the Wi-Fi HTTP Server.
PART 1: THE I2C MULTI-DEVICE LOGIC
This code demonstrates the power of the I2C bus. It initializes both the SH1106 OLED and the SHT31 sensor. In the loop, it requests 6 bytes of data from address 0x44 (Sensor), does the math, and then sends formatting commands to address 0x3C (OLED) to draw the text on the screen.
This section connects the ESP32 to the local Wi-Fi, prints the IP, and hosts an auto-refreshing HTML/CSS page injecting the variables obtained from the sensor.