Announcing the "ST_Anything" Arduino/ThingShield Project

Hi Dan,

The Leonardo board that I am using would be closer to the Micro formfactor than the UNO formfactor, it does not have the Arduino UNO form factor, of just plugging the shield onto the Leonardo.

I have taken a UNO prototyping board, and have hard wired the Arduino Shield connections to a connector that plugs into the Leonardo board… There is no ability to use Pins2/3 with a jumper, pins 0 and 1 are connected to the Serial1 port

The Github link is the one I am using, I got the date from the RAW files of the .h and .cpp, not from the change log.

So I need to massage the Smartthings.h and .cpp files to address the Serial to Serial1 change
can you give me some pointers?

Everything I am doing would be relevant for the Micro form factor or any Arduino board that uses the Atmega32U4 CPU

I read an article,

section 4.2.4 Arduino Shield was interesting

Thanks again

Ben

Ben,

My recommendation… Buy an Arduino MEGA. If you’re not an expert on Arduino hardware and programming, you’re going to continue to fight the legacy Leonardo product with a non-UNO form factor.

If you really want to fight it out, I suggest you read up on the SoftwareSerial library, as that is what the Thingshield Arduino library expects to use by default.

If you really want to hack the ThingShield library to work with HW Serial1, just find every call that uses serial communications in SmartThings.cpp, and replace it with “Serial1.xxxx”

Good luck!
Dan

Hi, Dan.
I’ve been trying to replace the photo resistor for the BH1750 digital sensor but I having some troubles. Can you please help me with this one. I have the value in a variable but I dunno how to replace it in your library in order to get it read in the app.
Thanks

Daniel,

Simply take my existing PS_Illuminance.cpp and PS_Illuminance.h files and simply replace their guts with whatever is needed to use the BH1750 sensor instead of the photoresistor.

Dan

Hi Dan, you are well aware that this is not that easy to fix…

There are Serial communications to the Arduno Debug screen and there are Serial communications to the Hardware serial port ( Serial1 )

For me it is beyond my abilities to do this, so I will bow out

Thanks for you input

Ben

Ben,

If I find some time, I can attempt to add proper Leonardo/Micro support to my ThingShield library. It really isn’t too difficult.

If you don’t mind me asking, why not just buy a MEGA (or an UNO for small projects) ?

Dan

Ben,

I have modified my version of the SmartThings ThingShield library so that it “should” work with the Leonardo’s “Serial1” HW UART port. In order for it to work properly, you’ll need to make sure you use the correct constructor, specifically you need to use the following:

SmartThingsCallout_t messageCallout; // call out function forward decalaration
SmartThings smartthing(HW_SERIAL1, messageCallout); // Hardware Serial constructor

If you send me a private message with your email address, I will send you a zip file with the new code for you to test with.

Dan

Seriously. Good Mega clones can be had for around $10.

HI Dan.
I tried but to be honest Im not a developer guy I just start learning how to program in arduino language, could you please give me a hand creating the new cpp and .h to use the following sketch of the BH1750
thanks a lot.

/#include Wire.h>

int BH1750_address = 0x23; // i2c Addresse
byte buff[2];

void setup(){
//Lux sensor initiation
Wire.begin();
BH1750_Init(BH1750_address);
delay(200);
Serial.begin(9600);
Serial.println(“Inicio”);
}

void loop(){

float valf=0;
if(BH1750_Read(BH1750_address)==2){
valf=((buff[0]<<8)|buff[1])/1.2; //lUMEN FORMULA
if(valf<0)Serial.print("> 65535");
else Serial.print((int)valf,DEC); //Print Value in Dec
Serial.println(" lx");
}
delay(1000);
}
//Communication with LUX sensor.
void BH1750_Init(int address){
Wire.beginTransmission(address);
Wire.write(0x10); // 1 [lux] aufloesung
Wire.endTransmission();
}

byte BH1750_Read(int address){
byte i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available()){
buff[i] = Wire.read();
i++; }
Wire.endTransmission();
return i;
}

Daniel,

Without having a BH1750, I really wouldn’t be confident that I could add this device to ST_Anything. Is there a reson you want to use the BH1750 instead of just a simple photo-resistor? Photo-Resistors are extremely simple and low cost.

Dan

@BenB2016

Ben,

After verifying everything still works on my UNO and MEGA, I have updated my GitHub repository with the new SmartThings.h and SmartThings.cpp files for the ThingShield’s “SmartThings” library. These new files should work properly with your Leonardo based board’s Serial1 UART on pins 0/1.

Again, make sure you use the HW Serial constructor as I noted in an earlier post.

I also updated my ST_Anything library’s Constants.h file to properly identify and automatically use the Leonardo’s Serial1 UART. This should allow you to use my ST_Anything library and sketches.

Dan

Hi dan.
Yes the main reason is because I’m using some wemo minis to send the signal of the sensors wirelesly using the udp library to another wemo that is giving each input to my anything module. The idea of this is to avoid the cables from the arduino and the sensors that are located in different places in my house. I’m using the wemo because cost 4 usd, is tiny and has wifi. So far all the sensors are working perfect without a significant delay, except for the switch that is taking 5 seconds since I press the bottom in the app until my light turn on, and the photo resistor that is taking a bit more and I think is because the wemos analog Input has some issues.
For that reason I test the BH1750 and the problem was solved but now I need to give that data to the arduino anything module.
Please let me know if you have any idea of how to fix it. I hope, I was clear in my exponation.

Daniel,

What is a wemo mini with wifi? I tried to search for it, but did not find anything that seems to match what you’re describing.

Dan

Sorry I misspelled it. It’s wemos
Here the link
http://www.wemos.cc/Products/d1_mini.html

Why not just bypass the Arduino and hub altogether, and just connect directly to the ST cloud? Since the wemos are just ESP-8266 boards, with wifi, they can directly connect without having to use the ThingShield.

There are numerous examples here in the forums of people doing exactly this.

So I had another Idea for the thingshield and a project.

I have an old garage door opener just like my current one. It accepts signals from Homelink (which seems to be prolific anymore)

I was thinking of either using its board, or finding something smaller that could receive teh signal from one of the other buttons on my homelink to use it as a “goodbye” or “I’m Back” trigger?

The wife plays along with this stuff but she would never use the phone app, but pushing a button in her car when she leaves to make sure everything is off she would do. I realize its not perfect since im talking about a toggle but… Something to use another homelink button for at least :wink:

Edit: One step closer:

Hi Dan,

I am currently out of town, back on the 18th of June,

I would really like to try the Smartthings library with Leonardo Hardware serial port support.

I picked up a bunch of the Tinkerkit TKLCD devices that sport a LCD screen as well as aAtmega32u4 cpu, and a form factor to be mounted on a panel, for LCD viewing.

the connections on the back of this device are molex type connectors that allow wired connection to serial, I2C, DI/O and AI/O devices.

The decision to purchase these devices, was partly based on your header file discussion on memory, and the use of Hardware serial ports.

I read the Arduino Leonardo page with them stressing the separate Hardware serial port, with Debug happening with the USB port. The other part was the form factor to be able to mount the unit, and have a local LCD readout. More memory that the UNO, better form factor for me than the Mega , and a hardware serial port. a winner in my terms …

Anyway, It is very capable of doing what I want to do, except for receiving data on the RXD line.

Dan, If you have a webpage that I could make a donation to I would gladly. I feel Smartthings should be doing this type of library / code interface work, but for many other platforms.

If there was code where the “library” or call was just the data to be sent or reecived, by smartthings and the programmer, had to explicitly set

what the serial port was called i.e “Serial1”, and what pin numbers were TXD, and RXD, , as well as the baudrate and its associated parameters

this could be used by may other micros.

That being said, I would like to try the Smartthings.cpp and .h files that support the Leonardo with hardware serial port.

Thank you for your efforts, they are much appreciated

Ben

Ben,

What you’re asking for is exactly what my version of the ThingShield library does. You can either use a SoftwareSerial port by calling the exact same constructor as the regular ThingShield library and simple pass in the Rx and Tx pins ( but only certain pins work!). Or, you can call my Hardware Serial constructor (as shown above) and just pass in the proper enum for HW_SERIAL1, 2, or 3.

Dan

Hi Dan Ive been reading all the related posts and I found that ST hub doesnt allow UDP communication, also I found some projects of ppl sending commands on the LAN but they are not able to pull the sensors status. For that reason I think that is better to use the shield to communicate with the hub. In order to do that I used the Wemos to send the sensors status wirelessly to a Wemos receptor " wemos wireless comm" and then I transfer the values to each imput of your Anything project. (It is working well but is not efficient enough)


For that reason I would like to improve the performance and time response by conecting the Wemos receptor to your anything module trough I2C. Do you think that is possible to modify the sketch of teh anything module to get the data directly to the variable rather than from the GIOP if yes could you please explain me how to do it.

Thanks you
Dan Perez

Have you looked an example like the following yet? Direct esp8266 to ST cloud ( no hub). Just another idea.

As for using ST_Anything, you could just create your own class which implements your communications with your ESP8266 devices and then makes the correct calls to send the data to ST via the ThingShield.

However, if that is all the Arduino is going to be used for, I don’t know that’d bother using ST_Anything. Instead, just write your own simple sketch based on one of the examples provided by ST for using the ThingShield.