Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
93 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,3 +3,5 @@ | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/settings.json | ||
src/config.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Sense | ||
Building HVAC sensor experimentation | ||
|
||
## Building | ||
|
||
Platform IO is used for this project. VSCode is recommeded for development. | ||
|
||
A `config.h` file must be created in order to build the project. `config.h`. | ||
|
||
|
||
```c++ | ||
// Config.h example | ||
#define WIFI_PASSWORD "test-password" | ||
#define WIFI_SSID "test-ssid" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -12,5 +12,8 @@ | ||
platform = espressif8266 | ||
board = nodemcuv2 | ||
framework = arduino | ||
lib_ldf_mode=2 | ||
lib_deps = | ||
562 | ||
562 | ||
BME280 | ||
617 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,192 +1,103 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn | ||
* Copyright (c) 2018 by Fabrice Weinberg | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
* ThingPulse invests considerable time and money to develop these open source libraries. | ||
* Please support us by buying our products (and not the clones) from | ||
* https://thingpulse.com | ||
* | ||
*/ | ||
|
||
// Include the correct display library | ||
// For a connection via I2C using Wire include | ||
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier | ||
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"` | ||
// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"` | ||
// For a connection via I2C using brzo_i2c (must be installed) include | ||
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier | ||
// #include "SSD1306Brzo.h" | ||
// #include "SH1106Brzo.h" | ||
// For a connection via SPI include | ||
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier | ||
// #include "SSD1306Spi.h" | ||
// #include "SH1106SPi.h" | ||
|
||
// Include custom images | ||
#include "images.h" | ||
|
||
// Initialize the OLED display using SPI | ||
// D5 -> CLK | ||
// D7 -> MOSI (DOUT) | ||
// D0 -> RES | ||
// D2 -> DC | ||
// D8 -> CS | ||
// SSD1306Spi display(D0, D2, D8); | ||
// or | ||
// SH1106Spi display(D0, D2); | ||
|
||
// Initialize the OLED display using brzo_i2c | ||
// D3 -> SDA | ||
// D5 -> SCL | ||
// SSD1306Brzo display(0x3c, D3, D5); | ||
// or | ||
// SH1106Brzo display(0x3c, D3, D5); | ||
|
||
// Initialize the OLED display using Wire library | ||
SSD1306Wire display(0x3c, D3, D5); | ||
// SH1106 display(0x3c, D3, D5); | ||
#include "SD.h" | ||
#include "ESP8266WiFi.h" | ||
#include <string.h> | ||
#include "config.h" | ||
#include "BME280I2C.h" | ||
|
||
const char *ssid = WIFI_SSID; | ||
const char *password = WIFI_PASSWORD; | ||
|
||
#define DEMO_DURATION 3000 | ||
typedef void (*Demo)(void); | ||
BME280I2C bme; // Default : forced mode, standby time = 1000 ms | ||
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off, | ||
|
||
int demoMode = 0; | ||
int counter = 1; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.println(); | ||
Serial.println(); | ||
|
||
// Initialize the OLED display using Wire library | ||
SSD1306Wire display(0x3c, D3, D5); | ||
|
||
// Initialising the UI will init the display too. | ||
display.init(); | ||
|
||
display.flipScreenVertically(); | ||
void displayText(const String text) { | ||
display.clear(); | ||
display.setTextAlignment(TEXT_ALIGN_LEFT); | ||
display.setFont(ArialMT_Plain_10); | ||
|
||
display.drawStringMaxWidth(0, 0, 128, text); | ||
display.display(); | ||
} | ||
|
||
void drawFontFaceDemo() { | ||
// Font Demo1 | ||
// create more fonts at http://oleddisplay.squix.ch/ | ||
display.setTextAlignment(TEXT_ALIGN_LEFT); | ||
display.setFont(ArialMT_Plain_10); | ||
display.drawString(0, 0, "Hello world"); | ||
display.setFont(ArialMT_Plain_16); | ||
display.drawString(0, 10, "Hello world"); | ||
display.setFont(ArialMT_Plain_24); | ||
display.drawString(0, 26, "Hello world"); | ||
} | ||
void printBME280Data() | ||
{ | ||
float temp(NAN), hum(NAN), pres(NAN); | ||
|
||
void drawTextFlowDemo() { | ||
display.setFont(ArialMT_Plain_10); | ||
display.setTextAlignment(TEXT_ALIGN_LEFT); | ||
display.drawStringMaxWidth(0, 0, 128, | ||
"Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." ); | ||
} | ||
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); | ||
BME280::PresUnit presUnit(BME280::PresUnit_Pa); | ||
|
||
void drawTextAlignmentDemo() { | ||
// Text alignment demo | ||
display.setFont(ArialMT_Plain_10); | ||
bme.read(pres, temp, hum, tempUnit, presUnit); | ||
|
||
// The coordinates define the left starting point of the text | ||
display.setTextAlignment(TEXT_ALIGN_LEFT); | ||
display.drawString(0, 10, "Left aligned (0,10)"); | ||
String data_str = ""; | ||
data_str += "Temp: "; | ||
data_str += temp; | ||
data_str += "°"+ String(tempUnit == BME280::TempUnit_Celsius ? 'C' :'F'); | ||
data_str += "\n Humidity: "; | ||
data_str += hum; | ||
data_str += "% RH"; | ||
data_str += "\n Pressure: "; | ||
data_str += pres; | ||
data_str += "Pa"; | ||
|
||
// The coordinates define the center of the text | ||
display.setTextAlignment(TEXT_ALIGN_CENTER); | ||
display.drawString(64, 22, "Center aligned (64,22)"); | ||
|
||
// The coordinates define the right end of the text | ||
display.setTextAlignment(TEXT_ALIGN_RIGHT); | ||
display.drawString(128, 33, "Right aligned (128,33)"); | ||
displayText(data_str); | ||
} | ||
|
||
void drawRectDemo() { | ||
// Draw a pixel at given position | ||
for (int i = 0; i < 10; i++) { | ||
display.setPixel(i, i); | ||
display.setPixel(10 - i, i); | ||
} | ||
display.drawRect(12, 12, 20, 20); | ||
void setup() { | ||
Serial.begin(9600); | ||
delay(100); | ||
|
||
// Fill the rectangle | ||
display.fillRect(14, 14, 17, 17); | ||
// Initialising the UI will init the display too. | ||
display.init(); | ||
display.flipScreenVertically(); | ||
|
||
// Draw a line horizontally | ||
display.drawHorizontalLine(0, 40, 20); | ||
// Open wifi connection to home wifi | ||
WiFi.begin(ssid, password); | ||
|
||
String conn_message = "Connecting to "; | ||
conn_message += ssid; | ||
|
||
// Draw a line horizontally | ||
display.drawVerticalLine(40, 0, 20); | ||
} | ||
displayText(conn_message.c_str()); | ||
Serial.println(conn_message); | ||
|
||
void drawCircleDemo() { | ||
for (int i=1; i < 8; i++) { | ||
display.setColor(WHITE); | ||
display.drawCircle(32, 32, i*3); | ||
if (i % 2 == 0) { | ||
display.setColor(BLACK); | ||
} | ||
display.fillCircle(96, 32, 32 - i* 3); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
delay(500); | ||
conn_message += "."; | ||
Serial.println(conn_message); | ||
displayText(conn_message); | ||
} | ||
} | ||
|
||
void drawProgressBarDemo() { | ||
int progress = (counter / 5) % 100; | ||
// draw the progress bar | ||
display.drawProgressBar(0, 32, 120, 10, progress); | ||
Serial.println(""); | ||
Serial.println("Wifi connected"); | ||
displayText("Wifi connected"); | ||
|
||
// draw the percentage as String | ||
display.setTextAlignment(TEXT_ALIGN_CENTER); | ||
display.drawString(64, 15, String(progress) + "%"); | ||
} | ||
while(!bme.begin()) | ||
{ | ||
Serial.println("Could not find BME280 sensor!"); | ||
delay(1000); | ||
} | ||
|
||
void drawImageDemo() { | ||
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html | ||
// on how to create xbm files | ||
display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits); | ||
switch(bme.chipModel()) | ||
{ | ||
case BME280::ChipModel_BME280: | ||
Serial.println("Found BME280 sensor! Success."); | ||
break; | ||
case BME280::ChipModel_BMP280: | ||
Serial.println("Found BMP280 sensor! No Humidity available."); | ||
break; | ||
default: | ||
Serial.println("Found UNKNOWN sensor! Error!"); | ||
|
||
} | ||
} | ||
|
||
Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo}; | ||
int demoLength = (sizeof(demos) / sizeof(Demo)); | ||
long timeSinceLastModeSwitch = 0; | ||
|
||
void loop() { | ||
// clear the display | ||
display.clear(); | ||
// draw the current demo method | ||
demos[demoMode](); | ||
|
||
display.setTextAlignment(TEXT_ALIGN_RIGHT); | ||
display.drawString(10, 128, String(millis())); | ||
// write the buffer to the display | ||
display.display(); | ||
|
||
if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) { | ||
demoMode = (demoMode + 1) % demoLength; | ||
timeSinceLastModeSwitch = millis(); | ||
} | ||
counter++; | ||
printBME280Data(); | ||
delay(10); | ||
} |