Getting started with the SmartThings Arduino shield


(Gray) #1

I got my shield a week ago and started playing with it this week. I’m definitely an Arduino beginner, but I’ve been learning the ropes and didn’t have much trouble getting it started up and linked to my hub (once I read the instructions and realized I had to push the button on it). But even after poking around the documentation and sample code on this site, I feel like I could really use a lot more information.

In another thread there was a discussion of the documentation for creating device types, which I think is really important.

Additionally, I would love some more information about the mechanics of the shield, particularly its power consumption. Does it need 5V? Is there any way to reduce power consumption in certain states so that I could run it for a reasonable period of time off of batteries?

Is there other information that others would like to have so that we can do some serious work with these shields?


Unofficial SmartThings + Arduino Documentation Collection
(Andrew Urman) #2

The shield itself needs 3.3V you could run it on a battery, but it would have to spend most of its time asleep.


(Dome) #3

I’ll echo that documentation would be very nice for creating custom device types.

In the meantime, I’m working on this project. I am trying to control an external LED strip and have a tile for the strip that cycles through these states: dark, red, green, blue, and white. I came up with this code:

standardTile("ledstrip", "device.ledstrip") {
			state "dark", label: '${name}', action: "ledstrip.red", icon: "st.Lighting.light13", backgroundColor: "#000000"
			state "red", label: '${name}', action: "ledstrip.green", icon: "st.Lighting.light13", backgroundColor: "#ff0000"
			state "green", label: '${name}', action: "ledstrip.blue", icon: "st.Lighting.light13", backgroundColor: "#00ff00"
			state "blue", label: '${name}', action: "ledstrip.white", icon: "st.Lighting.light13", backgroundColor: "#0000ff"
			state "white", label: '${name}', action: "ledstrip.dark", icon: "st.Lighting.light13", backgroundColor: "#ffffff"
		}

In this code, the states successfully cycle in the app, but don’t pass the desired commands on to the shield (commands are dark, red, green, blue, and white).

I tried this version, and the commands are passed but the states don’t change.

standardTile("ledstrip", "device.ledstrip") {
			state "dark", label: '${name}', action: "red", icon: "st.Lighting.light13", backgroundColor: "#000000"
			state "red", label: '${name}', action: "green", icon: "st.Lighting.light13", backgroundColor: "#ff0000"
			state "green", label: '${name}', action: "blue", icon: "st.Lighting.light13", backgroundColor: "#00ff00"
			state "blue", label: '${name}', action: "white", icon: "st.Lighting.light13", backgroundColor: "#0000ff"
			state "white", label: '${name}', action: "dark", icon: "st.Lighting.light13", backgroundColor: "#ffffff"
		}

I’m not quite sure how to get it working. Anyone have any insight?


(Juan Risso) #4

Hi! 2 things:
1 - You can define all the actions like this

def red() {
	return zigbee.smartShield(text: "red").format()
}

Or you can call the same action and pass the value of state

standardTile("ledstrip", "device.ledstrip") {
			state "dark", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#000000"
			state "red", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#ff0000"
			state "green", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#00ff00"
			state "blue", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#0000ff"
			state "white", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#ffffff"
		}

def arduino() {
	return zigbee.smartShield(text: "$ledstrip").format()
}

2 - Make sure that on the Device type settings you define all the actions as commands
For example, if you use the second example, add “arduino” as a command on you device type settings.


(Solardave1) #5

@gary. We built a prototype standalone wireless Arduino/ST shield device to control/monitor a laser tripwire security sensor. Adafruit provided most of the parts necessary. As pointed out, the shield (and xbee radios) require regulated 3.3 vdc and power consumption would require extended sleep times. The setup we used involved a large capacity (6600 mAH lipoly) battery, a lipo charger, a 6v 3.4w solar panel and both a 3.3v regulator and a 5v buck converter (minty boost) to supply the needed power. Everything was placed inside a nema ip66 waterproof plastic case with a small cable gland to provide an waterproof entry/exit path for the solar panel wire (so the panel could be mounted in the optimal sun catching position regardless of where we put the battery/charger/regulator/Arduino-shield components). A second cable gland was installed to provide for the wire that went to the security device’s contact closure/alarm-trip output. Virtually everything came off the shelf from Adafruit. The setup worked just fine and maintained sufficient available power throughout the night based on a full charge of the batteries during daytime. The same setup was ultimately used with a standard xbee shield with a high xmit power xbee and a ufcl connector and a pigtail with a bulkhead mount to allow the use of an external (to the box) directional antenna mounted at some height to increase the operating range to the 250m we needed. Hope this helps.


(Dome) #6

Juan,

Thanks for the help, but I’m still not getting commands through and it’s not changing states. I tried both examples. Here is my whole code:

/**
 *  Blank Slate 12
 *
 *  LED Strip
 *
 *  Author: tcnerison@gmail.com
 *  Date: 2013-08-29
 */
 // for the UI
metadata {
	simulator {
		// TODO: define status and reply messages here
	}

	tiles {
     
		standardTile("ledstrip", "device.ledstrip") {
			state "dark", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#000000"
			state "red", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#ff0000"
			state "green", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#00ff00"
			state "blue", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#0000ff"
			state "white", label: '${name}', action: "arduino", icon: "st.Lighting.light13", backgroundColor: "#ffffff"
		}

		main (["ledstrip"])
		details(["ledstrip"])
	}
}

// parse events into attributes
def parse(String description) {
	def value = zigbee.parse(description)?.text
	def name = value && value != "ping" ? "response" : null
	def result = createEvent(name: name, value: value)
	log.debug "Parse returned ${result?.descriptionText}"
	return result
}

def arduino() {
	return zigbee.smartShield(text: "$ledstrip").format()
}

In the Arduino sketch, my functions are defined as:

void red()
{
  smartthing.shieldSetLED(1, 0, 0);
  digitalWrite(ledR, HIGH);
  digitalWrite(ledG, LOW);
  digitalWrite(ledB, LOW);
  smartthing.send("red");       // send message to cloud
  Serial.println("red");
}

and so on.


(Tyler) #7

I’m currently building an electricity monitor per the following (couldn’t get the hyperlink button to work for me):

http://openenergymonitor.org/emon/buildingblocks/how-to-build-an-arduino-energy-monitor

I’ve had my arduino smartthings shield for a while, but am just plugging it in for the first time. Hopefully soon, I’ll be able to monitor all the circuits at the circuit breakers in my home from anywhere. Later, I can use other zigbee devices to use this information to further automate the house!


(Steve S) #8

@dome - I think the problem lies in your “parse()” method. Specifically, when you CreateEvent, “name” needs to be the name of the tile. So if you did this:

def parse(String description) {
	def value = zigbee.parse(description)?.text
	def name = value && value != "ping" ? "ledstrip" : null
	def result = createEvent(name: name, value: value)
	log.debug "Parse returned ${result?.descriptionText}"
	return result
}

It should work. Basically in CreateEvent, the “name” is the name of the tile - in your case, your standardTile was device.ledstrip, so to update it’s state, “name” needs to be “ledstrip” and then the “value” is the name of the state you want the tile to have.

It took me a whole weekend to figure that out - hope this saved you some time.


(Kelvin) #9

I’m having difficulty pairing the arduino smart things shield. It was paired at one point, then put aside for a while. Could not talk to it from an app so finally removed the device. Now trying to pair and not having any luck. I load the stLED sample, and pressed the switch but no joy. Anyone have any clues or similar experiences? It is a Mega 2560 R3 Arduino.

Thanks in advance and feel free to point out my stupidity! Just solve my problem.


(Kelvin) #10

Well I got another shield and tried a different hub and the shield is now paired. I now am having trouble receiving messages sent from the app to the shield. I’m basically using the Arduino SmartThings Shield LED Example.
For the SmartThings device I based/copied the On/Off shield example from Urman. On the App side and DeviceHandler side, I see logging that indicates everything up to the zigbee commands are being executed.
zigbee.smartShield(text: “on”).format() seems to be called. But on the device side, I don’t see anything on the serial logger. I noticed a blog above also having problems similar to this. Anyone have any clues here?
Thanks


(Jwu) #11

If you are using a Mega or Leonardo then there’s an additional step of jumping pin 3 to another pin that supports interrupt. See this post for more information on that.


(Paul Ockenden) #12

Tyler, I know this is a REALLY old thread, but I just wondered whether you every got your OpenEnegymonitor / Smartthings integration working?


(Ben Wolodko) #13

Hi All…

It’s me again… like a broken record …( Old School )

If anyone has an Arduino ThingShield available for sale, please let me know
still looking for a couple units.

Thanks so much

Ben