Please make sure that you succeeded in all the steps described here before you continue with the following instructions.

Installing all the libraries

Since the first version of this tutorial I have changed some parts of the code and turned it into a library. As a matter of fact not one library but three! But don’t get discouraged, it is easy enough to install them.Go to Sketch > Inlcude Library… > Manage Libraries… and install these three libraries:

Click to zoom

 

Click to zoom

 

Click to zoom

Make sure that you always have the latest version of the libraries installed. Users have reported many issues which could be reduced to updating the library. Also make sure that you only have one version of each of the libraries installed.

Open the Weather Station Example

You have now installed the three required libraries. Along with them came example sketches. If you have already worked with the Arduino IDE you might have used other demo sketches before. Now we are going to use the Weather Station template to get started.Go to File > Examples > ESP8266 Weather Station > WeatherStationDemo


Save the new sketch with a good name in a location you will remember;-), but leave it open.

 

Wunderground API Key

In order to display up-to-date weather information we’ll need to call a service. I recently switched from Forecast.io to wunderground.com. To get the Wunderground API key go to https://www.wunderground.com/weather/api/d/pricing.html and pick the “Stratus Developer” plan. Then get your API key from this page:

WundergroundApiKey

Click to zoom

 

If you should forget your key you can always come back and get it here. Or re-generate it just as I did after creating this screenshot;-)

Configuring the Weather Station

Now comes a bunch of configuration options:
  • Let’s start with the Wifi Settings. Replace yourssid with the name of your Wifi network and yourpassw0rd with its password. I had problems with a network that contained a dash (“-“) in the SSID. If you’re having problems consider this hint…
  • Next is the update interval. In the default it is set to 600 seconds or 10 minutes in other words. In my experience this is a good value, because you don’t have unlimited requests in your free Wunderground API account…
  • Now to the display settings. If you attach the display as I show on the next page you don’t have to change anything here. D3 and D4 are the pin names of the NodeMCU module. If you get compilation errors about them make sure that you have set your board to NodeMCU V1.0. If you have one of course;-). If you have another board just replace them with the proper pin number, e.g. “5” or “6”.
  • Use Time Client Settings section to adjust your local time zone offset compared to UTC time zone. It allows also half an hour offset, thanks to the user who made me implement that… (Ignorance is a bliss until you get confronted with it…)
  • In the Wunderground section you can now use the API key you received in the previous section. Also set the country and city of the place you want to show. To figure out which values work you can modify this URL: http://api.wunderground.com/api/3APIKEY/conditions/q/CA/San_Francisco.json and replace APIKEY with yours and “CA” and “San_Francisco” with your state or country and city.
  • For the moment ignore the ThingSpeak settings. We will use them for a later extension…

Now we are almost ready to get the weather station running on the ESP8266 for the first time. But we need to wire the display to the NodeMCU first… Read the next chapter after the break…

< Chapter 1 Chapter 3 >

17 comments
  1. Thanks Dani for this beautiful article. I managed with a ESP8266 -01.It works with charm. we can add a GPS ,so that no need to set the location.
    Can I write an Instructables on it ?I need your permission.

    • Hi! I'm glad that u liked it! Sure, go ahead with the instructable. It would be nice if you'd link to this blog and maybe the github repo on the first step for credits;-)

    • I had this same error for all of the methods. This seems to be due to the lack of Arduino C++ prototyping. Thus, to fix it you need to add prototypes manually before the initial method calls. TL;DR: Add "void drawFrame1(int x, int y);" somewhere in the very beginning of your code.

    • Thanks Juho, I was about ready to give up until I read this, and it cleared up the problem. I am using 1.6.7 IDE the the latest ESP8266 Stable core release. It WORKS for the OLED DEMO. I'll try it now for the Weather Station

    • I still get the errors

      C:UsersSusiDesktopWeatherStationDemoWeatherStationDemo.ino: In function 'void setup()':

      WeatherStationDemo:140: error: 'frames' was not declared in this scope

      ui.setFrames(frames, numberOfFrames);

      ^

      WeatherStationDemo:140: error: 'numberOfFrames' was not declared in this scope

      ui.setFrames(frames, numberOfFrames);

      ^

      exit status 1
      'frames' was not declared in this scope

  2. Hi Daniel,
    as in your code:
    const int SDA_PIN = D3;
    const int SDC_PIN = D4;
    where did you define D3 and D4? I can't find it anywhere. The SSD1306 constructor seems accept integer values.

    • // Display Settings

      const int I2C_DISPLAY_ADDRESS = 0x3c;
      const int SDA_PIN = D3;
      const int SDC_PIN = D4;

      /////

      SSD1306 display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);

  3. Hey,

    Trying to build the weather station. Getting stuck at SSD1306.h library. Arduino IDE say it is missing. Can you point me to the library or how to install? Can I substitute the Adafruit_SSD1306 library?

    Thanks.

    Tim

  4. Hallo !
    Weather Station mit BMP funktioniert, jedoch würde ich gerne die Daten an FHEM senden. von Thingspeak zu FHEM, kann mir einer sagen wie das geht ?? Dank vorab ! THX
    wie defeniere ich das den in FHEM ??

  5. I sent you a "beer" via PayPal! After A LOT of reading you seem to be the only person that can clearly communicate how someone can connect an ESP-12E to an SSD1306 OLED with I2C via Arduino's IDE, while also providing a library to make it work. THANK YOU! Side note (and I may just not be understanding something) but you mentioned D4 and D3 in your post but the SSD1306Demo example defines them as D2 and D4. Figured out but maybe that is something to be revised? THANK YOU AGAIN!!!

    • And now that I think about it your WeatherStationConig is probably different than the example sketch, so never mind! Thanks again and please share more!

Comments are closed.