Wemos and BMP180 readings on an OLED display simple project

In this particular example we are going to simply display temperature. pressure and altitude readings from a BMP180 sensor on an OLED display. These are all the shields used in making this a simple project to build.

Requirements

1 x Wemos Mini
1 x Wemos Dual Base
1 x OLED Shield
1 x BMP180 Shield (not an official Wemos Shield)

You can see what I assembled in the picture below, I could have stacked in one column but I wanted to see the OLED and also leave the BMP180 uncovered.

 

Code

There are 2 libraries required – you can install these via the library manager, here are links to them

https://github.com/adafruit/Adafruit-BMP085-Library
https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library

#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <SFE_MicroOLED.h>  // Include the SFE_MicroOLED library
#define PIN_RESET 255  //
#define DC_JUMPER 0  // I2C Addres: 0 - 0x3C, 1 - 0x3D
 
MicroOLED oled(PIN_RESET, DC_JUMPER); // Example I2C declaration
Adafruit_BMP085 bmp;
 
void setup() 
{
  Serial.begin(9600);
  if (!bmp.begin()) {
  Serial.println("Could not find a valid BMP180 sensor, check wiring!");
  while (1) {}
  }
  oled.begin();
  oled.clear(ALL);  // Clear the display's memory (gets rid of artifacts)
  oled.display();  
}
 
void loop() 
{
  // Wait a few seconds between measurements.
  delay(2000);
 
 
  oled.clear(PAGE); 
  oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
  oled.setCursor(1, 3);
  oled.print("Pressure = ");
  oled.setCursor(1, 12);
  oled.print(bmp.readPressure());
  oled.print(" Pa");
  oled.setCursor(1, 21);
  oled.print("Temp =");
  oled.setCursor(1, 30);
  oled.print(bmp.readTemperature());
  oled.print(" *C ");
  oled.display();  
  delay(2000);
  //2nd page of readings
  oled.clear(PAGE); 
  oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
  oled.setCursor(1, 3);
  oled.print("Altitude = ");
  oled.setCursor(1, 12);
  oled.print(bmp.readAltitude());
  oled.print(" m");
  oled.setCursor(1, 21);
  oled.print("Sea Level=");
  oled.setCursor(1, 30);
  oled.print(bmp.readSealevelPressure());
  oled.print(" Pa");
  oled.display();  
}

Output

I split the readings into 2, the first readings are displayed for 2 seconds. Here you can see the output

 

 

 

 

Links

You can get all the boards and shields for about $10

Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos

Double Socket Dual Base Shield for WeMos D1 Mini NodeMCU ESP8266 Diy PCB D1 Expansion board

64X48 IIC I2C LCD OLED LED Dispaly Shield for Arduino Compatible WeMos D1 Mini

BMP180 Replace BMP085 Digital Barometric Pressure Sensor Module FOR WeMos D1 mini

Wemos and DHT11 readings on an OLED display simple project

This is the first simple project we are going to create using the Wemos Mini and various shields

In this particular example we are going to simply display temperature and humidity readings from a DHT11 sensor on an OLED display. These are all shields making this a simple project to build.

Requirements

1 x Wemos Mini
1 x Wemos Dual Base
1 x OLED Shield
1 x DHT Shield

You can see what I assembled in the picture below, I could have stacked in one column but I wanted to see the OLED and also leave the DHT11 uncovered.

Code

Various libraries required – you can install these via the library manager, here are links to them

https://github.com/adafruit/DHT-sensor-library
https://github.com/adafruit/Adafruit_Sensor
https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library

#include "DHT.h"
#include <Wire.h>  // Include Wire if you're using I2C
#include <SFE_MicroOLED.h>  // Include the SFE_MicroOLED library
 
#define DHTPIN D4     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11
#define PIN_RESET 255  //
#define DC_JUMPER 0  // I2C Addres: 0 - 0x3C, 1 - 0x3D
 
MicroOLED oled(PIN_RESET, DC_JUMPER); // Example I2C declaration
DHT dht(DHTPIN, DHTTYPE);
 
void setup() 
{
  Serial.begin(9600);
  dht.begin();
  oled.begin();
  oled.clear(ALL);  // Clear the display's memory (gets rid of artifacts)
  oled.display();  
}
 
void loop() 
{
  // Wait a few seconds between measurements.
  delay(2000);
 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) 
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  oled.clear(PAGE); 
  oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
  oled.setCursor(1, 3);
  oled.print("Humidity: ");
  oled.setCursor(1, 12);
  oled.print(h);
  oled.print(" %\t");
  oled.setCursor(1, 21);
  oled.print("Temp :");
  oled.setCursor(1, 30);
  oled.print(t);
  oled.print(" *C ");
  oled.display();  
}

 

Output

All going well you should see something like this on your display, you can obviously change the text to what you want or even convert to fahrenheit. The Adafruit library supports that and a heat index value, here you can see what we need to be added to display this via the serial monitor, this is in the DHT11 example in the library.

 

// Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);
 
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F")

 

 

Links

You can get all the boards and shields for about $10
Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos

Double Socket Dual Base Shield for WeMos D1 Mini NodeMCU ESP8266 Diy PCB D1 Expansion board

D1 Mini WeMos DHT11 Single Bus Digital Temperature Humidity Sensor Shield Module

64X48 IIC I2C LCD OLED LED Dispaly Shield for Arduino Compatible WeMos D1 Mini

Wemos buzzer shield example

In this example we look at another Wemos mini shield, this time its the buzzer_shield which as its name suggests is a basic buzzer. Its an MLT_8540.

The product page is https://wiki.wemos.cc/products:d1_mini_shields:buzzer_shield

 

Code

This example plays a few notes from a popular song

int buzzerPin=D5; //Buzzer control port, default D5
const int songLength = 18;
char notes[] = "cdfda ag cdfdg gf ";
int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
int tempo = 150;
 
 
void setup() 
{
  pinMode(buzzerPin, OUTPUT);
}
 
 
void loop() 
{
  int i, duration;
 
  for (i = 0; i < songLength; i++) // step through the song arrays
  {
    duration = beats[i] * tempo;  // length of note/rest in ms
 
    if (notes[i] == ' ')          // is this a rest? 
    {
      delay(duration);            // then pause for a moment
    }
    else                          // otherwise, play the note
    {
      tone(buzzerPin, frequency(notes[i]), duration);
      delay(duration); // wait for tone to finish
    }
    delay(tempo/10);              // brief pause between notes
  }
 
  while(true){}
 
}
 
 
int frequency(char note) 
{
 
  int i;
  const int numNotes = 8;  // number of notes we're storing
  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
  int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
 
 
  for (i = 0; i < numNotes; i++)  // Step through the notes
  {
    if (names[i] == note)         // Is this the one?
    {
      return(frequencies[i]);     // Yes! Return the frequency
    }
  }
  return(0); 
}

Wemos mini MATRIX LED Shield example

A new shield for the Wemos Mini came my way recently, this is called the MATRIX LED Shield – You can find out more at https://wiki.wemos.cc/products:d1_mini_shields:matrix_led_shield

The board uses a TM1640, as you can see there are 8×8 LEDs with 8 levels of intensity. The shield will also use the D5 an D7 pins of your wemos mini, so these won’t be available for any other projects

Code

This requires the library from https://github.com/wemos/WEMOS_Matrix_LED_Shield_Arduino_Library

There are a couple of built in examples but here are a few examples that will flash various LEDs

#include <WEMOS_Matrix_LED.h>
 
MLED mled(5); //set intensity=5
 
void setup()
{
 
}
 
void loop() {
 
  for(int y=0;y<8;y++)
  {
    for(int x=0;x<8;x++)
    {
        mled.dot(x,y); // draw dot
        mled.display();
        delay(200);      
    }  
  }
}
#include <WEMOS_Matrix_LED.h>
MLED mled(5); //set intensity=5
void setup()
{
}
void loop() {
for(int y=0;y<8;y++)
{
mled.dot(0,y); // draw dot
mled.display();
delay(200);
}
}

#include <WEMOS_Matrix_LED.h>
MLED mled(5); //set intensity=5
int randX, randY;
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop()
{
randX = random(8);
randY = random(8);
mled.dot(randX,randY); // draw dot
mled.display();
delay(200);
}

#include <WEMOS_Matrix_LED.h>
MLED mled(5); //set intensity=5
int randX, randY;
void setup()
{
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop()
{
randX = random(8);
randY = random(8);
mled.dot(randX,randY); // draw dot
mled.display();
delay(200);
mled.dot(randX,randY,0);//clear dot
mled.display();
delay(200);
}

 

Links