Das zweiundzwanzigste Türchen

Short before Christmas, most people surely think of roast goose and chocolate Christmas tree balls. Dear good Santa, look at your rod, I always want to be good (or something like that). But winter has more to offer than just holidays. Father Frost ensures that we should also take an occasional look at the thermometer, especially as a driver or other road user who should leave earlier in fog or black ice.

The content behind today's little door is just right: A highly flexible ESP8266-12F in the form of the unsoldered Lolin V3. What are the clear strengths and advantages of this micro controller? First of all, it is a high-performance ESP8266 with many pins brought out for connecting sensors and actuators. And of course you can integrate it with WiFi in your home WiFi. Since the board comes unsoldered, there are other possibilities than just using a breadboard.

The following test setup is suitable for measuring the atmospheric data under the carport or on the balcony / terrace. In a first step, I will display the weather data in the Serial Monitor of the Arduino IDE, then build on this to display the data in the WLAN.

Figure 1 shows the setup for measuring air pressure, temperature and relative humidity with the BME280 sensor.

Are you missing the jumper cables in the picture? I moved it below the micro controller to get by with a “half breadboard”. The breadboard becomes even narrower if you remove the power supply strips.

Alternatively, instead of the pin strips, you can solder in so-called spring strips, also known as socket strips (not included in delivery).


Then you don't need a breadboard at all and can plug in the sensor directly. If, like me, you use the combined air pressure, temperature and humidity sensor BME280, a 4 socket strip may be sufficient. I advise against soldering in the sensor in order to be able to replace it if necessary.


Connection is no problem with the four pins. We only need the power supply and the two I2C connections SDA and SCL, which are here on SDA = D6 = GPIO12 and SCL = D5 = GPIO14.

The sketch also offers the option of adapting individual lines for the SPI version of the sensor. However, the BME280 from the AZ-Delivery range only supports I2C.


// Example testing sketch for various DHT humidity/temperature sensors written by ladyada
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor

#include <Wire.h>

//Sensor
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
/* pins for SPI
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 4
*/
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime = 2000;
float tempC;
float humid;
float pressure;

void setup() {
//Sensor
  Serial.begin(74880);
  Wire.begin(12,14);
  while(!Serial); // time to get serial running
  Serial.println(F("BME280 test"));

  unsigned status;

// default settings
  status = bme.begin(0x76);
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
    Serial.print("SensorID was: 0x"); 
    Serial.println(bme.sensorID(),16);
    Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
    Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
    Serial.print(" ID of 0x60 represents a BME 280.\n");
    Serial.print(" ID of 0x61 represents a BME 680.\n");
    while (1) delay(10);
  }
}

void loop() {
// Sensor
// Wait a few seconds between measurements.
  delay(delayTime);

// Read temperature as Celsius (the default)
  tempC = bme.readTemperature();
// Read rel. humidity
  humid = bme.readHumidity();
// Read air pressure
  pressure = bme.readPressure() / 100.0;

  Serial.print(F("Air Pressure: "));
  Serial.print(pressure,1);
  Serial.print(F(" HPa "));
  Serial.print(F(" Humidity: "));
  Serial.print(humid,1);
  Serial.print(F("% Temperature: "));
  Serial.print(tempC,1);
  Serial.println(F("°C "));
  Serial.println();

Download Code1

Here is a screenshot of the output in the serial monitor:


Now we want to add the registration in the home WLAN; then the data can be read on the PC or smartphone in the browser. Please make sure to include your WiFi data (SSID and password) before uploading the sketch.

// Example testing sketch for various DHT humidity/temperature sensors written by ladyada
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
// modified for WiFi by Team AZ-Delivery.de
// add your SSID and password below

#include <Wire.h>
// Server
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* SSID = "-----your SSID-----";
const char* PASSWORD = "---your password---";
ESP8266WebServer server(80);

//Sensor
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme; // I2C
/* pins for SPI
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 4
*/
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime = 2000;
float tempC;
float humid;
float pressure;

void setup() {
//Sensor
  Serial.begin(74880);
  Wire.begin(12,14);
  while(!Serial); // time to get serial running
  Serial.println(F("BME280 test"));

  unsigned status;

// default settings
  status = bme.begin(0x76);
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
    Serial.print("SensorID was: 0x");
    Serial.println(bme.sensorID(),16);
    Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
    Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
    Serial.print(" ID of 0x60 represents a BME 280.\n");
    Serial.print(" ID of 0x61 represents a BME 680.\n");
    while (1) delay(10);
  }

// Server
  Serial.begin(74880);
  WiFi.mode(WIFI_STA);
  WiFi.begin(SSID, PASSWORD);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.printf("Connected to %s.\n", SSID);
  Serial.printf("IP-Address: %s.\n", WiFi.localIP().toString().c_str());

  if (MDNS.begin("Lolin32")) {
    Serial.println("MDNS-Responder started.");
  }

  server.on("/", handleRoot);

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP-Server started.");

}

void loop() {
// Sensor
// Wait a few seconds between measurements.
  delay(delayTime);

// Read temperature as Celsius (the default)
  tempC = bme.readTemperature();
// Read rel. humidity
  humid = bme.readHumidity();
// Read air pressure
  pressure = bme.readPressure() / 100.0;

  Serial.print(F("Air Pressure: "));
  Serial.print(pressure,1);
  Serial.print(F(" HPa "));
  Serial.print(F(" Humidity: "));
  Serial.print(humid,1);
  Serial.print(F("% Temperature: "));
  Serial.print(tempC,1);
  Serial.println(F("°C "));
  Serial.println();
 
// Server
  server.handleClient();

server.on("/Sensor", HTTP_GET, []() {
  String message = "<!doctype html>\n";
  message += "<html>\n";
  message += " <head>\n";
  message += " <title>Lolin V3 und BME280</title>\n";
  message += " </head>\n";
  message += " <body>\n";
  message += " <h1>Air Pressure: ";
  message += String(pressure, 1);
  message += " HPa;</h1>\n";
  message += " <h1>Temperature: ";
  message += String(tempC, 2);
  message += " &#8451;</h1>\n";
  message += " <h1>Rel. Humidity: ";
  message += String(humid, 0);
  message += " %</h1>\n";
  message += " </body>\n";
  message += "</html>\n";
  server.send(200, "text/html", message);
  });
}

void handleRoot() {
  server.send(200, "text/plain", "Here is your LolinV3!");
}

void handleNotFound() {
  String message = "Path ";
  message += server.uri();
  message += " not found.\n";
  server.send(404, "text/plain", message);
}

Download Code2

After the start or reset, you will see the IP address of the Lolin V3-8266 in the Serial Monitor before air pressure, rel. humidity and temperature are displayed in an infinite loop.


And so the whole thing in the browser, simply the IP address, supplemented by /sensor enter.


I wish you a blessed Christmas and all the best for a better year 2021.

Specials

3 comments

Bernd Albrecht

Bernd Albrecht

@ A. Freudenstein
Hallo und vielen Dank für Ihr Interesse an unseren Produkten und Blog-Beiträgen.
Ich mache keinen Hehl daraus, dass ich aufgrund des letzten Satzes geneigt war, Ihren Kommentar komplett zu löschen. Aber mein Lehrer sagte immer „Sine ira et studio“. Selbstverständlich kann immer etwas beim Hochladen oder Verlinken schief gehen. Also habe ich die Verlinkung aus dem Blog genommen, die beiden Sketches heruntergeladen und gestartet, das richtige Micro Controller Board eingestellt und das Kompilieren gestartet. Beide Sketche wurde ohne Fehlermeldung kompiliert.
Aufgrund Ihrer Angaben kann ich den Fehler bei Ihnen leider nicht abschließend analysieren; ich vermute falsche Board-Einstellung oder nicht-kompatible Bibliotheken.
Wenn die Probleme fortbestehen, wenden Sie sich bitte an unseren Service.

A. Freudenstein

A. Freudenstein

Hallo,
versuchte, über Weihnachten das 22. Türchen zum Laufen zu bringen, nachdem ich mir die Teile original bei az.delivery bestellt und auch noch rechtzeitig erhalten hatte.
Dachte, recht einfache Sache. Trugschluß!
Beim Kompilieren traten Fehler über Fehler auf, die ich nach und nach beseitigt hatte, bis zum Schluß der Fehler mit der wire.h Bibliothek noch übrig blieb, der sich nicht beseitigen ließ und ein Fehler in der Zeile ca. 45, beginnt mit: Serial.println(bme.sensorID(),16);
Frage: Gibt es mittlerweile irgendwo schon eine lauffähige Version, die mir jemand zukommen lassen kann? (Beide Versionen, Code 1 + 2)?
Damit das Suchen und Basteln ein Ende hat.
Wurden die Versionen vom Verfasser des Blogs ausprobiert?
MfG
A. Freudenstein

Matthias Kasper

Matthias Kasper

Hallo zusammen,

genau dafür habe ich schon vor einiger Zeit ein Gehäuse zum 3D-Druck konstruiert. Das kann auf Thingiverse mit dem Link https://www.thingiverse.com/thing:4672436 runter geladen werden.

Mit freundlichen Grüßen
Matthias

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN