Arduino Integration

  • 277 Views
  • Last Post 17 September 2014
hdrider465@gmail.com posted this 16 September 2014

Thought I would share some scripts to communicate with your Arduino.

-------------------------------------------------
Test script for the Arduino to play a tone when InControl talks to it and Turn LED on / off

int ledPin = 13;
int TonePin = 11;
int state = 0;

void setup() {
// initialize digital pin 13 as an output.
pinMode(ledPin, OUTPUT);
pinMode(TonePin, OUTPUT);
Serial.begin(9600);
}

void loop() {
if(Serial.available() > 0){
state = Serial.read();
//Play a tone on Serial Data
tone(100, 1000);
}
// if the state is D13OFF the led will turn off
if (state == 'D13OFF') {
digitalWrite(ledPin, LOW);
Serial.println("Led Off");
}
// if the state is D13ON the led will turn on
else if (state == 'D13ON') {
digitalWrite(ledPin, HIGH);
Serial.println("Led On");
}
}

void tone(long duration, int freq){
duration *= 1000;
int period = (1.0 / freq) * 1000000;
long elapsedtime = 0;
while (elapsed
time < duration)="">
digitalWrite(TonePin, HIGH);
delayMicroseconds(period / 2);
digitalWrite(TonePin, LOW);
delayMicroseconds(period / 2);
elapsed_time += (period);
}
}

-------------------------------------------------
And an InControl Test script to use on a scene to talk to the Arduino over USB Serial

using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class ArduinoOn : ScriptBase, ScriptInterface {
public void runScript() {
SerialPort mySerialPort = new SerialPort("COM10"); // Whatever COM port your Arduino is on
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.WriteTimeout = 5000;
mySerialPort.Open();
mySerialPort.Write("D13ON\r\n"); // LED ON
//mySerialPort.Write("D13OFF\r\n"); // LED OFF
mySerialPort.Close();
}
}

Order By: Standard | Newest | Votes
Ryan-Scott posted this 16 September 2014

This is pretty cool info! Can I ask how you plan to use your Arduino when it's all said and done?

hdrider465@gmail.com posted this 17 September 2014

This is pretty cool info! Can I ask how you plan to use your Arduino when it's all said and done?


I am trying to create a gateway that can allow me to use the Arduino to extend out into other PAN networks ( Bluetooth and ZigBee to start with )

Close