[DEPRECATED] ST_Anything - Arduino/ESP8266/ESP32

Oh wow! I should have seen that a while ago and I am sorry that I didn’t catch it sooner!

You simply need to F() your strings!!! Take a look below and you’ll see where I added the F() around the 1st argument. This is used to store strings in flash memory, instead of precious RAM. We did this as a memory optimization for the Arduino UNO as it only has 2KB of RAM.

  //Polling Sensors 
  static st::PS_TemperatureHumidity sensor2(F("temphumid1"), 120, 7, PIN_TEMPERATUREHUMIDITY, st::PS_TemperatureHumidity::DHT11,"temperature1","humidity1");

Try this line of code and let me know if it works. Every example sketch has the F() nomenclature, which is where I assume most people start their ST_Anything journey. Sorry for the confusion!

Hendre,

I have tweaked the “Child Ultrasonic Sensor” sensor to fix the input field’s description from radius to diameter. I have also exposed the custom attribute “ultrasonic” which will allow you to use the numeric value of the water level (in %) in a webCoRE rule. I just tested this and it seems to work fine. Update from the GitHub integration.

You may need to remove the sensor from webCoRE, save webCoRE settings, and then r-add it back in to allow webCORE to learn of the new custom attribute.

I’ll take a look at your “Car Presence Sensor” version next… stay tuned…

Dan

1 Like

Not a big deal but the Child Temperature DH has no logic to chose between the tile colors between Celsius and Fahrenheit. I use Fahrenheit so whats happening is when the temp goes below 40F the colors start using the Celsius Colors.

Existing DH…
backgroundColors: [
// Celsius
[value: 0, color: “#153591”],
[value: 7, color: “#1e9cbb”],
[value: 15, color: “#90d2a7”],
[value: 23, color: “#44b621”],
[value: 28, color: “#f1d801”],
[value: 35, color: “#d04e00”],
[value: 37, color: “#bc2323”],
// Fahrenheit
[value: 40, color: “#153591”],
[value: 44, color: “#1e9cbb”],
[value: 59, color: “#90d2a7”],
[value: 74, color: “#44b621”],
[value: 84, color: “#f1d801”],
[value: 95, color: “#d04e00”],
[value: 96, color: “#bc2323”]

My solution was to delete the Celsius portion and add some more Fahrenheit
colors below 40F.
// Fahrenheit
[value: 0, color: “#D3D3D3”], // Light Gray
[value: 15, color: “#ea93e2”], // Pink
[value: 25, color: “#911486”], // Purple
[value: 35, color: “#153591”], // Dark Blue
[value: 44, color: “#1e9cbb”], // Light Blue
[value: 59, color: “#90d2a7”], // Light Green
[value: 74, color: “#44b621”], // Dark Green
[value: 84, color: “#f1d801”], // Dark Yellow
[value: 92, color: “#d04e00”], // Orange
[value: 96, color: “#bc2323”] // Red

Yea, having both F and C temperatures/colors was a compromise I found in other DTH’s that support temp conversion. If anyone knows of a better method, I am all ears.

(Plus, I live in North Carolina, so temps below 40 F don’t occur all that often. :wink: )

Just throwing it out there. For the car presence sensor, if you can get a sensor that reports feet or inches or meters or whatever back as voltage, you could use the existing voltage class with a new DTH and just have a preference item that says “Presence is considered any value lower then this value” and then someone can manually put in say 7 feet (or whatever measurement unit). Anything less then this would make the space presence go to present and anything more and its not present.

We use the same sensors in my industry to detect water levels (or lack there of) and get back a voltage reading related to inches. Then we program some logic that says “if inches less then xx then water level high else if less then yy water level normal else water level low” and then act on it if needed (water fill valve, drain valve, etc).

Not sure if this helps or not, you probably already thought about it, but it makes sense and should be “easy”.

Yes, that is exactly how I was going to write the Child DH. Just simply compare a value against a target to determine the status of Presence.

It really doesn’t matter what type of sensor is used, as long as a numeric value is sent to the Child DH. I should have something ready tomorrow.

@949BFN, @vseven

Hendre,

I have created a new Child Device Handler called “Child Presence Sensor” which is now available in the ST_Anything GitHub repository. You will also need to update the Parent Ethernet Device Handler as well.

In order for this Child Device to appear, the ESP8266 device’s sketch will need to send updates to a device named “presence1” (or “presence2”, “presence3”, etc…) This name is what the Parent DTH uses to determine which type of child device to create. Below is an example sketch that demonstrates this naming convention.

The new “Child Presence Sensor” device also exposes a custom attribute called “level” which is the RAW numeric value sent from ST_Anything to SmartThings. This means you can use this value in an app like webCoRE if you’d like.

In this sketch, which is a continuation of the previous example we created together, you will see that three ST_Anything devices are being created. You can remove any that aren’t needed for your project. You should be able to use one NodeMCU ESP8266 for both garage stalls. Just define unique pin assignments.

  //Polling Sensors
  static st::PS_Ultrasonic  sensor1(F("ultrasonic1"), 60, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E);
  static st::PS_Ultrasonic  sensor2(F("presence1"), 60, 5, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E);
  static st::PS_Voltage     sensor3(F("presence2"), 15, 1, PIN_ANALOG, 0, 1023, 0, 100);

The first one should look very familiar to you. Nothing has changed, and it will still cause an “Child Ultrasonic Sensor” to be created and updated, just like before. This is because of the first argument, the name, which is “ultrasonic1” (i.e. the first ultrasonic child device).

The second one is exactly the same as the first, BUT the name is now “presence1”, which will cause a new Child Presence Sensor child device to be created and updated. This new child MUST be configured by you in the child’s settings page. The settings are the “Presence Trigger Value” (numeric) and the “Invert Logic” (boolean). With these two settings, you can determine what value will change the presence from “present” to “not present”, and if the logic should check for presence above or below the trigger value.

The third one demonstrates the creation of a second “Child Presence Device”, but this one is driven by an analog input’s voltage reading, not the ultrasonic distance measurement sensor you’ve been using. This is what Allen was describing above as an option. It uses an st::PS_Voltage device instead of the st::PS_Ultrasonic device. Since both devices simply transmit a numeric value, the Child Device Handler doesn’t care who sends the data, as long as they call themselves “presence1” (or “presence2”, “presence3”, etc…) Hopefully this is making sense.

So, at this point, I think you have everything you need to create your Ultrasonic Distance based Garage Occupancy Sensors.

@vseven Allen - FYI - the new “Child Presence Sensor” will accept numeric values, or the strings “present” and “not_present” as values. If numeric, it does the comparison against the optional settings for the child device. If non-numeric, it simply uses the string values to update the status.

If anyone finds any issues/bugs, please let me know so we can get them addressed ASAP.

//******************************************************************************************
//  File: ST_Anything_UltrasonicESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one ESP8266 to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the ESP8266's WiFi.
//    
//
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2018-02-25  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP8266WiFi
//******************************************************************************************
#include <SmartThingsESP8266WiFi.h>

//******************************************************************************************
// ST_Anything Library 
//******************************************************************************************
#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input 
#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h>      //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h>        //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h>  //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h>       //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h>        //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

#include <PS_Ultrasonic.h>   //Ultrasonic Distance Measurement Sensor, being used to monitor water level in cylindrical tank
#include <PS_Voltage.h>      //Implements a Polling Sensor (PS) to measure voltage on an analog input pin 

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
//#define LED_BUILTIN 16
//#define BUILTIN_LED 16
//
//#define D0 16  //no internal pullup resistor
//#define D1  5
//#define D2  4
//#define D3  0  //must not be pulled low during power on/reset, toggles value during boot
//#define D4  2  //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15  //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************

#define PIN_ULTRASONIC_T             D1  //digital output to trigger ultrasonic
#define PIN_ULTRASONIC_E             D2  //digital input to read the echo

#define PIN_ANALOG                   A0  //Analog pin to read a voltage

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "yourSSIDhere";                           //  <---You must edit this line!
String str_password = "yourPASSWORDhere";                       //  <---You must edit this line!
IPAddress ip(192, 168, 1, 228);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(192, 168, 1, 1);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(192, 168, 1, 1);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
IPAddress hubIp(192, 168, 1, 149);    // smartthings hub ip     //  <---You must edit this line!
const unsigned int hubPort = 39500;   // smartthings hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors
  static st::PS_Ultrasonic  sensor1(F("ultrasonic1"), 60, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E);
  static st::PS_Ultrasonic  sensor2(F("presence1"), 60, 5, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E);
  static st::PS_Voltage     sensor3(F("presence2"), 15, 1, PIN_ANALOG, 0, 1023, 0, 100);
  
  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //  -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
  //         to prevent communication conflicts with the ST Shield communications
  //*****************************************************************************
  st::Everything::debug=true;
  st::Executor::debug=true;
  st::Device::debug=true;
  st::PollingSensor::debug=true;
  st::InterruptSensor::debug=true;

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings ESP8266WiFi Communications Object
    //STATIC IP Assignment - Recommended
    st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);
 
    //DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
    //st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //Add each sensor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addSensor(&sensor1);
  st::Everything::addSensor(&sensor2);
  st::Everything::addSensor(&sensor3);
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************

  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
  
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}
3 Likes

The changes work great, thank you (once again) Dan.
I now have a piston to warn me via text messages every 10% the level drops below 70% and every 5% the level drops below 30%

How would one format the % and litres reported in the app to only show 1 or 2 decimals? (Currently, it shows about 10 decimals)

I managed to make the following changes to your DTH in order to show the remaining litres as opposed to the water capacity! (It is probably something that would have taken you 2 minutes, but after about 45 minutes of trial and error, I got it going!)

Hope I did not mess up something else, but I’ll know that soon I suppose.

There go my other Sunday plans! Going to try this immediately.

I have updated the “Child Ultrasonic Sensor” which should limit the display to 2 decimal places. Give it a try.

Note - I do not have your “capacity” to “liters” changes, so make sure you keep a copy of those edits so they are not lost once you import the new version from Github.

1 Like

Dan

Very excited about this. Got 1 presence sensor setup so far.

I changed the sketch and wrote it successfully to the device. I’ll be connecting 2 sensors to the device - not sure if my pin setup was done correctly and if that is the reason why only 1 presence sensor child device is created by the Parent Device?

EDIT: I know where I went wrong. I failed to add the second sensor here:

//*****************************************************************************
//Add each sensor to the “Everything” Class
//*****************************************************************************
st::Everything::addSensor(&sensor1);
st::Everything::addSensor(&sensor2);

//******************************************************************************************
//  File: ST_Anything_Ultrasonic_ESP01WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one ESP8266-01 (ESP-01) to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the ESP-01's WiFi.
//    
//            ST_Anything_Multiples implements the following ST Capabilities in multiples of 1 as a demo of what is possible with a single ESP-01
//              - 1 x Ultrasonmic Sensor device (used to monitor water level)
//
//  Note:  The tiny ESP-01 only has 2 GPIO pins, so this example is somewhat limited.  Use the ST_ANything_Multiples_ESP8266WiFi.ino example to see 
//         what else is possible.  As long as you only try using 2 pins, you can use them for whatever you'd like.
//
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2018-02-15  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP8266WiFi
//******************************************************************************************
#include <SmartThingsESP8266WiFi.h>

//******************************************************************************************
// ST_Anything Library 
//******************************************************************************************
#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input 
#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h>      //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h>        //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h>  //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h>       //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h>        //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

#include <PS_Ultrasonic.h>   //Ultrasonic Distance Measurement Sensor, being used to monitor water level in cylindrical tank

//*************************************************************************************************
//ESP01 Pin Definitions - it only has 2 GPIO pins!
//*************************************************************************************************
//#define PIN0  D1
//#define PIN2  D2

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************

#define PIN_ULTRASONIC_T             D6  //digital output to trigger ultrasonic
#define PIN_ULTRASONIC_E             D7  //digital input to read the echo
#define PIN2_ULTRASONIC_T            D8  //digital output to trigger ultrasonic
#define PIN2_ULTRASONIC_E            D9  //digital input to read the echo

//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "Camelot";                           //  <---You must edit this line!
String str_password = "rossouws";                   //  <---You must edit this line!
IPAddress ip(192, 168, 0, 27);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(192, 168, 0, 1);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(192, 168, 0, 1);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings / Hubitat Hub TCP/IP Address
IPAddress hubIp(192, 168, 0, 21);    // smartthings/hubitat hub ip //  <---You must edit this line!

// SmartThings / Hubitat Hub TCP/IP Address: UNCOMMENT line that corresponds to your hub, COMMENT the other
const unsigned int hubPort = 39500;   // smartthings hub port
//const unsigned int hubPort = 39501;   // hubitat hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors
  //static st::PS_Ultrasonic  sensor1(F("ultrasonic1"), 60, 0, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E);
  static st::PS_Ultrasonic  sensor1(F("presence1"), 15, 4, PIN_ULTRASONIC_T, PIN_ULTRASONIC_E);
  static st::PS_Ultrasonic  sensor2(F("presence2"), 15, 5, PIN2_ULTRASONIC_T, PIN2_ULTRASONIC_E);
  
  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //  -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
  //         to prevent communication conflicts with the ST Shield communications
  //*****************************************************************************
  st::Everything::debug=true;
  st::Executor::debug=true;
  st::Device::debug=true;
  st::PollingSensor::debug=true;
  st::InterruptSensor::debug=true;

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings ESP8266WiFi Communications Object
    //STATIC IP Assignment - Recommended
    st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);
 
    //DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
    //st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //Add each sensor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addSensor(&sensor1);
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************

  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
  
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}

Any idea where I went wrong?

Otherwise, it works perfectly. It is going to be a breeze setting up the webCoRE piston.

I love your icons!

I wonder if someone who knows how the Arduino pinouts work, will be able to help please:

I’m trying to connect to ultrasonic sensors to a WeMoS D1 (R2). The pinouts are as follows:
|Pin|Function|ESP-8266 Pin|
|TX|TXD|TXD|
|RX|RXD|RXD|
|A0|Analog input, max 3.3V input|A0|
|D0|IO|GPIO16|
|D1|IO, SCL|GPIO5|
|D2|IO, SDA|GPIO4|
|D3|IO, 10k Pull-up|GPIO0|
|D4|IO, 10k Pull-up, BUILTIN_LED|GPIO2|
|D5|IO, SCK|GPIO14|
|D6|IO, MISO|GPIO12|
|D7|IO, MOSI|GPIO13|
|D8|IO, 10k Pull-down, SS|GPIO15|
|G|Ground|GND|
|5V|5V|–|
|3V3|3.3V|3.3V|
|RST|Reset|RST|

I can’t get the sensors to work with any of the pins apart from D6 and D7. For the second sensor, I’ve tried the following combinations without any success: D0 and D1; D1 and D2; D3 and D4; D2 and D5.

I’ve defined the pinouts as follows when for the combinations D1 & D2 for the first sensor and D6 & D7 for the second:

#define PIN_ULTRASONIC_T_1 D1 //digital output to trigger ultrasonic
#define PIN_ULTRASONIC_E_1 D2 //digital input to read the echo
#define PIN_ULTRASONIC_T_2 D6 //digital output to trigger ultrasonic
#define PIN_ULTRASONIC_E_2 D7 //digital input to read the echo

Anyone who can spot what I’m doing wrong?

I never used one of these before but usually some signals need to be opposite of the device.

|Pin|Function|ESP-8266 Pin|
|TX|TXD|RXD|
|RX|RXD|TXD|
|A0|Analog input, max 3.3V input|analog output?|
|D0|IO|GPIO16|
|D1|IO, SCL|GPIO5|
|D2|IO, SDA|GPIO4|
|D3|IO, 10k Pull-up|GPIO0|
|D4|IO, 10k Pull-up, BUILTIN_LED|GPIO2|
|D5|IO, SCK|GPIO14|
|D6|IO, MISO|GPIO12|
|D7|IO, MOSI|GPIO13|
|D8|IO, 10k Pull-down, SS|GPIO15|
|G|Ground|GND|
|5V|5V|–|
|3V3|3.3V|3.3V|
|RST|Reset|RST|

I appreciate your reply Brian. If I understand you correctly, I should try to use TX and RX in place of e.g. D0 and D1 for one of the sensors. Will try that and report back.

Edit: OK, I must have misunderstood you. Using TX and RX result in this error when compiling the sketch:

ST_Anything_Ultrasonic_WeMoSGarage:66: error: ‘RX’ was not declared in this scope

ST_Anything_Ultrasonic_WeMoSGarage:67: error: ‘TX’ was not declared in this scope

exit status 1

Glad you like the icons! Those were a bit of a hidden treasure especially for you!

Not sure about you Wemos D1 pin issues, as I do not have any of those boards.

How many ultrasonic sensors are you attempting to connect to one microcontroller? Just two? It would seem like you could identify 2 pairs of pins that should work.

The Tx/Rx pins are usually connected to the onboard USB chip, making it somewhat difficult to use those pins for anything except USB communications (especially if you have a USB cable plugged into the board!!!) Also, the fact that ST_Anything sends ASCII text out the Tx pin for the Arduino Serial Debug Window makes it hard to use those pins for anything but USB communications.

@949BFN

Hendre,

Here is the Arduino IDE’s pin definitions for the Wemos D1 R2. This file is what allows your code to use the friendly pin names (like D1, D2, etc…) in your sketch. Be sure to NOT override any of these definitions in your sketch as that will mess up the mapping of friendly names to actual ESP8266 GPIO pins.

    #define PIN_WIRE_SDA (4)
    #define PIN_WIRE_SCL (5)

    static const uint8_t SDA = PIN_WIRE_SDA;
    static const uint8_t SCL = PIN_WIRE_SCL;

    #define LED_BUILTIN 2 //new ESP-12E GPIO2

    static const uint8_t D0   = 3;
    static const uint8_t D1   = 1;
    static const uint8_t D2   = 16;
    static const uint8_t D3   = 5;
    static const uint8_t D4   = 4;
    static const uint8_t D5   = 14;
    static const uint8_t D6   = 12;
    static const uint8_t D7   = 13;
    static const uint8_t D8   = 0;
    static const uint8_t D9   = 2;
    static const uint8_t D10  = 15;
    static const uint8_t D11  = 13;
    static const uint8_t D12  = 12;
    static const uint8_t D13  = 14;
    static const uint8_t D14  = 4;
    static const uint8_t D15  = 5; 

Thank you Dan!
Yes, I will only be using 2 sensors for now.
Should I add that to the sketch? The board is marked with the friendly names like D0, D1, D2 etc. I tried many combinations but the only pair that I could get to function properly are D6 and D7.
I won’t waste your time with this. I’ll spend some time trying to figure this out and in the process, will hopefully learn a few things about sketches etc. If I don’t come right, I’ll simply use two boards with one sensor each.
I must tell you that the water level sensor is incredibly accurate. It is actually mind-boggling that on a 3000l/790gal. tank, it registers the +/- 8 litres/2 gal. used when a toilet is flushed. I can’t get my head around.

I need to do this Ultrasonic tank sensor for my 2000gal tank!! Great Idea… Is this the sensor you have and will it work with 3.3V or only 5V as described? I want to use it with my ESP32.

Thanks…

No, do not add that to your sketch. That file is automatically included by the Arduino IDE when you tell the IDE which board you’re compiling the sketch for.

I just wanted to make sure your sketch wasn’t trying to redefine any of these, as that could result in the use of the wrong GPIO pins.

Check out the original thread for the water tank level work by @Saif76

1 Like