Updated Wemos shield usermod (#880)
* Added support for H803FW controller * Create usermod_bme280.cpp * Create usermod_bme280.cpp * Added BME280 sensor * Update readme.md * Update usermod_bme280.cpp * Update platformio.ini * Update for lightweight sensor
This commit is contained in:
parent
94c5f0d7a8
commit
6ade40ce85
@ -37,6 +37,7 @@ default_envs = d1_mini, esp01, esp01_1m_ota, esp32dev
|
|||||||
; default_envs = esp8285_4CH_H801
|
; default_envs = esp8285_4CH_H801
|
||||||
; default_envs = esp8285_5CH_H801
|
; default_envs = esp8285_5CH_H801
|
||||||
; default_envs = d1_mini_5CH_Shojo_PCB
|
; default_envs = d1_mini_5CH_Shojo_PCB
|
||||||
|
; default_envs = wemos_shield_esp32
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -155,8 +156,7 @@ lib_deps =
|
|||||||
#For use SSD1306 OLED display uncomment following
|
#For use SSD1306 OLED display uncomment following
|
||||||
#U8g2@~2.27.2
|
#U8g2@~2.27.2
|
||||||
#For Dallas sensor uncomment following 2 lines
|
#For Dallas sensor uncomment following 2 lines
|
||||||
DallasTemperature@~3.8.0
|
#OneWire@~2.3.5
|
||||||
OneWire@~2.3.5
|
|
||||||
#For BME280 sensor uncomment following
|
#For BME280 sensor uncomment following
|
||||||
#BME280@~3.0.0
|
#BME280@~3.0.0
|
||||||
lib_ignore =
|
lib_ignore =
|
||||||
@ -302,3 +302,14 @@ build_flags = ${common.build_flags_esp32} -D LEDPIN=16
|
|||||||
lib_ignore =
|
lib_ignore =
|
||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
ESPAsyncUDP
|
ESPAsyncUDP
|
||||||
|
|
||||||
|
[env:wemos_shield_esp32]
|
||||||
|
board = esp32dev
|
||||||
|
platform = espressif32@1.11.2
|
||||||
|
upload_port = /dev/cu.SLAB_USBtoUART
|
||||||
|
monitor_port = /dev/cu.SLAB_USBtoUART
|
||||||
|
upload_speed = 460800
|
||||||
|
build_flags = ${common.build_flags_esp32} -D LEDPIN=16 -D RLYPIN=19 -D BTNPIN=17
|
||||||
|
lib_ignore =
|
||||||
|
ESPAsyncTCP
|
||||||
|
ESPAsyncUDP
|
||||||
|
@ -1,24 +1,49 @@
|
|||||||
#include "wled.h"
|
#include "wled.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
|
#include <U8x8lib.h> // from https://github.com/olikraus/u8g2/
|
||||||
#include <DallasTemperature.h> //Dallastemperature sensor
|
#include <OneWire.h> // Dallas temperature sensor
|
||||||
#ifdef ARDUINO_ARCH_ESP32 //ESP32 boards
|
|
||||||
|
//Dallas sensor quick reading. Credit to - Author: Peter Scargill, August 17th, 2013
|
||||||
|
int16_t Dallas(int x, byte start)
|
||||||
|
{
|
||||||
|
OneWire DallasSensor(x);
|
||||||
|
byte i;
|
||||||
|
byte data[2];
|
||||||
|
int16_t result;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
DallasSensor.reset();
|
||||||
|
DallasSensor.write(0xCC);
|
||||||
|
DallasSensor.write(0xBE);
|
||||||
|
for ( i = 0; i < 2; i++) data[i] = DallasSensor.read();
|
||||||
|
result=(data[1]<<8)|data[0];
|
||||||
|
result>>=4; if (data[1]&128) result|=61440;
|
||||||
|
if (data[0]&8) ++result;
|
||||||
|
DallasSensor.reset();
|
||||||
|
DallasSensor.write(0xCC);
|
||||||
|
DallasSensor.write(0x44,1);
|
||||||
|
if (start) delay(1000);
|
||||||
|
} while (start--);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
uint8_t SCL_PIN = 22;
|
uint8_t SCL_PIN = 22;
|
||||||
uint8_t SDA_PIN = 21;
|
uint8_t SDA_PIN = 21;
|
||||||
OneWire oneWire(23);
|
uint8_t DALLAS_PIN =23;
|
||||||
#else //ESP8266 boards
|
#else
|
||||||
uint8_t SCL_PIN = 5;
|
uint8_t SCL_PIN = 5;
|
||||||
uint8_t SDA_PIN = 4;
|
uint8_t SDA_PIN = 4;
|
||||||
|
uint8_t DALLAS_PIN =13;
|
||||||
// uint8_t RST_PIN = 16; // Uncoment for Heltec WiFi-Kit-8
|
// uint8_t RST_PIN = 16; // Uncoment for Heltec WiFi-Kit-8
|
||||||
OneWire oneWire(13);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//The SCL and SDA pins are defined here.
|
//The SCL and SDA pins are defined here.
|
||||||
//ESP8266 Wemos D1 mini board use SCL=5 SDA=4 while ESP32 Wemos32 mini board use SCL=22 SDA=21
|
//ESP8266 Wemos D1 mini board use SCL=5 SDA=4 while ESP32 Wemos32 mini board use SCL=22 SDA=21
|
||||||
#define U8X8_PIN_SCL SCL_PIN
|
#define U8X8_PIN_SCL SCL_PIN
|
||||||
#define U8X8_PIN_SDA SDA_PIN
|
#define U8X8_PIN_SDA SDA_PIN
|
||||||
//#define U8X8_PIN_RESET RST_PIN // Uncoment for Heltec WiFi-Kit-8
|
//#define U8X8_PIN_RESET RST_PIN // Uncoment for Heltec WiFi-Kit-8
|
||||||
// Dallas sensor
|
|
||||||
DallasTemperature sensor(&oneWire);
|
// Dallas sensor reading timer
|
||||||
long temptimer = millis();
|
long temptimer = millis();
|
||||||
long lastMeasure = 0;
|
long lastMeasure = 0;
|
||||||
#define Celsius // Show temperature mesaurement in Celcius otherwise is in Fahrenheit
|
#define Celsius // Show temperature mesaurement in Celcius otherwise is in Fahrenheit
|
||||||
@ -36,7 +61,9 @@ U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(U8X8_PIN_NONE, U8X8_PIN_SCL, U8X8_PIN_
|
|||||||
//U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(U8X8_PIN_RESET, U8X8_PIN_SCL, U8X8_PIN_SDA); // Constructor for Heltec WiFi-Kit-8
|
//U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(U8X8_PIN_RESET, U8X8_PIN_SCL, U8X8_PIN_SDA); // Constructor for Heltec WiFi-Kit-8
|
||||||
// gets called once at boot. Do all initialization that doesn't depend on network here
|
// gets called once at boot. Do all initialization that doesn't depend on network here
|
||||||
void userSetup() {
|
void userSetup() {
|
||||||
sensor.begin(); //Start Dallas temperature sensor
|
//Serial.begin(115200);
|
||||||
|
|
||||||
|
Dallas (DALLAS_PIN,1);
|
||||||
u8x8.begin();
|
u8x8.begin();
|
||||||
u8x8.setPowerSave(0);
|
u8x8.setPowerSave(0);
|
||||||
u8x8.setFlipMode(1);
|
u8x8.setFlipMode(1);
|
||||||
@ -77,18 +104,17 @@ void userLoop() {
|
|||||||
//Check if MQTT Connected, otherwise it will crash the 8266
|
//Check if MQTT Connected, otherwise it will crash the 8266
|
||||||
if (mqtt != nullptr)
|
if (mqtt != nullptr)
|
||||||
{
|
{
|
||||||
sensor.requestTemperatures();
|
// Serial.println(Dallas(DALLAS_PIN,0));
|
||||||
//Gets prefered temperature scale based on selection in definitions section
|
//Gets prefered temperature scale based on selection in definitions section
|
||||||
#ifdef Celsius
|
#ifdef Celsius
|
||||||
float board_temperature = sensor.getTempCByIndex(0);
|
int16_t board_temperature = Dallas(DALLAS_PIN,0);
|
||||||
#else
|
#else
|
||||||
float board_temperature = sensor.getTempFByIndex(0);
|
int16_t board_temperature = (Dallas(DALLAS_PIN,0)* 1.8 + 32);
|
||||||
#endif
|
#endif
|
||||||
//Create character string populated with user defined device topic from the UI, and the read temperature. Then publish to MQTT server.
|
//Create character string populated with user defined device topic from the UI, and the read temperature. Then publish to MQTT server.
|
||||||
char subuf[38];
|
String t = String(mqttDeviceTopic);
|
||||||
strcpy(subuf, mqttDeviceTopic);
|
t += "/temperature";
|
||||||
strcat(subuf, "/temperature");
|
mqtt->publish(t.c_str(), 0, true, String(board_temperature).c_str());
|
||||||
mqtt->publish(subuf, 0, true, String(board_temperature).c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,10 +156,10 @@ void userLoop() {
|
|||||||
lastRedraw = millis();
|
lastRedraw = millis();
|
||||||
|
|
||||||
// Update last known values.
|
// Update last known values.
|
||||||
#if defined(ESP8266)
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
knownSsid = apActive ? WiFi.softAPSSID() : WiFi.SSID();
|
|
||||||
#else
|
|
||||||
knownSsid = WiFi.SSID();
|
knownSsid = WiFi.SSID();
|
||||||
|
#else
|
||||||
|
knownSsid = apActive ? WiFi.softAPSSID() : WiFi.SSID();
|
||||||
#endif
|
#endif
|
||||||
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
|
knownIp = apActive ? IPAddress(4, 3, 2, 1) : WiFi.localIP();
|
||||||
knownBrightness = bri;
|
knownBrightness = bri;
|
||||||
|
Loading…
Reference in New Issue
Block a user