Put it out on a breadboard and fixed some of my problems and implemented your suggestion. My SSR can’t run a DC current so that was causing some of my confusion so just powering a LED directly now. Though the way it currently is coded means the PWM signal still runs even when the switch is “off”. I am going to edit the function EX_Switch_DIM::writeLevelToPin()
to set the PWM signal to either high or low, depending on m_bInvertedLogic
, when the switch is off.
Made some edits to the code to allow inverting the PWM signal and checks for the ESP8266 for 10-bit PWM otherwise 8-bit. It looks like it is working for me but please check as I am not savvy with Arduino yet.
EX_Switch_Dim.cpp
void EX_Switch_Dim::writeLevelToPin()
{
if(m_bCurrentState) {
#if defined(ARDUINO_ARCH_ESP8266) //<---- ESP8266 10-bit
analogWrite(m_nPinPWM, map(m_nCurrentLevel, 0, 100, m_bInvertPWM ? 1023 : 0, m_bInvertPWM ? 0 : 1023));
#else
analogWrite(m_nPinPWM, map(m_nCurrentLevel, 0, 100, m_bInvertPWM ? 255 : 0, m_bInvertPWM ? 0 : 255));
#endif
}
else {
#if defined(ARDUINO_ARCH_ESP8266) //<---- ESP8266 10-bit
analogWrite(m_nPinPWM, m_bInvertPWM ? 1023 : 0);
#else
analogWrite(m_nPinPWM, m_bInvertPWM ? 255 : 0);
#endif
}
}
//public
//constructor
EX_Switch_Dim::EX_Switch_Dim(const __FlashStringHelper *name, byte pinSwitch, byte pinPWM, bool startingState, bool invertLogic, bool invertPWM) :
Executor(name),
m_bCurrentState(startingState),
m_bInvertLogic(invertLogic),
m_bInvertPWM(invertPWM)
{
m_nCurrentLevel = startingState == HIGH ? 100 : 0;
setSwitchPin(pinSwitch);
setPWMPin(pinPWM);
}
EX_Switch_Dim.h
byte m_bInvertPWM; //determines whether the Arduino PWM Output should use inverted logic
EX_Switch_Dim(const __FlashStringHelper *name, byte pinSwitch, byte pinPWM, bool startingState = LOW, bool invertLogic = false, bool invertPWM = false);
Looks pretty good. I noticed one minor issue in your change to EX_Switch_Dim.h… You should probably change the data type of m_bInvertPWM from “byte” to “bool” to match the function prototype.
Once you get things working as desired, let me know. We can work together to get the GitHub repository updated with your changes.
Thanks,
Dan
Did you fix the issue where you were not seeing the dimmer in the child device?
Please see this post above for details of naming the devices correctly in the Arduino sketch in order for the correct child device handlers to be used when creating the child devices.
Yes, I fixed that when I found your reply. The examples in the sketches show using “Switch” with the Dimmer instead of “dimmerSwitch”. ST_Anything_Switch_Dimmer_ThingShield.ino
Looks like that example sketch is from the deprecated folder. Those sketches were written prior to the Parent/Child device handler architecture existing. I modified that one just to avoid any future confusion as you’re the second person that has reported the same issue.
Thanks for the feedback!
Fellow Smartthings users, Good morning,
If there is anyone willing to sell a Smartthings Arduino shield, please let me know
Thanks
Ben
Successfully built a tiny in fixture dimmer with the ESP-01S, 5v solid state relay(G3MB-202P), transistor(2N2222), 120v to 5V converter(TSP-05), 5v to 3.3v regulator(LD1117V33), 2x10uF caps. I used GPIO3 which is the RX pin just as a proof of concept. Using GPIO3 also allowed testing before installing due to the RX LED onboard. This means that someone could use an ESP01 or ESP11 and use 3 GPIOs possibly 4 if serial is disabled. From what I researched the TX pin (GPIO1) will always have some debugging output on boot up so it should not be used for relays. The only problem I had is that my LED fixture doesn’t like the PWM frequency used and visibly strobes at below ~50%. Is there a simple way to increase the frequency. I also realized I will want an easy way of updating the firmware and there are OTA solutions for the ESP8266. Since ESP12E/F are practically the same price as ESP01 but with vastly more GPIO and with 4MB flash compared to 1MB it will be a great platform for any wifi device with plenty of free space for OTA updates. I will try to add OTA next.
I’m missing something here. I’m using your ST_Anything_Multiples_ESP8266WiFi.ino example here. Is there a simple way to just comment out the pins Im not using?
edit: In reading further, I really just need this for my garage door. Do I just need DoorControl, and not the Multiples? If so, is there an example of this anywhere?
I just finished making one for me with dual door control and magnetic switches. I’ll try to post in once I get home in an hour.
Check this out: https://github.com/zybeon/ST_Anything/blob/master/Arduino/Sketches/ST_Anything_Multiples_ESP8266WiFi/ST_Anything_GarageDoor_ESP8266WiFi.ino
Notice that this also has an extra variable in the ESP wifi setup String deviceName = "ESP8266-Garage-Control"
then I added WiFi.hostname(deviceName);
before calling st::Everything::init();
. This sets the name as it appears in your router so it is much easier to determine what things are.
Got OTA updates working through uploading the compiled .bin into a webpage hosted on the ESP8266. Next up is password protecting.
Neat! I was gonna ask about OTA updates because it’s no fun yanking this thing back off my garage door.
Yea, I decided it was necessary after I installed the dimmer into a ceiling light fixture to only realize that the LED bulb doesn’t like the default PWM frequency. Now it can only be used as plain switch. Will also allow updating for compatibility of new ST firmware changes, changes in the network (IP address, SSID, Pass), adjusting/disabling of sensors, and anything else without having to dig it out of a wall or ceiling and connecting a programmer. I planned to use all my leftover ESP01 and other ESP modules that don’t have integrated programmers but realized quickly that updates would be incredibly time consuming. Now I don’t have to worry as I only have to program over the wire once. With the test sketch I added a lot of sensors and included all the libraries to make sure there would be room to still update the scripts. Thankfully the ESP-12E/F has 4MB flash which is more than enough for holding the current script and uploading a new one. I forgot to look at the size to see if this would work with 1MB flash which is common for all the smaller ESP modules.
BTW, probably not a huge deal, but you did leave your wifi creds in there…
Thanks, and fixed. That’s what I get for doing it so late.
If you’re still looking for something to do, OTA updates from the Arduino IDE would be nice as well.
I looked at doing that at first and was getting a lot of compiling errors or it not showing in my IDE. Found out I had an old library that caused the issue but left it out. I couldn’t test this yet but try this out. https://github.com/zybeon/ST_Anything/blob/master/Arduino/Sketches/ST_Anything_Multiples_ESP8266WiFi/ST_Anything_MultiplesOTA_ESP8266WiFi
So just for fun, because I had one, I added a DHT to my garage door opener. I see it reporting data in the serial monitor, but the child device doesn’t seem to get created for the DHT. What am I missing?
Make sure you specify the temp and humidity device names in your setup() routine as shown below. The last two arguments really are no longer optional, as those names are sent to ST with the corresponding numeric values. The name must be un the form shown below. This is also noted in the ST_Anything ReadMe on Github.
static st::PS_TemperatureHumidity sensor7(F("temphumid1"), 15, 5, PIN_TEMPERATUREHUMIDITY_1, st::PS_TemperatureHumidity::DHT22,"temperature1","humidity1");