In this project we’ll create a weather station using StackyFi that collects temperature, humidity, and pressure data and displays it on a web interface. The data will be collected from a weather HAT and accessed remotely via a web interface.
What's StackyFi?Meet StackyFi—a revolutionary microcontroller board designed to empower your projects with ease and flexibility. Housed in a compact Raspberry Pi Zero form factor, StackyFi packs a powerful ESP32-S3 WROOM 1 microcontroller, featuring a dual-core 32-bit LX7 processor running up to 240 MHz.
StackyFi stands out with its seamless support for Raspberry Pi HATs, allowing you to directly stack and integrate various HATs without needing a separate Raspberry Pi board. Equipped with built-in 2.4 GHz Wi-Fi, Bluetooth® 5 (LE), and an onboard accelerometer, StackyFi offers dynamic connectivity and sensor integration options for a wide range of IoT and automation applications.
Fully open-source and highly customizable, StackyFi is perfect for developers and hobbyists looking to create innovative and versatile projects with ease.
1. Setting Up the HardwareConnect the Weather HAT to StackyFi:
- Align the Weather HAT with the 40-pin GPIO on StackyFi.
- Ensure the pins are properly seated.
- Connect the Weather HAT to StackyFi:Align the Weather HAT with the 40-pin GPIO on StackyFi.Ensure the pins are properly seated.
Power Supply:
- Connect StackyFi to a power source using a USB-C cable or battery pack.
- Power Supply:Connect StackyFi to a power source using a USB-C cable or battery pack.
Install Arduino IDE:
- Download and install the Arduino IDE from Arduino's official website.
- Install Arduino IDE:Download and install the Arduino IDE from Arduino's official website.
Add ESP32 Board Support:
- Open Arduino IDE.
- Go to
File>Preferences. - Add the following URL to the "Additional Boards Manager URLs" field:
https://dl.espressif.com/dl/package_esp32_index.json - Go to
Tools>Board>Boards Manager. - Search for "ESP32" and install the package.
- Add ESP32 Board Support:Open Arduino IDE.Go to
File>Preferences.Add the following URL to the "Additional Boards Manager URLs" field:https://dl.espressif.com/dl/package_esp32_index.jsonGo toTools>Board>Boards Manager.Search for "ESP32" and install the package.
Install Required Libraries:
- Go to
Sketch>Include Library>Manage Libraries.
Search and install the following libraries:
Adafruit Unified SensorAdafruit BME280(for temperature, humidity, and pressure)WiFi(to handle Wi-Fi connectivity)ESPAsyncWebServer(for the web server)- Search and install the following libraries:
Adafruit Unified Sensor(for temperature, humidity, and pressure)
Adafruit BME280WiFi(to handle Wi-Fi connectivity)ESPAsyncWebServer(for the web server) - Install Required Libraries:Go to
Sketch>Include Library>Manage Libraries.Search and install the following libraries:Adafruit Unified Sensor(for temperature, humidity, and pressure)
Adafruit BME280WiFi(to handle Wi-Fi connectivity)ESPAsyncWebServer(for the web server)
Weather Station Code:
This code will read data from the Weather HAT and serve it via a web interface.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
// Replace with your network credentials
const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
// Create an instance of the BME280 sensor
Adafruit_BME280 bme;
// Create an instance of the web server
AsyncWebServer server(80);
void setup() {
// Initialize serial communication
Serial.begin(115200);
// Initialize BME280 sensor
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to Wi-Fi");
// Define the web server routes
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<html><body>";
html += "<h1>Weather Station</h1>";
html += "<p>Temperature: " + String(bme.readTemperature()) + " ℃</p>";
html += "<p>Humidity: " + String(bme.readHumidity()) + " %</p>";
html += "<p>Pressure: " + String(bme.readPressure() / 100.0F) + " hPa</p>";
html += "</body></html>";
request->send(200, "text/html", html);
});
// Start the server
server.begin();
}
void loop() {
// Nothing to do here
}4. Uploading the Code
Select the Board:
- Go to
Tools>Boardand selectESP32 Dev Module. - Select the Board:Go to
Tools>Boardand selectESP32 Dev Module.
Select the Port:
- Go to
Tools>Portand choose the port where StackyFi is connected. - Select the Port:Go to
Tools>Portand choose the port where StackyFi is connected.
Upload the Code:
- Click the upload button (right arrow) to compile and upload the code to StackyFi.
- Upload the Code:Click the upload button (right arrow) to compile and upload the code to StackyFi.
Find the IP Address:
- Open the Serial Monitor in Arduino IDE (
Tools>Serial Monitor). - After StackyFi connects to Wi-Fi, it will display its IP address.
- Find the IP Address:Open the Serial Monitor in Arduino IDE (
Tools>Serial Monitor).After StackyFi connects to Wi-Fi, it will display its IP address.
Open the Web Interface:
- Enter the IP address into a web browser on your computer or smartphone.
- Open the Web Interface:Enter the IP address into a web browser on your computer or smartphone.
View Weather Data:
- You should see the temperature, humidity, and pressure readings displayed on the web page.
- View Weather Data:You should see the temperature, humidity, and pressure readings displayed on the web page.


_9UbRhuEvdT.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)








Comments