1/16/16 - Updated to reflect recent ST IDE nomenclature changes and v2 SmartThings Phone App image.
Just a heads up - The current Arduino IDE 1.6.6 has a bug in it which throws a compiler error (invalid namespace) when trying to build ST_Anything. Please continue to use v1.6.5 until 1.6.7 is released. You can use the latest "Hourly Build" of the 1.6.7 IDE as well, since I have confirmed the bug has been fixed in that version, as of 11/28/15.
I am happy to share with the SmartThings Community a project that my son and I have been working on for the past two weeks - ST_Anything! Our goal was to make it as easy as possible for anyone with some Arduino hardware/software skills to be able to get a new "Device" up and running in a matter of minutes versus hours/days. We have implemented many of the typical Device Capabilities supported natively by SmartThings. ST_Anything can be used "as-is" if desired, but we believe that most of you will want to do something somewhat unique to solve a particular need. To that end, ST_Anything is more of a reusable framework that abstracts all of the SmartThings library away from the user, allowing you to focus on creating new "Devices" by inheriting from the ST_Anything C++ library's PollingSensor, InterruptSernsor, and Executor classes. Please refer to the sample devices like Illuminance, Temperature/Humidty, Motion, Contact, Switch, Alarm, an Water as examples of how to do this.
The entire project can be found at https://github.com/DanielOgorchock/ST_Anything
Feedback is most welcome. I am also willing to help anyone who needs assistance getting this up and running. The initial contents of the GitHub repo's ReadMe are below, which explains most of how to get things up and running.
NOTE: You can also find a new and improved version of SmartThings' Arduino Library in the repository. We have made many improvements to the library which any existing Arduino/ThingShield project will most likely appreciate as well. Please see the ReadMe section below for specifics - also, the ReadMe at the GitHub link has more details of how to use the new library.
Turn your Arduino into an AnyThing. ST_Anything is an Arduino library, sketch, and Device Type that works with your SmartThings ThingShield to create an all-in-one SmartThings device.
This package currently implements the following SmartThings Device Capabilities:
•Alarm (Siren only currently)
•Relative Humidity Measurement
Note: Attempting to use all of these at once on an Arduino UNO is likely to result in running out of SRAM on the UNO (the UNO only has 2 kilobytes of RAM.) Using an Arduino MEGA 2560 with 8 kilobytes of SRAM is recommended if you want to run everything at once.
ST_Anything consists of four parts:
•The ST_Anything.ino Arduino sketch
•The ST_Anything Arduino library
•The SmartThings (ThingShield) library - A modified, more efficient version
•The ST_Anything.groovy DeviceType
ST_Anything Arduino Setup Instructions
•Download the ST_Anything repository.
•This folder structure should mirror that of your local Arduino directory. Copy all the files in the repo to the corresponding local directories (detailed instructions of this process are below if needed).
◦ Look inside the 'Arduino\Sketches' folder of the repo.
◦ Copy and paste the 'ST_Anything' sketch folder into your local 'Arduino\Sketches' directory.
◦ Look inside the 'Arduino\libraries' folder of the repo.
◦ Copy and paste both the 'ST_Anything' and 'SmartThings' folders into your local 'Arduino\libraries' directory. (Note: it may be wise to rename your existing 'SmartThings' library to prevent any overwriting if you have already downloaded the official release.)
•Download DHT library from https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib and copy dht.h, dht.cpp, and ReadMe.txt to your 'Arduino\libraries\DHT' folder.
•Open the ST_Anything.ino and see if it successfully compiles.
•WARNING: If you are using an Arduino UNO, you will most likely need to comment out some of the devices in the sketch (both in the global variable declaration section as well as the setup() function) due to the UNO's limited 2 kilobytes of SRAM. Failing to do so will most likely result in unpredictable behavior. The Arduino MEGA 2560 has 8k of SRAM and has four Hardware Serial ports (UARTs). If you plan on using lots of devices, get the MEGA 2560.
ST_Anything SmartThings Device Handler Installation Instructions
•Join your Arduino/ThingShield to your hub using your phone's SmartThings App. It will show up as a generic "Arduino ThingShield"
•Create an account and/or log into the SmartThings Developers Web IDE.
•Click on "My Device Handlers" from the navigation menu.
•Click on "+ New Device Handler" button.
•Select the "From Code" Tab near the top of the page
•Paste the code from the ST_Anything.groovy file from this repo.
•If you commented out any of the devices in the sketch, be sure to comment out the corresponding tiles & preferences in the ST_Anything.groovy code as well.
•Click on Save in the IDE.
•Click on Publish -> For Me in the IDE.
•Click on My Devices from navigation menu
•Select your "Arduino ThingShield" device from the list
•Click the Edit button at the bottom of the screen
•Change the Type to "ST_Anything"
•Click the Update button at the bottom of the screen
•On your phone, log out of SmartThings in the app, and then log back into SmartThings to refresh its settings
•Your Arduino Device Tile should now look like the image above in this ReadMe
•Be sure to go into the Preferences section to set the polling rates for the sensors. These are sent to the Arduino if you press the Configure tile. (Note: Currently, these settings do not persist after an Arduino reboot. I am hoping to figure out a method to have SmartThings send the Configure() command each time the Arduino starts up. Gotta leave something for the future! )
Updated SmarthThings ThingShield Library
While developing the ST_Anything library and Arduino sketch, it was discovered that the Arduino UNO R3's 2 kilobytes of SRAM was quickly limiting the number of devices that could be hosted simultaneously. Numerous optimizations were made to the ST_Anything library which resulted in significant savings. Focus was then turned to the SmartThings ThingShield library.
Improvements to the SmartThings ThingShield library include:
•100% backwards compatible for use with your existing Arduino code
•SRAM memory optimizations (~150 bytes saved)
•Elimination of unnecessary temporary dynamic memory allocations (255 bytes per send command)
•Elimination of unused variables and dead code paths
•The additon of a Hardware Serial communications constructor
•Support for the 3 additional hardware UARTS on the Arduino MEGA 2560
If you choose to use the complete ST_Anything package (i.e. ST_Anything.ino, ST_Anything library, and ST_Anything.groovy) the following choices are automatically made:
•If using an Arduino UNO - SoftwareSerial is used on pins 2/3
•If using an Arduino Leonardo - SoftwareSerial is used on pins 2/10 (add jumper from pin 10 to pin 2)
•If using an Arduino MEGA, Hardware Serial is used on pins 14/15 (add jumpers from Pin14 to Pin2 and another from Pin15 to Pin3)