VoxCommando

Arduino & Other Home-made Gadgets (that work with VC!) => Arduino support => Topic started by: dedlefou on March 18, 2014, 10:58:39 AM

Title: Arduino Plugin
Post by: dedlefou on March 18, 2014, 10:58:39 AM
Hi,

I would love to use vox for my home automation but every thing is wired to work with an arduino :o(

A simple plugin to read/write digital and analog pin from/to an arduino board (via serial communication by example) would be so nice !

I dream to ask vox what is the temperature outside ? is it raining ? adding to my robot a knock sensor to wake up vox (from red to yellow) lol
Turn on light (and depending on which presence sensor is detecting me, it light up only the closest light by relay) so one command work for all lights...

Or best of all, based on presence sensor, activate the closest micro only ;o) and be able to extand vox to any room ...

It look like a huge work but it can be done with 4 new actions ? Write analog, read analog and two more for digital ? Then the logical (if, then, etc..) can be handle by vox to command most arduino functions.

Please, without commanding you of course, take a serious consideration on it :o))))

Thank's to read, André.

Ps: I almost forgot to say that your software is the most impressive for me since I discover netscape :p in 1998
Title: Re: Arduino Plugin
Post by: jitterjames on March 18, 2014, 11:27:46 AM
Hi André,

Welcome to the forum.  :)

Everything you want can be achieved relatively easily using the python plugin.  It is more powerful and flexible than writing a plugin for Arduino, which in any case would be much more complicated than what you describe, because it will depend on which arduino you are using, and how you have programmed it, whether you are using serial or ethernet or bluetooth to control it.  Maybe you want to have VC query your arduino for the state of a certain analog input, or maybe you want your Arduino to send this information automatically on an interval, or only when it reaches a certain state.

I can see that a serial plugin would make things a bit easier but until I make that, you can use the python plugin, and I think once you get more serious about trying to do different things, you will prefer to use the python plugin over a serial plugin anyway.

I am working on some examples for this right now.  I will start with just setting some pins high or low, but you can do much more of course.
Title: Re: Arduino Plugin
Post by: dedlefou on March 18, 2014, 12:04:45 PM
Good morning James,

I am working on some examples for this right now.  I will start with just setting some pins high or low, but you can do much more of course.

Wow you are like a father for me...

Ok to be very honnest I was sure it was not so simple as I describ of course... But I tried lol

I'm webmaster and worked on linux for more then ten years... and I hate Python :( but I will re-learn it ! You convince me that a plugin is not a real solution. And you really well understood what I would like to do with my arduino and Vox. The query option is a critical part of my project but the result mixing this both technology could be very powerfull !

So I really would love to have a starting point as you said making pin LOW / HIGH etc... Will it be on the PY plugin wiki page ?

Thank you very much, sincerly yours, André.

Title: Re: Arduino Plugin
Post by: jitterjames on March 18, 2014, 01:31:30 PM
Here is an example:

http://voxcommando.com/mediawiki/index.php?title=Arduino
Title: Re: Arduino Plugin
Post by: dedlefou on March 18, 2014, 02:22:18 PM
Wow

It's a bit more then a starting point, there is a video  lol

Very glad to asking you... I had some hesitations, I would miss something ! What a support !

I will study this in details, but for sure you gain a new customer ! And a fan in bonus !

Thanks very much, for your best support and your fast reply :o)
Title: Re: Arduino Plugin
Post by: hehrm on March 18, 2014, 03:40:23 PM
great video james.  makes me really want to save up for vera again too :P
Title: Re: Arduino Plugin
Post by: dedlefou on March 19, 2014, 02:40:25 PM
Hi James,

I finally take my finger in Python, and my remembers was right... I hate this kind of language :( It's very strict ! I'm probably not compatible  ::confused

And the need to asking you was not too long... And your fear is going to happen  >:D
Yes I'm going to ask you about retrieving data, the other way, the final return, with TTS.speech to conclude...

Could you please (not in the next hour, take your time please, listen some jazz)  add a reading status code in the wiki example page?

I mean retrieve a value (analog would be best but i'm not sure if it's possible at this time...) I'm swimming yet, especially about the Vox commando XML part, the python part, and probably the arduino part. I dont see other parts... :P

So with this I will be able to work very long long time, and leave you alone.

I'm sure it will help lot of people, thanks a lot.

Sincerly, André.
Title: Re: Arduino Plugin
Post by: jitterjames on March 20, 2014, 04:46:23 PM
Programming languages are pretty much all strict by definition.  Computers are not very good at guessing what you mean.  You need to be precise.

I have personally found python to be one of the easier languages, but there are some pitfalls.  The only thing about it that I really don't like is the indentation but you get used to it.

I will try to post something on this in the next week or two but I am a bit overloaded with other things at the moment.
Title: Re: Arduino Plugin
Post by: dedlefou on March 20, 2014, 05:22:17 PM
Hi,

Ok no problems, I'm learning fast finaly... even if exception is a new concept for me  :bonk
I will need the wox xml part especialy. The arduino part looks to be easy and I become more confident on python and reading/writing should be good soon.
But I have no idea yet about the vox side...

So I can wait but a whole process commented by you will be priceless for me and a great time saver.

Btw about price you really should price your soft at less twice more !
I dont know if it's a conversion trick between $CA and € but I was surprise about your price : 25 euros !! it's just a meal and wine lol
I mean it was a good news of course, but it wont hurt anyone to paid the double  :) especially for a soft of this quality ! And you let people fully try the soft, can't be best...

I'm freelance too so I know the benefit of a small price and seriously 50€ / 80 CA$ keep this same benefits...

Anyway thank's to you, have a good day, andre.
Title: Re: Arduino Plugin
Post by: jitterjames on March 26, 2014, 04:34:14 PM
Here is an example with serial communication in both directions.  The Arduino sketch and the python script are attached.  Load the .ino sketch onto your arduino and save the python file to your VC\py folder.  Adjust the com port number in the python file is necessary to match your port. Paste the following group into your VC command tree and restart VC.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 1.9.1.7-->
<commandGroup open="True" name="Arduino test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="739" name="Read value of pin {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("ar.{1}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Read value of pin</phrase>
    <payloadRange>0,15</payloadRange>
  </command>
  <command id="735" name="analog value event" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Pin {1} has a value of {2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Analog.Pin</event>
  </command>
  <command id="762" name="Set pin {1} high" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("dw.high.{1}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set pin</phrase>
    <payloadRange>40,50</payloadRange>
    <phrase>high</phrase>
  </command>
  <command id="776" name="Set pin {1} low" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("dw.low.{1}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set pin</phrase>
    <payloadRange>40,50</payloadRange>
    <phrase>low</phrase>
  </command>
  <command id="715" name="hello arduino" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("hello")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>hello arduino</phrase>
  </command>
</commandGroup>
Title: Re: Arduino Plugin
Post by: jitterjames on March 26, 2014, 04:41:15 PM
By the way I am cheating by using a method that has not yet been documented in VoxCommando's Python plugin:
Code: [Select]
vc.evaluateActionString(String)...allows you to send a string to execute any action.  The String will be evaluated the same way as a string VC receives by UDP, TCP, HTTP, or by command line.

The String will be broken up by "&&" as follows:

Code: [Select]
ActionType&&Param1&&Param2&&Param3...
so for example you could write

Code: [Select]
vc.evaluateActionString("TTS.Speak&&Hello my friend")
or

Code: [Select]
vc.evaluateActionString("VC.Standby")
or

Code: [Select]
vc.evaluateActionString("OSD.ShowText&&I am at the top for 2 seconds!&&2000&&-20")
Of course you don't have to use this method but it allows the most freedom to be able to make any call from your Arduino without having to change the python code.  If you prefer you can use the other methods as shown on the wiki: http://voxcommando.com/mediawiki/index.php?title=Python
Title: Re: Arduino Plugin
Post by: dedlefou on March 27, 2014, 08:03:12 AM
Hi James,

Firstly, let me thank you so much once again  ::)

Your exemple is exactly what I'm looking for, especially your second post wich is very intuitive to code ! Perfect !
In fact I dont yet decide where to place the "logical" but depending what will be more fast it could finally be done in the python script.

I got a problem to import your xml file... Very strange. I tried copy past an other xml file from the dedicated exchange board and it work.
I tried both version of vox (1 and alpha 1) and the result is the same. I then copy paste the code to notepad++ and tried all the encodage possibility... same same (yes I learn english in Thailland sorry)...

this is the error windows open me :

Code: [Select]
************** Texte de l'exception **************
System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
   à VoxCommando.commandBlock.eval_ᜀ(XmlNode A_0)
   à VoxCommando.commandBlock.addMacroFromXML(XmlNode macroNode)
   à VoxCommando.CommandList.addCommand(XmlNode cmdXmlNode, String strParentGroup)
   à eval_a.eval_ᜁ(TreeNode A_0, XmlNode A_1, Int32 A_2)
   à eval_a.eval_ᜁ(XmlNode A_0, Int32 A_1)
   à eval_a.eval_ᜁ(String A_0, TreeNode A_1)
   à eval_a.eval_ᜠ(Object A_0, EventArgs A_1)
   à System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   à System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   à System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   à System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   à System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   à System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   à System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   à System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   à System.Windows.Forms.Control.WndProc(Message& m)
   à System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   à System.Windows.Forms.ToolStrip.WndProc(Message& m)
   à System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


I tried to figure out what's wrong myself but I have to disturb you a bit more...
I hope it's just a debug on your computer to de-activate or a "&" encodage matter which dont take you too much time  ;)

Thank in advance, sincerly, André.
Title: Re: Arduino Plugin
Post by: nime5ter on March 27, 2014, 08:22:32 AM
Sorry about that. There will be some changes to the xml structure in future VC2 releases and James accidentally wrote those commands in the new version.

Try the following:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<commandGroup open="True" name="Arduino test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="739" name="Read value of pin {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>arduinoWrite("ar.{1}")</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Read value of pin</phrase>
    <payloadRange>0,15</payloadRange>
  </command>
  <command id="735" name="analog value event" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <cmdString>Pin {1} has a value of {2}</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Analog.Pin</event>
  </command>
  <command id="762" name="Set pin {1} high" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>arduinoWrite("dw.high.{1}")</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set pin</phrase>
    <payloadRange>40,50</payloadRange>
    <phrase>high</phrase>
  </command>
  <command id="776" name="Set pin {1} low" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>arduinoWrite("dw.low.{1}")</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set pin</phrase>
    <payloadRange>40,50</payloadRange>
    <phrase>low</phrase>
  </command>
  <command id="715" name="hello arduino" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <cmdString>arduinoWrite("hello")</cmdString>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>hello arduino</phrase>
  </command>
</commandGroup>

The above will work with old versions of VC1. However, anyone using Version 1 should still update their installations to 1.191, which is on the downloads page: http://voxcommando.com/downloads.asp

That version accepts the new xml command structure so that commands can still be shared on the forum. (The new version 2 alpha with these changes has not yet been released, but will be posted soon.)
Title: Re: Arduino Plugin
Post by: dedlefou on March 27, 2014, 09:36:06 AM
Hi nime5ter,

It work !! Thank's a lot  ;D

I'm ready to spend hours making an Assistant more real then ever !

Thanks to whole voxCommando team ! You Rock's !
Title: Re: Arduino Plugin
Post by: scott_fx on April 13, 2014, 05:33:01 AM
I'm not familiar with writing python code but I was wondering if it would be a big hassle to modify the script in order to communicate with two devices via two com ports? 

Reason I'm asking is that I want to use vox to add speech recognition to a ui I'm building for my car. It is written using processing2.js (it's what the arduino IDE is based off of)

Here is my progress so far
http://youtu.be/zC2-ZxUgTLw

It is currently using a com port to communicate with an arduino via serial.  I'm a novice in coding but am trying to figure out how they can all talk. 
Title: Re: Arduino Plugin
Post by: jitterjames on April 13, 2014, 07:56:04 AM
Sure, no problem.  ;D

VoxCommando can communicate with multiple devices using multiple com ports.  Other than that I don't really know what you are asking.
Title: Re: Arduino Plugin
Post by: donmehdi on April 27, 2015, 07:09:16 PM
[img][img]Hey, i just made the circuit on my arduino UNO. i dont know if it is correct since  the tutoriel of the arduino doesn t use a breadboard but a relayboard. I want to know if it is correct.
Title: Re: Arduino Plugin
Post by: Kalle on April 27, 2015, 07:29:55 PM
Hi donmehdi, no your wiring is wrong.

D3-> resistor -> LED(long leg=anode=+) and LED (short leg=kathode= -) to ground

D4-> resistor-> LED(long leg=anode=+) and LED (short leg=kathode= -) to ground

D5-> resistor -> LED(long leg=anode=+) and LED (short leg=kathode= -) to ground

You will find a lot of examples here: http://www.arduino.cc/en/Tutorial/Blink (http://www.arduino.cc/en/Tutorial/Blink)
Title: Re: Arduino Plugin
Post by: donmehdi on April 27, 2015, 07:37:30 PM
OH the placement of my resistors is wrong  i have to put it between the digital and the led. i'm going to try that
Thanks.
Title: Re: Arduino Plugin
Post by: donmehdi on April 27, 2015, 09:11:18 PM
i think the method adjustrelays() provided in the wiki for arduino should be like that:

///////////////////

void adjustRelay(int whichPin, char setState)
{
  if (setState=='1')// 1 instead of 0
  {
    Serial.write(" OFF");
    digitalWrite(whichPin, HIGH);
  }
  else if(setState=='0')// 0 instead of 1
  {   
    Serial.write(" ON");
    digitalWrite(whichPin, LOW);   
  }     
}
/////////////////////////////////
Title: Re: Arduino Plugin
Post by: jitterjames on April 28, 2015, 09:15:45 AM
The nice thing about code is that you are free to modify it to suit yourself.

I personally like to follow logical conventions as much possible so that code is easier to understand.

99.9 percent of the time 0 = off and 1 = on but you can do whatever makes you happy.  :)
Title: Re: Arduino Plugin
Post by: donmehdi on April 29, 2015, 12:12:48 AM
I know, but the thing is when i used the code you provided, when i tell vc to turn relays on it turns them to off and same thing for off,  it turns them to on.  :D :D ;)
Title: Re: Arduino Plugin
Post by: Kalle on April 29, 2015, 03:49:32 AM
Yes there are some relays available which works in reverse  ::)
Title: Re: Arduino Plugin
Post by: jitterjames on April 29, 2015, 08:48:12 AM
Maybe this will help.
https://youtu.be/YN_kV2h-a04

And if you are using LEDs you should be aware that there are two different types. Common anode and common cathode. http://forum.arduino.cc/index.php?topic=22413.0
Title: Re: Arduino Plugin
Post by: donmehdi on April 29, 2015, 09:22:44 AM
Thanks James :), now i understand ;)
Title: Re: Arduino Plugin
Post by: batfasturd on June 15, 2015, 12:38:43 PM
I use Openhab as the center of my home automation which is a combination of arduinos using the Mysensors libraries, the Hue hub and bulbs and a few GE smart bulbs. Openhab has a web API which can be easily accessed using Voxcommando so I can ask, what's the weather outside and it can pull data directly from my HA controller via web scrape and tell me the conditions from my arduino node. Voxcommando also can control all the lights in my house, garage door, etc... using the same web API.
Title: Re: Arduino Plugin
Post by: laksmanx on June 16, 2015, 08:18:26 AM
Hi James.

I want VC to reply with speech if an input is triggered on the arduino.

I used the code provided in THIS FORUM and it works but I am unable to get VC to read an input from my Arduino when triggered.



Kind regards

Title: Re: Arduino Plugin
Post by: jitterjames on June 16, 2015, 08:51:18 AM
Hi laksmanx,
Welcome to the forum.

There are many codes posted on "this forum".  It always helps to be specific about what you have tried when seeking help from others.

In fact,  in this very thread,  a few posts up,  you can find an example of sending data in both directions,  to Arduino from VoxCommando and to VoxCommando from Arduino:  http://voxcommando.com/forum/index.php?topic=1452.msg12742#msg12742

If you have tried this example code and are unable to get it to work,  then please tell us more specifically what you are doing and what is happening vs what you expect etc.

Read the following for tips on getting support more effectively: http://voxcommando.com/mediawiki/index.php?title=Getting_support
Title: Re: Arduino Plugin
Post by: laksmanx on June 16, 2015, 09:49:57 AM
I am referring to reply #9 to #12 in the Arduino plugin post which is about two way coms between VC and Arduino.

I used the code and it works for both Arduino uno and VC.
VC is able to set outputs on Arduino high or low and I am able to ask VC what the pin status is of relevant pin.

What I would like to do is trigger an input on the Arduin uno and have VC respond with a phrase eg. the front door is open garage door opening.

I am not sure where to make the change , in Arduino code or python code or probably both.


Title: Re: Arduino Plugin
Post by: jitterjames on June 16, 2015, 02:11:05 PM
Now we are getting somewhere!

Yes you only need to adjust the Arduino Sketch.  You do not need to modify the python code.

You only need to know a few fundamental things about Arduino to modify the code I posted.  The code that I posted was supposed to be a starting point so that you could see how it works and then modify it to suit your needs.  I suggest that you look over the Arduino sketch and the Python code and try to understand how it all fits together.

In order to add some extra functionality to your sketch for a button, you should first take a look at this example:
http://www.arduino.cc/en/Tutorial/Button

That sketch is using a button, and resistor, and Digital pin #2 to read the state of the button.  You can add a button using the same wiring that they show.  Then you need to borrow some of their code and adapt it a little bit to our existing sketch.

At the beginning of our sketch you need to define some constants and variables:
Code: [Select]
const int buttonPin = 2;     // the number of the pushbutton pin
int buttonState = 0;         // variable for reading the pushbutton status

in the setup() you need to let Arduino know that we will be using pin 2 as an input:
Code: [Select]
pinMode(buttonPin, INPUT);
and in the loop we need to look at the state of the button (newButtonState), compare it to the old state of the button (buttonState) to see if it changed.  If it did change then we can fire an event in VC showing if the button is pressed or released.  Finally we should store the new button state (newButtonState) in our variable (buttonState) so next time we can see if it changed or not.

Code: [Select]
// read the state of the pushbutton value:
  int newButtonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (newButtonState != buttonState) {     
    //send event to VC showing the button changed
    if(newButtonState)
    {   
      Serial.println("VC.TriggerEvent&&Button.Pressed");
    }
    else
    {   
      Serial.println("VC.TriggerEvent&&Button.State.Released");
    }
    buttonState=newButtonState;
  }

Then you can use the event to trigger any commands in VC that you like.

The updated Arduino sketch is attached.
Title: Re: Arduino Plugin
Post by: laksmanx on June 21, 2015, 04:12:04 AM
Hi James

Thank you for the advice on VC responding to inputs on the Arduino.

It all makes a great deal of sense now.

By triggering events with digital inputs on Arduino, one can literally do anything. I went from the idea of VC letting me know when the front door or garage door is opening, to a multimedia interface where i can play, pause and skip music from my entertainment area with buttons or voice.

Here is the code I used to trigger multiple inputs.

Code: [Select]
String data="";  //used to receive serial messages
const int buttonPin1 =2;
const int buttonPin2 =3;
const int buttonPin3 =4;
const int buttonPin4 =5;
bool flag_1 = 0;
bool flag_2 = 0;
bool flag_3 = 0;
bool flag_4 = 0;
bool buttonState_1 = 0;
bool buttonState_2 = 0;
bool buttonState_3 = 0;
bool buttonState_4 = 0;
void setup() {
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  Serial.begin(9600);
}

void loop() {
  delay(100);
  int oneButtonState = digitalRead(buttonPin1);
 
  if (oneButtonState != buttonState_1) {
    if(oneButtonState)
    {
       if(flag_1 == 0)
       {
       Serial.println("VC.TriggerEvent&&ButtonOne.Pressed");
       flag_1 = 1;
       }
    }
    else
    {
       if(flag_1 == 1)
          {
            Serial.println("VC.TriggerEvent&&ButtonOne.State.Released");
            flag_1 = 0;
          }
    }
    buttonState_1 = oneButtonState;
  }
  delay(100);
  int twoButtonState = digitalRead(buttonPin2);
  if (twoButtonState != buttonState_2) {
    if(twoButtonState)
    {
      if(flag_2 == 0)
        {
         Serial.println("VC.TriggerEvent&&ButtonTwo.Pressed");
         flag_2 = 1;
        }
    }
    else
    {
      if(flag_2 == 1)
        {
         Serial.println("VC.TriggerEvent&&ButtonTwo.Released");
         flag_2 = 0;
        } 
    }
    buttonState_2 = twoButtonState;
  }
 
  delay(100);
  int threeButtonState = digitalRead(buttonPin3);
  if (threeButtonState != buttonState_3) {
    if(threeButtonState)
    {
      if(flag_3 == 0)
        {
         Serial.println("VC.TriggerEvent&&ButtonThree.Pressed");
         flag_3 = 1;
        }
    }
    else
    {
      if(flag_3 == 1)
        {
         Serial.println("VC.TriggerEvent&&ButtonThree.Released");
         flag_3 = 0;
        } 
    }
    buttonState_3 = threeButtonState;
  }
delay(100);
  int fourButtonState = digitalRead(buttonPin4);
  if (fourButtonState != buttonState_4) {
    if(fourButtonState)
    {
      if(flag_4 == 0)
        {
         Serial.println("VC.TriggerEvent&&ButtonFour.Pressed");
         flag_4 = 1;
        }
    }
    else
    {
      if(flag_4 == 1)
        {
         Serial.println("VC.TriggerEvent&&ButtonFour.Released");
         flag_4 = 0;
        } 
    }
    buttonState_4 = fourButtonState;
  }
}

void serialEvent() {
  data="";
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the data:
    if (inChar == (char)10)
    {
      break; //break message on newline
    }
    data += inChar;
  }
  //data should be ready now.  What should we do with it?

  if (data=="hello")
  {
    Serial.println("tts.speak&&hi there");
  }

  //Analog Read - Pin #
  else if (data.startsWith("ar."))
  {
    String strPin = data.substring(3);
    int whatPin = atoi(strPin.c_str());
    int v = analogRead (whatPin);
    Serial.println("VC.TriggerEvent&&Analog.Pin&&"+strPin+"&&"+v);
  }

  //DigitalWrite HIGH - Pin #
  else if (data.startsWith("dw.high."))
  {
    String strPin = data.substring(8);
    int whatPin = atoi(strPin.c_str());
    pinMode(whatPin, OUTPUT);
    digitalWrite (whatPin,HIGH);
  }

  //DigitalWrite LOW - Pin #
  else if (data.startsWith("dw.low."))
  {
    String strPin = data.substring(7);
    int whatPin = atoi(strPin.c_str());
    pinMode(whatPin, OUTPUT);
    digitalWrite (whatPin,LOW);
  }

  //unknown command
  else
  {
    Serial.println("VC.TriggerEvent&&Arduino.error&&"+data);
  }

  //clear data for next time
  data="";
}









Title: Re: Arduino Plugin
Post by: mexicanto on December 19, 2015, 04:06:45 AM
Hi James,

I already did the 2 examples for arduino (relays and led/analog), and both worked perfectly,
but in both VC is triggering the accions

Is there a chance for you to post a example for trigger a event or two for buttons in arduino as a
starting point?
my main goal is, for example, if somebody ring the bell on the main door, the arduino can
"speak" a message: "the door bell is ringing", and a osd.text display in the screen
and have another button in the same sketch, for example a motion sensor in the back patio
that trigger a speak and a message on the screen

in this example, can you include the PY code, the arduino code and the XML code?


but, if is this not a big problem, the best could be have a complete example, with a couple of buttons, a couple
of LEDs, and a couple of potentiometres, with the PY, Arduino and XML code

Thank you very much in advance

Daniel
Title: Re: Arduino Plugin
Post by: jitterjames on December 19, 2015, 11:09:49 AM
Sounds like you would benefit from using "MySensors".  Try doing a search for it on this forum.
Title: Re: Arduino Plugin
Post by: jitterjames on December 19, 2015, 11:11:16 AM

Is there a chance for you to post a example for trigger a event or two for buttons in arduino as a
starting point?

That is exactly what the post immediately before your question shows how to do!

http://voxcommando.com/forum/index.php?topic=1452.msg19237#msg19237
Title: Re: Arduino Plugin
Post by: mexicanto on December 19, 2015, 07:09:57 PM
Thanks for the quick response, James

I am just scratching the surface of VC, and i am very happy with it

I checked mysensors before, and is very interesting too
when i asked for an example of two buttons, i was thinking in a whole example
like what you did with the relays, LED and analog input reading, with
the arduino sketch, the PY source and the XML, and from there, modify as my needs
as i said, i just start digging in VC, can you somebody give me a hand with that ?

so far, what i was doing is modify the examples of the XML to suit my needs,
for me is easiest in that way, than start from scratch.

I also have the amazon echo, and this device is superb on voice recognition, BUT...
it is lacking the functions to "ask" values of sensors, triggers events (you can do it
with IFTT, but takes forever to have a response), and in this field, VC is perfect

greetings from (not so) sunny California

Daniel


Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 12:33:39 AM
any help with this ??
an example with:

a PY code, arduino code and xml code for a two button in arduino triggering action in VC ?

thank you
Title: Re: Arduino Plugin
Post by: Kalle on December 24, 2015, 01:49:50 AM
Hi mexicanto, the example is already given here: http://voxcommando.com/forum/index.php?topic=1452.msg12742#msg12742
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 05:50:24 AM
Thank you Kalle

I did both examples already (relay control and reading the state of a pin)
but both examples are triggered from VC to the arduino
i am looking for the opposite,
That is, arduino trigger an event in VC

lets say that i have two buttons in arduino, when i press one, i expect VC to trigger an event, lets say
an osd.showtext "button 1 have been pressed", the same for button 2

I learn quickly just modifying examples, for that, if somebody can help me
with the arduno code, the PY code and the XML code, i will appreciate that

thank you again
Title: Re: Arduino Plugin
Post by: Kalle on December 24, 2015, 08:18:41 AM
It looks like you did not read also the next post in the link above  ;)


The python script listen to the Arduino port, so you can put in your Arduino code something like this: Serial.println("VC.TriggerEvent&&I am Event&&and am I a payload").


It is better you read all the posts in this thread, because there are some helpful information and also the same question as yours:
http://voxcommando.com/forum/index.php?topic=1452.msg19182#msg19182


I have no example script here, but if you take a look in the "SerialTestJames.ino" you will find it at line 36. We have a "ready" to use python script for the MySensors API, with this script VC can communicate with the MySensors stuff (MySensors-Gateway is needed)
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 10:51:12 AM
Hi Kalle,

I read all the post at least twice, the PY code is there, the arduino sketch is there, if only
somebody help me with the XML code as an example, it will help me a lot

I am pretty new to VC, less than a month using it, 2 weeks as a licensed user

after finish the button testing, i will jump into mysensors to implement it on home automation
i have a little dog as a roommate, some times he is alone most of the day, i have surveillance cameras
to keep an eye on her, but my first goal is to have a monitoring system, to alert me (via email, i have that cover
with VC) in case of fire or flood, i can attach the sensors to arduino, and the arduino can trigger the VC

thanks again
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 10:59:50 AM
I forgot to ask you... when is the mysensors-gateway will be ready for purchase?

thanks again
Title: Re: Arduino Plugin
Post by: Kalle on December 24, 2015, 11:14:06 AM
Yes, I have here some MySensors-Gateways, but without any housing - write me a PM with your address.  ;)


When you ask for a xml, you mean a command which contain trigger event?
I will look into or maybe James or Dave can help, because they has even more experience  ::)
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 11:24:18 AM
Yes, the XML that goes into the command tree, with the instructions for, lest say:

osd.showtext "button one has been pressed"

osd.showtext "button two has been pressed"

I will pm you with my info

thank you
Title: Re: Arduino Plugin
Post by: jitterjames on December 24, 2015, 12:05:12 PM
The sample above generates events in VC when a button is pressed on your Arduino.  An event can trigger any command in VC.

It sounds like maybe you need to learn how to use events.  Here is the information you need to use events, which by the way is a core concept that you will need to understand in order to make full use of VoxCommando's potential:
http://voxcommando.com/mediawiki/index.php?title=Events
(Note that there are video tutorials on that wiki page.)

If you do not learn how to use events in VoxCommando, then you should not even consider using MySensors because they generate events.
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 12:20:29 PM
Thanks James & Kalle

I think i finally doing some progress, i did some test with vc.triggerevent
i can now fire one event based in other command

i will probably post the XML for the buttons in a few days (hours).

have all of you a happy holidays
Title: Re: Arduino Plugin
Post by: Kalle on December 24, 2015, 12:28:14 PM
This sounds good and I'm sure you will understand fast how things work in VC.
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 12:36:10 PM
Hi again Kalle,

Can you check your inbox ? i already sent you a pm

My main goal is to have the most plug-n-play system, because after what i did with
the harmony remote, and what i am going to do with mysensor, my friends are going
to ask me to install something like mine in their homes, and my rule is:
"the easiest and simplest, the better"

thank you for your support, kalle and james
Title: Re: Arduino Plugin
Post by: Kalle on December 24, 2015, 12:49:09 PM
The last PM I got is your mail address.
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 01:06:54 PM
Yes Kalle, thats my last pm,

I will keep in touch with you

This question is probably out of this forum, but just for my information:
what is the difference between a event with number 9 and event with number 3 ?

thank you
Title: Re: Arduino Plugin
Post by: jitterjames on December 24, 2015, 01:13:32 PM
If you are talking about the event icon the number is meaningless so there is no difference. It's just a picture.
Title: Re: Arduino Plugin
Post by: mexicanto on December 24, 2015, 01:28:06 PM
Thank you, yes, i was talking about the event icon
Title: Re: Arduino Plugin
Post by: mexicanto on December 29, 2015, 09:52:56 AM
I know this codes/sketches/scripts are in other post
I just want to put everything in one post for whom ever can use it

thanks to james and laksmanx, the authors of the code

The notes:
I tested it with 2 leds, 2 potentiometers, and 2 pushbuttons
I suggest that you use a pulldown resistors on the analog inputs not in use
to avoid floating readings, this same applies to the pushbuttons in use


in my test i connect the leds to pins 6 & 7
the potentiometers on pins A1 & A3 (i will use the potentiometer on pin3 for later use, a smoke/fire alarm)
the pushbuttons on pins 11 & 12

happy holidays

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.7-->
<commandGroup open="True" name="LED-Pin-Hello-WR" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="310" name="Arduino Startup" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\ArduinoStartup.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
  <command id="798" name="Set The LED On" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Set The LED On</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Set The LED On</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("dw.high.6")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set The LED On</phrase>
  </command>
  <command id="817" name="Set The LED Off" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Set The LED Off</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Set The LED Off</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("dw.low.6")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set The LED Off</phrase>
  </command>
  <command id="779" name="Get The Value" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("ar.1")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Get The Value</phrase>
  </command>
  <command id="796" name="Read value of pin {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("ar.{1}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Read value of pin</phrase>
    <payloadRange>0,15</payloadRange>
  </command>
  <command id="756" name="analog value event" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>The Pin number. {1}. has a value of. {2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>The Pin number. {1}. has a value of. {2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Analog.Pin</event>
  </command>
  <command id="784" name="Set pin {1} high" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Set Pin. {1}. High</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Set Pin. {1}. High</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("dw.high.{1}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set pin</phrase>
    <payloadRange>1,50</payloadRange>
    <phrase>high</phrase>
  </command>
  <command id="829" name="Set pin {1} low" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Set Pin. {1}. Low</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Set Pin. {1}. Low</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("dw.low.{1}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Set pin</phrase>
    <payloadRange>1,50</payloadRange>
    <phrase>low</phrase>
  </command>
  <command id="736" name="hello arduino" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>arduinoWrite("hello")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>hello arduino</phrase>
  </command>
  <command id="746" name="Button One Is Pressed" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Button One Is Pressed</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Button One Is Pressed</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>ButtonOne.Pressed
</event>
  </command>
  <command id="398" name="Button One Is Released" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Button One Is Released</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Button One Is Released</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>ButtonOne.State.Released
</event>
  </command>
  <command id="399" name="Button Two Is Pressed" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Button Two Is Pressed</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Button Two Is Pressed</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>SMTP.Send</cmdType>
      <params>
        <param>7148308504@mymetropcs.com</param>
        <param>Button 2 Pressed</param>
        <param>The Button No. 2 Has Been Pressed</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>SMS Pressed Sent</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>SMS Pressed Sent</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>ButtonTwo.Pressed
</event>
  </command>
  <command id="400" name="Button Two Is Released" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Button Two Is Released</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Button Two Is Released</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>SMTP.Send</cmdType>
      <params>
        <param>7148308504@mymetropcs.com</param>
        <param>Button 2 Release</param>
        <param>The Button N. 2 Has Been Release</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>SMS Released Sent</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>SMS Released Sent</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>ButtonTwo.Released
</event>
  </command>
</commandGroup>