Author Topic: Arduino Plugin  (Read 22162 times)

0 Members and 4 Guests are viewing this topic.

dedlefou

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 0
    • View Profile
Arduino Plugin
« 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

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Arduino Plugin
« Reply #1 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.
« Last Edit: March 18, 2014, 11:30:00 AM by jitterjames »

dedlefou

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 0
    • View Profile
Re: Arduino Plugin
« Reply #2 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é.


jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Arduino Plugin
« Reply #3 on: March 18, 2014, 01:31:30 PM »

dedlefou

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 0
    • View Profile
Re: Arduino Plugin
« Reply #4 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)

hehrm

  • $upporter
  • Jr. Member
  • *****
  • Posts: 11
  • Karma: 0
    • View Profile
Re: Arduino Plugin
« Reply #5 on: March 18, 2014, 03:40:23 PM »
great video james.  makes me really want to save up for vera again too :P

dedlefou

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 0
    • View Profile
Re: Arduino Plugin
« Reply #6 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é.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Arduino Plugin
« Reply #7 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.

dedlefou

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 0
    • View Profile
Re: Arduino Plugin
« Reply #8 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.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Arduino Plugin
« Reply #9 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>
« Last Edit: March 26, 2014, 04:45:55 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Arduino Plugin
« Reply #10 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
« Last Edit: March 26, 2014, 04:48:04 PM by jitterjames »

dedlefou

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 0
    • View Profile
Re: Arduino Plugin
« Reply #11 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é.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Arduino Plugin
« Reply #12 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.)
« Last Edit: March 27, 2014, 08:26:50 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

dedlefou

  • Jr. Member
  • **
  • Posts: 7
  • Karma: 0
    • View Profile
Re: Arduino Plugin
« Reply #13 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 !

scott_fx

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 1
    • View Profile
Re: Arduino Plugin
« Reply #14 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.