Arduino sketch sharing, discussion and support

I don’t have an exact timeplan, but yes… we need some kind of mechanism for knowing that a message has arrived to its target. One way of solving it is to have a new type of sendVariable-function that triggers a reply from the recipient when message has reached its target.

Actuator can then send update-request to target. The ack-response will eventually arrive asynchronously from the recipient. When reply arrives it switches relay (or perform the actuator change).

This will give instant feedback if communication is down as the relay won’t switch.

Its seems that most sketches or examples use pull-down resistors for switches but I was wondering why not use the built in pull-up resistor and just change some logic. It can be activated with the following command in the sketch

 digitalWrite(12, HIGH)

It would save some excess soldering or wiring.

void setup() {
  pinMode(13, OUTPUT);    // Use Built-In LED for Indication
  pinMode(12, INPUT);      // Push-Button On Bread Board
  /* this next line is the new one */
  digitalWrite(12, HIGH);  // Turn on internal Pull-Up Resistor
}
 
void loop() {
  bool buttonState = digitalRead(12);  // store current state of pin 12
  digitalWrite(13, buttonState);
}

Yes - good idea. Making use of the bounce library (replaces the debounce lib) would be appropriate in some cases as well:

Ok, added debouce2 library (among some other).

Feel free to fix and post updated examples taking advantage of this and the internal pull-up.

Here’s the RelayWithButtonActuator. I just changed the 2 HIGH’s to LOW and the LOW to HIGH for buttonVal, added the digitalWrite(BUTTON_PIN,HIGH) and added bluman’s fix also. No resistor is needed for the button. Just connect to ground to activate relay and change status in vera also. Only thing different is that if you reset the arduino or remove power. When you plug it back in it will turn on or off based on its last state in vera.
Also if you need more pins
Pin 14 = Analog in 0 or A0
Pin 15 = Analog in 1 or A1
Pin 16 = Analog in 2 or A2
Pin 17 = Analog in 3 or A3
Pin 18 = Analog in 4 or A4
Pin 19 = Analog in 5 or A5

Thanks Derek Macias I will see if I can use this in my garage door controller also.

I tested my garage door controller a bit and it seems to work as expected but I do not dear to keep it connected at the moment because if something goes wrong and the garage doors for some reason is left open bad things will happen because of the -20C degrees outside.

Hi Hek,

I’ve just sat down to do a garage controller myself - before reading this thread ;-( , anyway, i pretty much started with the same starting point as korttoma ( thanks mate! ), being the motion sketch.

However rather than use the motion type, I chose “LOCK”
gw.sendSensorPresentation(CHILD_ID, S_LOCK);

And it comes up nicely in UI5 as a lock device ( icon is a padlock )

However, i wonder if the variable 'tripped" is valid for the device type of “lock”…

So i did some digging into the D_DoorLock.json file and see that it is expecting the variable “status” :

"flashicon": "icons/Door_Lock.swf", "imgIconBody": "", "imgIconDimmable": "", "imgIconTurnable": "", "imgIconMin": "icons/Door_Lock_open.png", "imgIconMax": "icons/Door_Lock.png", "halloIconsDir": "pics/hallo", "x": "2", "y": "4", "inScene": "1", "DisplayStatus": { "Service": "urn:micasaverde-com:serviceId:DoorLock1", "Variable": "Status", "MinValue": "0", "MaxValue": "1"

So if i then change the line:
gw.sendVariable(CHILD_ID, V_TRIPPED, tripped?“1”:“0”); // Send tripped value to gw
to
gw.sendVariable(CHILD_ID, V_STATUS, tripped?“1”:“0”); // Send tripped value to gw

the sketch wont compile with error:
MotionSensor:36: error: ‘V_STATUS’ was not declared in this scope

Do i need to go into the arduino mysensor library and add this as a valid variable?
or am i barking up the wrong tree?

OK …a little update.

I did dig around and think its partially working.

I updated the mysensors/sensor.h file:// Sensor variables that can be used in sketches typedef enum { V_TEMP,V_HUM, V_LIGHT, V_DIMMER, V_PRESSURE, V_FORECAST, V_RAIN, V_RAINRATE, V_WIND, V_GUST, V_DIRECTION, V_UV, V_WEIGHT, V_DISTANCE, V_IMPEDANCE, V_ARMED, V_TRIPPED, V_WATT, V_KWH, V_SCENE_ON, V_SCENE_OFF, V_HEATER, V_HEATER_SW, V_LIGHT_LEVEL, V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5, V_UP, V_DOWN, V_STOP, V_IR_SEND, V_IR_RECEIVE, V_FLOW, V_VOLUME[b], V_STATUS[/b] } variableType;
just adding V_STATUS

Sketch then compiled…

Then in L_Arduino.lua i added

IR_RECEIVE = {33, "urn:upnp-org:serviceId:ArduinoIr1", "IrCode", ""}, FLOW = {34, "urn:micasaverde-com:serviceId:WaterMetering1", "Flow", "" }, VOLUME = {35, "urn:micasaverde-com:serviceId:WaterMetering1", "Volume", "0" }, [b] LOCK = {36, "urn:micasaverde-com:serviceId:DoorLock1", "Status", ""},[/b]

Now when the sensor state ( a button at this time ) changes the padlock icon and the UI buttons “Unlock” and “Lock” toggle accordingly! ;D

Next step…getting it to toggle the relay - will be borrowing your code here korttoma.

Nice to see that someone actually has some use for the sketch I made (at least parts of it).

Btw, by using the “LOCK” type of device is it then possible to reduce the amount of devices shown in Vera? My sketch produces one “motion” device and one “Light” device (per door) and then I use the garage door plugin to make it show a door lock device.
You get only the Lock device right? If this is the case I would really like it if you share your work when it is done.

[quote=“gregl, post:28, topic:178741”]OK …a little update.

I did dig around and think its partially working.

I updated the mysensors/sensor.h file:// Sensor variables that can be used in sketches typedef enum { V_TEMP,V_HUM, V_LIGHT, V_DIMMER, V_PRESSURE, V_FORECAST, V_RAIN, V_RAINRATE, V_WIND, V_GUST, V_DIRECTION, V_UV, V_WEIGHT, V_DISTANCE, V_IMPEDANCE, V_ARMED, V_TRIPPED, V_WATT, V_KWH, V_SCENE_ON, V_SCENE_OFF, V_HEATER, V_HEATER_SW, V_LIGHT_LEVEL, V_VAR1, V_VAR2, V_VAR3, V_VAR4, V_VAR5, V_UP, V_DOWN, V_STOP, V_IR_SEND, V_IR_RECEIVE, V_FLOW, V_VOLUME[b], V_STATUS[/b] } variableType;
just adding V_STATUS

Sketch then compiled…

Then in L_Arduino.lua i added

IR_RECEIVE = {33, "urn:upnp-org:serviceId:ArduinoIr1", "IrCode", ""}, FLOW = {34, "urn:micasaverde-com:serviceId:WaterMetering1", "Flow", "" }, VOLUME = {35, "urn:micasaverde-com:serviceId:WaterMetering1", "Volume", "0" }, [b] LOCK = {36, "urn:micasaverde-com:serviceId:DoorLock1", "Status", ""},[/b]

Now when the sensor state ( a button at this time ) changes the padlock icon and the UI buttons “Unlock” and “Lock” toggle accordingly! ;D

Next step…getting it to toggle the relay - will be borrowing your code here korttoma.[/quote]

Thanks, I must have missed the lock-status-variable…

I will add it right away. They will be named:
L_Arduino.lua: LOCK (like in your example)
Sensor.h: V_LOCK_STATUS (just STATUS was a bit too generic)

My answer to the $45 ([url=http://www.amazon.com/gp/product/B006TG9W4Y/]http://www.amazon.com/gp/product/B006TG9W4Y/[/url]) Everspring Z-Wave Water/Flood Sensor. Thanks to the CopperTop Bunny for 3V power and everyone elses help in getting power usage to a minimum.

Sal

PS: Oh yeah, thanks to Hek, too. :wink:

Nice!!

Here is a sketch I’m using to send a discrete IR code to select the HDMI 3 input on my Sony NX720. It’s a long story…pronto codes, protected hex, UEI… Henk you have made this possible thanks to the Arduino Sensor Plugin along with Ken Shirriff’s IR decode sketch.

It’s basic but was the missing link in my ability to create a scene using my XBMC plugged into HDMI 3.

Using a modified relay actuator sketch it sends the discrete IR code for HDMI 3 with the on or off function of the light switch presented to the Vera.

I hope others can make use of this and look forward to the new IR Remote device which I believe Henk is working on.

Here’s a modified version of the servo sketch. I had a noisy servo that would make some noise randomly and hum at certain spots. I tried capacitors and different power supplies. However I decided to add a delay and detach() after every move and this fixed my problem. So basically the servo pin only connects when its activated from vera then detaches when done. Also by adding detach to stop, if your fast enough you can stop it.

Thanks Derek,

I’ll add your changes to the git repo.

I’m trying to put together a simple sketch that would receive all RF traffic and dump it on the serial port.
It has become clear to me that I do not know what I’m doing and I can’t seem to figure out this simple sketch.

My goal is to be able to plug my extra nano in to me android tablet and be able to see using a serial monitor the traffic.

This node should not be a part of the sensor network and not send anything on RF just dump what it sees on serial.

If anyone could lend me a hand I would be grateful.

I already tested my android device with the GW sketch in combination with https://play.google.com/store/apps/details?id=jp.ksksue.app.terminal&hl=en so I know this is possible.

[quote=“korttoma, post:29, topic:178741”]Nice to see that someone actually has some use for the sketch I made (at least parts of it).

Btw, by using the “LOCK” type of device is it then possible to reduce the amount of devices shown in Vera? My sketch produces one “motion” device and one “Light” device (per door) and then I use the garage door plugin to make it show a door lock device.
You get only the Lock device right? If this is the case I would really like it if you share your work when it is done.[/quote]

Hi korttoma - i ran out of time trying to get the single device for the “Garage Monitor” as we were discussing last week. I would like to come back to it when i have some time, but in the interim, i found there is an existing plugin called “Garage Door” from Richard…Garage Door - Vera Plugin.
To use it is easy.
You create your sketch as you have including
gw.sendSensorPresentation(MS_CHILD_ID, S_MOTION);
gw.sendSensorPresentation(RLY_CHILD_ID, S_LIGHT);

then configure the garage door plugin setting two of its variables:
DoorSensorDevNum
DoorSwitchDevNumber
to correspond the the device id’s created by your sketch.

Thats it!

The plugin will send a short on-off command to your S_Light device, which is likely toggling a relay and closing your garage door.

I have then created a PLEG to alert me when the wife has left the garage door open between 10pm-7am.

I’ve not installed it yet…awaiting PCB’s to do a nice neat setup. Ill use a reed switch and magnet to detect door in open position.

It is a bit hard to monitor all traffic in the radio network using the MySensor library as is. I use the Pipe-concept (read up on it below) heavily and you cannot listen to more than 6 piped per radio.

What you want to do is probably to place the sniffing-device near the gateway and listen to pipe 0 (where all non sensor->sensor messages eventually end up) without replying/acking any messages on the network.

You will need to make changes to the behavior of the Gateway code to realize this.

https://www.sparkfun.com/datasheets/Components/SMD/nRF24L01Pluss_Preliminary_Product_Specification_v1_0.pdf

@gregl

http://forum.micasaverde.com/index.php/topic,22334.msg149259.html#msg149259

@hek
Thanks for the info. For the first time it seems like it is not going to be easier then I thought.

[quote=“korttoma, post:39, topic:178741”]@gregl

http://forum.micasaverde.com/index.php/topic,22334.msg149259.html#msg149259[/quote]

bah… :-[