Sie sind auf Seite 1von 7

instructables

ESP8266 NodeMCU With BME280 Gauges & Chart

by optio50

Fancy Gauges and Chart for your ESP8266 Breadboard Jumpers ($3.09 from Banggood.com
NodeMCU Development board with BME280 Hong Kong)
Temperature, Humidity and Pressure sensor.
Thingspeak will store all your data in the cloud for Breadboard ($2.28 from Banggood.com Hong Kong)
retrieval at any time for years (hopefully) to come.
The gauges and chart are populated from the data Power Supply, Free if you have a micro USB phone
stored at thingspeak and are updated automatically charger
every 5 minuets.
Micro USB cable, Free if you have one already
Needed Items:
Arduino IDE, Free Download
ESP8266 NodeMCU Development board ($3.79 from
Banggood.com Hong Kong) Get the .ino & .HTML code files here
https://github.com/optio50/ESP8266-NodeMCU-12E-
Bosch BME280 ($5.63 from Banggood.com Hong with-BME280
Kong)

ESP8266 NodeMCU With BME280 Gauges & Chart: Page 1


Step 1: Create & Setup Your Thingspeak Channels

1. Create a free Thingspeak account and new 2. The new channel should have 3 fields named
channel at https://thingspeak.com , Call the channel Temperature Humidity Pressure in that specific order
"ESP8266-NodeMCU-12E-BME280" (Note First Letter capitalization).

3. Take note of your new "channel ID" XXXXXX 6. This new channel should have 6 fields named
under "Channel Settings" Tmax Tmin Hmax Hmin Pmax Pmin in that specific
order (Note First Letter capitalization).
4. Click the "API Keys" link and take note of your
"API Write" and "Read API Keys" 7. Take note of the "BME280 Daily High Low Data"
XXXXXXXXXXXXXXX. Also, make this a public "channel ID" , "Read" & "Write API keys" just like in
channel under sharing. the above steps.

5. Create a second Thingspeak channel that will hold


the "Today" (since midnight) High Low data. Call it
"BME280 Daily High Low Data"

Step 2: Setup the Arduino IDE, Libraries and Configure the BME280

ESP8266 NodeMCU With BME280 Gauges & Chart: Page 2


8. Follow the instructions for installing the Arduino words Adafruit BME280 Library in the search box.
IDE & ESP8266 core at http://easy-esp.com/getting- The one you want says "Adafruit BME280 Library by
started-with-easyesp-... Adafruit"

9. Fire up the Arduino IDE so we can install the four 12. Another library you need is Wire.h , install it in the
libraries we will need. "Library Manager" in Arduino IDE. Menu, Sketch -->
Include Library --> Manage Libraries Do a search by
10. You will need the "Adafruit Unified Sensor Driver" Type = "Contributed" Topic = "Signal Input/Output"
library, install it in the "Library Manager" in Arduino then put the word Wire in the search box. The one
IDE. Menu Sketch --> Include Library --> Manage you want says "Wire Built-in by Arduino" Most likely
Libraries do a search by Type = "Recommended" at the bottom of the selection.
Topic = "Sensors" then put the words Adafruit Unified
Sensor Driver in the search box. The one you want 13. One more library, ESP8266WiFi , install it in the
says "Adafruit Unified Sensor Driver by Adafruit" "Library Manager" in Arduino IDE. Menu, Sketch -->
Include Library --> Manage Libraries Do a search by
11. In addition, you will also require the "Adafruit Type = "Contributed" Topic = "Communication" then
BME280 Library" install it in the "Library Manager" in put the word ESP8266wifi in the search box. The one
Arduino IDE. Menu Sketch --> Include Library --> you want says "ESP8266wifi Built-in by Ivan
Manage Libraries do a search by Type = Grokhotkov"
"Recommended" Topic = "Sensors" then put the

14. The I2C address for BME280 is hardcoded in the ESP8266-NodeMCU-12E-BME280.html file in a text
Adafruit_BME280.h file (look for the line #define editor and enter your "ESP8266-NodeMCU-12E-
BME280_ADDRESS 0x77) inside the BME280" (The first channel you created) "Channel
Adafruit_BME280_Library folder. Adafruit’s BME ID" & "Read API Key" for the variables key1 & chan1.
sensor modules are hard-wired to use the I2C Also enter the "Read API Key" and "Channel ID" for
address of 0x77. But the BME280 can have a slightly "BME280 Daily High Low Data" (The second channel
different I2C address (0x76) if its external SDO pin is you created) for key2 and chan2. In addition, enter
grounded. If you are using the sensor modules from a your timezone offset from UTC. As in -5 for me. All
third party, it is likely that it’s address would not the values must be inside the provided single quotes
match with the default value in the Adafruit library. 'XXXXX'. Save and exit the text editor.
For example, for most of the BME280 sensor
modules available on eBay or Aliexpress have their Plug in your ESP8266 with the USB cable to your
I2C address to be 0x76. If you dont get a response computer then select your serial port to be the USB
from the sensor using the default address set in the port.
Adafruit_BME280.h file, you might need to change it
to 0x76. Linux users may have to change ownwership of the
USB port to communicate with the /dev/ttyUSB0 as in
BME280 & ESP8266 Connection Points. ESP8266 'sudo chown yourusername /dev/ttyUSB0' or what
3.3V to BME280 Vin, ESP8266 GND to BME280 ever you selected as your port in setup.
GND, ESP8266 D4 to BME280 SCL, ESP8266 D3 to
BME280 SDA. 15. Open the provided

ESP8266 NodeMCU With BME280 Gauges & Chart: Page 3


Step 3: Program the ESP8266 With the Arduino IDE

16. Next we will program the ESP8266. Connect a "Password" into the correct section of the sketch.
USB cable between your ESP8266 and your Then click menu item "Sketch" & "Upload". After you
computer. upload the sketch (Progress reaches 100%) to your
ESP8266 you can open the serial monitor (Icon top
Load the provided New_BME_Sensor.ino file into the right looks like a magnifiying glass) and see your data
Arduino IDE. Your BME280 sensor should be hooked print out after 5 Minutes, every 5 Minutes. The data
to D3 (SDA) & D4 (SCL) on the ESP8266. Enter your gets sent to thingspeak at 5 min intervals so it will be
"ESP8266-NodeMCU-12E-BME280" (The first some time before you have meaningful chart data but
channel you created) "Write Key" "Wireless SSID" & you should have gauge readings after 5 min.

Make sure you get a correct readings from the Wait a few minuets till the next reading and verify the
BME280 in the serial monitor. readings look good.

The first measurement will likely be an invalid nan.

ESP8266 NodeMCU With BME280 Gauges & Chart: Page 4


Step 4: Go Back to the Thingspeak to Do Some Data Tweaking

17. Now, While the data is slowly uploading to writeNewChannelID & writeAPIKey respectivly. I
thingspeak lets do some tweaking to get some know it sounds confusing (read it again). Click save
additional data from whats being uploaded. Go back and run. If you did it correcty and the read channel is
to the thingspeak website and in the Thingspeak public you will see no errors and it successfully prints
"BME280 Daily High Low Data" channel page (The the values. Note, You may see an error if no data has
second channel you created) click the green been uploaded to that channel yet. Despite the error
"MATLAB Analysis" button. Select Template "Custom continue. If desired you can revisit Click save and run
(No Starter Code)" to make sure it works once data has been uploaded.

18. Name the MATLAB Analysis "Calculate Min Max 20. Next, we need to create a "Time Control" to fire
Since Midnight". this code every 5 min and our data gets written to the
channel "BME280 Daily High Low Data" (The second
19. Copy the MATLAB Analysis.txt code into the channel you created). From the main page of
provided space. Enter the "channel ID" for "BME280 Daily High Low Data" (The second channel
"ESP8266-NodeMCU-12E-BME280" (The first you created) select Apps at the top. Under actions
channel you created) into "readChannelID". Enter the select "TimeControl" then the Green button "New
"BME280 Daily High Low Data" (The second channel TimeControl". Name it "Send High Low Temps
you created) Write "Channel ID" & "Write Key" into ESP8266". Select your time zone if needed and

select "Recurring" under Frequency. Select Minute is "Calculate Min Max Since Midnight". Save
under Recurrence. Set to run every 5 Minutes. Action TimeControl.
should be MATLAB Analysis and "Code to Execute"

ESP8266 NodeMCU With BME280 Gauges & Chart: Page 5


Step 5: Edit the Provided HTML File

Edit the HTML files and look for comments that say some timing issues to be aware of. You likely will not
"******** Change Me 1 of 8 *********" Change these have the absolute most current data but it should
to your preference. always be less than 5 Minutes old. This comes from
when the timing control gets fired, When the data was
Notes: sent from the ESP8266 and when you loaded /
refreshed the web page.
Some of the text fields and the weekly chart will not
populate correctly until you have a full day and full Open the provided ESP8266-NodeMCU-12E-
week of data for the 24 Hr and Week section and BME280.html file in your web browser and you
chart. should see the gauges and chart populated.
Once you have a bunch of data you can zoom in on
the charts with the mouse wheel (Right Click to Get the .ino & .HTML code files here
Reset). You can also have a fourth gauge (as seen in https://github.com/optio50/ESP8266-NodeMCU-12E-
the screenshots) from another sensor from another with-BME280
channel but I have commeted out the relevant
portions. If you feel savy, hook it up. There is also

ESP8266 NodeMCU With BME280 Gauges & Chart: Page 6


ESP8266 NodeMCU With BME280 Gauges & Chart: Page 7

Das könnte Ihnen auch gefallen