Go Down

Topic: Roving Networks RN-XV + Arduino Wireless Proto Shield (rev 3) (Read 9769 times) previous topic - next topic

Waltermixxx

#15
Mar 04, 2012, 06:00 am Last Edit: Mar 04, 2012, 06:17 am by Waltermixxx Reason: 1
okie doke, here is my code this far... (it errors out so I know i have syntax issues...but it's easy to see what I am trying to accomplish)
the RN-VX was already configured manually using $$$ and various commands, so i know it's listening to UDP messages from my iPhone :)

Code: [Select]
/* using an RN-XV setup to monitor UDP messages, sending to the serial port.
*  scanning arduino serial port for P7H, P7L, P6H, P6L, P5P, and finally OFF.
*  then compare the input with the above to turn one of 3 L.E.D.'s on or off  for this test I removed the PWM slider,
*  to challenging for now..
*/


#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

char Buff [3]; // not sure if I need this as a character buffer?

void setup()  
{
 pinMode(5, OUTPUT); // LEDA
 pinMode(6, OUTPUT); // LEDB
 pinMode(7, OUTPUT); // LEDC
 
 Serial.begin(9600);
 mySerial.begin(9600);
 mySerial.println("Hello, world?"); // check to see if it's working
}

void loop() // run over and over
{
 while (Serial.available())  
{
   char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
 
   // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
 
   if (strncmp(ch, "P7H", 3) == 0) //Check to see if the message is "P7H" if it is set Pin7. HIGH
     {
       digitalWrite(7,HIGH);
       mySerial.println(ch); //send the message to mySerial so I can check it.
     }
 
     else if (strncmp(ch, "P7L", 3) == 0) //check to see if the message is "P7L" if it is set Pin7 LOW
       {
         digitalWrite(7,LOW);
         mySerial.println(ch); //send the message to mySerial so I can check it.
       }
   
     else if (strncmp(ch, "P6H", 3) == 0) //check to see if the message is "P6H" if it is set Pin6 HIGH
       {
         digitalWrite(6,HIGH);
         mySerial.println(ch); //send the message to mySerial so I can check it.
       }
 
     else if (strncmp(ch, "P6L", 3) == 0) // check to see if the message is "P6L" if it is set Pin6 LOW
       {
         digitalWrite(6,LOW);
         mySerial.println(ch);
       }
     else if (strncmp(ch, "P5P", 3) == 0) // check to see if the message is "P5P" if it is set Pin5 High for a few seconds then LOW again.
       {
         digitalWrite(5,HIGH);
         delay(1000);          
         digitalWrite(5,LOW);
         mySerial.println(ch); //send the message to mySerial so I can check it.
       }
   
     else if (strncmp(ch, "OFF", 3) == 0) // check to see if the message is "OFF" if it is set Pin5,Pin6 and Pin7 LOW.
       {
         digitalWrite(5,LOW);
         digitalWrite(6,LOW);
         digitalWrite(7,LOW);
         mySerial.println(ch); // send the message to mySerial so I can check it.
       }
}
}


ok I figured out the code posting bit, now I just have to figure out the syntax.

I used "char ch = Serial.read()" to read the data into "ch" ( hoping it would store the 3 characters coming in)   then use the compare string function mentioned above to see if ch was one of the codes I had assigned "P7H" or "P7L" etc.... but the syntax is not right... :

if (strncmp(ch, "P7H", 3) == 0) //Check to see if the message is "P7H" if it is set Pin7. HIGH
     {
       digitalWrite(7,HIGH);
       mySerial.println(ch); //send the message to mySerial so I can check it.
     }

did not work ....not sure why... I think the structure of the program is fine, now I need to work on the syntax....

P.S.  I went back and properly posted the code in the code box for my posts :)

oric_dan


In "char ch = Serial.read()", ch only holds a single char, so you can only do a single-character
compare such as if( ch == 'P' ) ....

You can setup a character array as char datain[16], and read in data inside a while loop until
there is no more data, but have to be careful you don't overflow the array. Eg,

dhunt

#17
Mar 04, 2012, 06:33 am Last Edit: Mar 04, 2012, 06:51 am by dhunt Reason: 1
I posted this a while back, an example sketch reading messages from the WiFly receiving UDP messages: http://arduino.cc/forum/index.php/topic,68007.msg667351.html#msg667351.

In this case the messages can vary in length so I decided to use an end of message character so the sketch knows when it has received a full message.  I used 255, but it could instead be a character that you can send from the serial monitor like a '!'.  The sketch builds up a string in a character array until it receives the end of message marker. Whenever it gets an end of message marker it acts on the string and resets the index for the array to start receiving the next message.

edit: fixed typo

Waltermixxx

#18
Mar 04, 2012, 06:47 am Last Edit: Mar 04, 2012, 07:31 am by Waltermixxx Reason: 1
okie doke... this did compile, I switched to single character messages... for button presses this will be fine... added a couple more buttons, loaded it to my arduino and it worked great... so this is a great wear to do some simple things with UPD an iPhone and a little help from my friends.... :) here is the code based on all the suggestions for use with single character sending.

here is a picture of it :)

http://www.flickr.com/photos/66577016@N00/6805127880/

Code: [Select]

/* using an RN-XV setup to monitor UDP messages, sending to the serial port.
*  scanning arduino serial port for A, B, C, D, D, E, G, H and finally F for all Off
*  then compare the input with the above to turn one of 3 L.E.D.'s on or off  for this test I removed the PWM slider,
*  to challenging for now..
*/


#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

void setup()  
{
 pinMode(5, OUTPUT); // LED5
 pinMode(6, OUTPUT); // LED6
 pinMode(7, OUTPUT); // LED7
 
 Serial.begin(9600);
 mySerial.begin(9600);
 mySerial.println("Hello, world?"); // check to see if it's working
}

void loop() // run over and over
{
 while (Serial.available())  
{
   char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
 
   // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
 
   if (ch == 'A') //Check to see if the message is "A" if it is set LED7. HIGH
     {
       digitalWrite(7,HIGH);
       mySerial.println(ch); //send the message to mySerial so I can check it.
     }
     
     else if (ch == 'B') //check to see if the message is "B" if it is set LED7 LOW
       {
         digitalWrite(7,LOW);
         mySerial.println(ch); //send the message to mySerial so I can check it.
       }
   
     else if (ch == 'C') //check to see if the message is "C" if it is set LED6 HIGH
       {
         digitalWrite(6,HIGH);
         mySerial.println(ch); //send the message to mySerial so I can check it.
       }
 
     else if (ch == 'D') // check to see if the message is "D" if it is set LED6 LOW
       {
         digitalWrite(6,LOW);
         mySerial.println(ch);
       }
     else if (ch == 'E') // check to see if the message is "E" if it is set LED5 High for a few seconds then LOW again.
       {
         digitalWrite(5,HIGH);
         delay(1000);          
         digitalWrite(5,LOW);
         mySerial.println(ch); //send the message to mySerial so I can check it.
       }
       
       else if (ch == 'G') // check to see if the message is "G" if it is set LED5 HIGH.
       {
         digitalWrite(5,HIGH);
         mySerial.println(ch); // send the message to mySerial so I can check it.
       }
   else if (ch == 'H') // check to see if the message is "H" if it is set LED5 LOW.
       {
         digitalWrite(5,LOW);
         mySerial.println(ch); // send the message to mySerial so I can check it.
       }
   
     else if (ch == 'F') // check to see if the message is "F" if it is set all LEDs LOW.
       {
         digitalWrite(5,LOW);
         digitalWrite(6,LOW);
         digitalWrite(7,LOW);
         mySerial.println(ch); // send the message to mySerial so I can check it.
       }
}
}

Waltermixxx

Here is the latest code I wrote (with much help)... :)   it allows me to turn 3 devices on and off, one of them can be pulsed.  it also includes control for a servo. when a button is pressed on the iPhone the servo turns 180 degrees, then back.   :) uses the servo.h and SoftwareSerial.h libraries....

Code: [Select]

/* using an RN-XV setup to monitor UDP messages, sending to the serial port.
*  scanning arduino serial port for A, B, C, D, D, E, G, H and finally F for all Off
*  then compare the input with the above to turn one of 3 L.E.D.'s on or off  for this test I removed the PWM slider,
*  to challenging for now..
*/


#include <SoftwareSerial.h>
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

void setup() 
{
  pinMode(5, OUTPUT); // LED5
  pinMode(6, OUTPUT); // LED6
  pinMode(7, OUTPUT); // LED7
 
 
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.println("Hello, world?"); // check to see if it's working
  myservo.write(pos);
}



void loop() // run over and over
{
  while (Serial.available()) 
{
    char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
 
    // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
 
    if (ch == 'A') //Check to see if the message is "A" if it is set LED7. HIGH
      {
        digitalWrite(7,HIGH);
        mySerial.println(ch); //send the message to mySerial so I can check it.
      }
     
      else if (ch == 'B') //check to see if the message is "B" if it is set LED7 LOW
        {
          digitalWrite(7,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
   
      else if (ch == 'C') //check to see if the message is "C" if it is set LED6 HIGH
        {
          digitalWrite(6,HIGH);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
 
      else if (ch == 'D') // check to see if the message is "D" if it is set LED6 LOW
        {
          digitalWrite(6,LOW);
          mySerial.println(ch);
        }
      else if (ch == 'E') // check to see if the message is "E" if it is set LED5 High for a few seconds then LOW again.
        {
          digitalWrite(5,HIGH);
          delay(1000);           
          digitalWrite(5,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
        }
       
        else if (ch == 'G') // check to see if the message is "G" if it is set LED5 HIGH.
        {
          digitalWrite(5,HIGH);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
    else if (ch == 'H') // check to see if the message is "H" if it is set LED5 LOW.
        {
          digitalWrite(5,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
   
      else if (ch == 'F') // check to see if the message is "F" if it is set all LEDs LOW.
        {
          digitalWrite(5,LOW);
          digitalWrite(6,LOW);
          digitalWrite(7,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
        }
       
      else if (ch == 'X') // check to see if the message is "X" if it is Dispense the treat.
        {
          myservo.attach(9);  // attaches the servo on pin 9 to the servo object
          for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
        {                                  // in steps of 1 degree
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
          for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
        {                               
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
        myservo.detach();
       
        }
     
       
       
       
       
}
}


Waltermixxx

#20
Mar 10, 2012, 03:05 am Last Edit: Apr 23, 2012, 01:31 am by Waltermixxx Reason: 1
Here is the same sketch but with better comments, and I am trying to send confirmation info back to my iPhone via UDP.  I am able to send UPD messages from my iPhone no matter where it is, because I send the info directly to the IP of the router, and then use a NAT table to direct port 7777 to my Arduino.  And it works great, If I am at home it works, if I am on 3g with wireless turned off it works... The problem is I would like the Arduino to send back confirmation messages to the iPhone  for example when it receives the X command it runs the server, I have a message that indicates the Treat is being dispensed, and confirms when done.  If my iPhone is on the local network (same as the arduino, it works great...) but when I switch to 3g I am not sure how to get the message back to the iPhone that that treat has been dispensed (yup it's a dog treat dispenser...)

Any clues?  Not really an arduino question more of a networking question...  I can receive udp messages on the arduino from anywhere, just not sure how to get them back on the iPhone.... using an app called UDP_Test... (free) when on the local network, I can receive the messages back from the arduino, just not when on 3g... :)

I did do the Auto Pairing setting in the manual Section 11.2   using the following commands:

set ip host 0.0.0.0
set ip flags 0x40

save
reboot

and it does pick up an ip address of what I guess is my iPhone, but my iPhone does not receive the confirmation text...



here is my latest code for those who are interested in using the RN-XV for something similar... :)


Code: [Select]


/* using an RN-XV setup to monitor UDP messages, sending to the serial port.
* info from my RN-XV  need this info to setup the udp app on the iphone.
* IF=UP
* DHCP=OFF
* IP=192.168.10.200:7777   <  the IP address I assigned my RN-XV
* NM=255.255.255.0
* GW=192.168.10.1
* HOST=192.168.10.124:7777 < the ip address for my iphone
* PROTO=UDP,
* MTU=1524
*  make sure you set the RN-XV up manually before setting the IP address that the app is using.
*  scanning arduino serial port for A, B, C, D, D, E, G, H and finally F for all Off
*  then compare the input with the above to turn one of 3 L.E.D.'s on or off  I have added a server motor and
*  the server library so now I can turn a server 180 degrees and back.  I setup soft serial to send info to the
*  Arduino serial monitor.  Now however I also want to send a confirmation message back to my iphone iva UDP.
*  I was hoping I could use the serial port I am receivig data from and send UDP info... just not sure where to send it?
*/


#include <SoftwareSerial.h>
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

SoftwareSerial mySerial(2, 3); // using soft serial to monitor what the arduino is doing. The hardware serial is busy talking to the RN-XV

void setup() 
{
  pinMode(5, OUTPUT); // LED5
  pinMode(6, OUTPUT); // LED6
  pinMode(7, OUTPUT); // LED7
 
 
  Serial.begin(9600);  // used to communicate with the RN-XV module.
  mySerial.begin(9600); // start up the second serial port used to sending messages to Arduino Serial Monitor.
  mySerial.println("Hello, world?"); // check to see if it's working
  myservo.write(pos);
}



void loop() // run over and over
{
  while (Serial.available()) 
{
    char ch = Serial.read();     //hoping this will transfer the characters from UDP coming in on serial port into ch?
 
    // the meat and potatoes portion of the sketch... this errors out but I want to get the idea of what I want to do down...
 
    if (ch == 'A') //Check to see if the message is "A" if it is set LED7. HIGH
      {
        digitalWrite(7,HIGH);
        mySerial.println(ch); //send the message to mySerial so I can check it.
        Serial.println("LED7 on");  // send this message back via UDP back to my iphone to confirm it happened.
      }
     
      else if (ch == 'B') //check to see if the message is "B" if it is set LED7 LOW
        {
          digitalWrite(7,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
          Serial.println("LED7 Off");  // send this message back via UDP back to my iphone to confirm it happened.
        }
   
      else if (ch == 'C') //check to see if the message is "C" if it is set LED6 HIGH
        {
          digitalWrite(6,HIGH);
          mySerial.println(ch); //send the message to mySerial so I can check it.
          Serial.println("LED6 On");  // send this message back via UDP back to my iphone to confirm it happened.
        }
 
      else if (ch == 'D') // check to see if the message is "D" if it is set LED6 LOW
        {
          digitalWrite(6,LOW);
          mySerial.println(ch);
          Serial.println("LED6 Off");  // send this message back via UDP back to my iphone to confirm it happened.
        }
      else if (ch == 'E') // check to see if the message is "E" if it is set LED5 High for a few seconds then LOW again.
        {
          digitalWrite(5,HIGH);
          delay(1000);           
          digitalWrite(5,LOW);
          mySerial.println(ch); //send the message to mySerial so I can check it.
          Serial.println("LED5 Pulsed"); // send this message back via UDP back to my iphone to confirm it happened.
        }
       
        else if (ch == 'G') // check to see if the message is "G" if it is set LED5 HIGH.
        {
          digitalWrite(5,HIGH);
          mySerial.println(ch); // send the message to mySerial so I can check it.
          Serial.println("LED5 On"); // send this message back via UDP back to my iphone to confirm it happened.
        }
    else if (ch == 'H') // check to see if the message is "H" if it is set LED5 LOW.
        {
          digitalWrite(5,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
          Serial.println("LED5 Off"); // send this message back via UDP back to my iphone to confirm it happened.
        }
   
      else if (ch == 'F') // check to see if the message is "F" if it is set all LEDs LOW.
        {
          digitalWrite(5,LOW);
          digitalWrite(6,LOW);
          digitalWrite(7,LOW);
          mySerial.println(ch); // send the message to mySerial so I can check it.
          Serial.println("All Off"); // send this message back via UDP back to my iphone to confirm it happened.
        }
       
      else if (ch == 'X') // check to see if the message is "X" if it is Dispense the treat.
        {
          myservo.attach(9);  // attaches the servo on pin 9 to the servo object
          Serial.println("Dispencing Treat"); // send this message back via UDP back to my iphone to confirm it happened.
          for(pos = 0; pos < 20; pos += 1)  // goes from 0 degrees to 180 degrees
        {                                  // in steps of 1 degree
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
          delay(40);
          for(pos = 20; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
        {                               
          myservo.write(pos);              // tell servo to go to position in variable 'pos'
          delay(15);                       // waits 15ms for the servo to reach the position
        }
        myservo.detach();
        Serial.println("Done");  // send this message back via UDP back to my iphone to confirm it happened.
       
        }
     
       
       
       
       
}
}

Waltermixxx

#21
Apr 21, 2012, 10:18 pm Last Edit: Apr 21, 2012, 10:20 pm by Waltermixxx Reason: 1
http://www.youtube.com/watch?v=rxpmoFbpgd0  here is the project up and running on you tube

http://www.youtube.com/watch?v=nZH8lACsjCs&context=C4c335aeADvjVQa1PpcFOc4ql4DZAruJwQPyqDYmPne9hZ88puVYc=

leozinox

Hello. I want to do exactly what you're doing. Which is to turn on/off a led through wireless. The thing is that I understand about arduino and hardware in general, but I'm having trouble with protocols. Why did you use UDP and not TCP?

But the main question is: How can I do what you did through my computer. What software to use to send the commands?

THANK YOU SO MUCH

rgramza

Hi Walter, great post!  I am trying to do exactly what you are doing.  I have a RN-XV, Ardumote, sitting on a sparkfun Xbee breakout board.  I can read my code from the ipad, ie P5H through the serial port.  Down loading your code I can't seem to get it to work.  Is there anyway you could spell out the wire connections and any other code?  Also, it seems that your code is only looking for one letter "A", "B" ect.  The ardumote app outputs a High/Low, meaning  "AH"  or "AL", is there a way to change it.  Thanks Ron.  Having fun but getting frustrated....

Waltermixxx

Ardumote buttons have two different types, the toggle puts the H or the L.
I am not using the toggle, I am using the button in Ardumote.  It will produce what ever code you want.  My buttons on the iPhone are programmed to produce a "B" or an "A" etc.  

As far as the wiring up, the RN-XV tx and Rx are wired to the arduino Rx and tx respectively.
LEDs are wired from the pins as indicated along with the servo...

What I may not make clear is that I configured the RN-XV manually before loading the sketch.

I connect the RN-XV to the computer USB via the arduino. Program it using the commands from the manual.
I associate it with my wireless network, I assign a manual ip address which I use in the Ardumote programmable buttons

Remember Ron do not use the toggle in Ardumote use the regular button.

Hope this helps....


Waltermixxx

#25
Apr 23, 2012, 12:02 am Last Edit: Apr 23, 2012, 01:33 am by Waltermixxx Reason: 1
here is a link to the button settings in Ardumote. Please note this includes internal ip address, but if you like you can put in your routers external ip address here, and the turn on NAT on your home router and assign incoming UDP traffic from port 7777 to internal IP address 192.168.10.15 or what ever you happen to be using... I also updated my sketch above with additional comments about configuring the RN-XV prior to loading the sketch

http://flic.kr/p/bPJZyp

it's a pic of the settings... :)

here is a pic with the RN-XV on the Arduino Wireless Proto Sheild.

http://www.flickr.com/photos/66577016@N00/6950292209/in/photostream/


cmd1024

#26
Apr 23, 2012, 03:11 am Last Edit: Apr 23, 2012, 03:18 am by cmd1024 Reason: 1
I didn't get one thing. You are not using a Wifly library in Arduino code. How can it connect wirelessly without that? Did you also make a physical change in Arduino Proto shield?
Do you have the code for with the slider version ? Would be great if you could share pin connections.

Also you wrote:

Quote
What I may not make clear is that I configured the RN-XV manually before loading the sketch.

I connect the RN-XV to the computer USB via the arduino. Program it using the commands from the manual.
I associate it with my wireless network, I assign a manual ip address which I use in the Ardumote programmable buttons


So do we have to make that configuration as well with that FTDI stuff? Ports you use will be different in our case? Those parts you didn't explain smells really tricky..

dhunt


I didn't get one thing. You are not using a Wifly library in Arduino code. How can it connect wirelessly without that? Did you also make a physical change in Arduino Proto shield?
Do you have the code for with the slider version ? Would be great if you could share pin connections.

Also you wrote:

Quote
What I may not make clear is that I configured the RN-XV manually before loading the sketch.

I connect the RN-XV to the computer USB via the arduino. Program it using the commands from the manual.
I associate it with my wireless network, I assign a manual ip address which I use in the Ardumote programmable buttons


So do we have to make that configuration as well with that FTDI stuff? Ports you use will be different in our case? Those parts you didn't explain smells really tricky..



The WiFly is actually a pretty easy module to use. The tricky part is that you have to read the manual to work out how to use it. http://rovingnetworks.com/resources/download/93/WiFly_User_Manual


I didn't get one thing. You are not using a Wifly library in Arduino code. How can it connect wirelessly without that? Did you also make a physical change in Arduino Proto shield?
Do you have the code for with the slider version ? Would be great if you could share pin connections.


Thats what I was confused about as well. I uploaded the code after configuring the WiFly and nothing occurred.  After using another sample UDP server sketch and editing it a little bit, I was able to use Ardumote with the WiFly, however I had some issues.  Currently I only know how to send 1 character messages, and the WiFly will only read values if they are placed in between the phrases *OPEN* and *CLOS*.  This strikes a problem for the PWM sliders because they have the 'XXX' number values at the end, leaving them outside of the OPEN and CLOS message. If anyone has had any experience with Ardumote and using the PWM sliders, or has any ideas on how to read the message without the OPEN and CLOS messages I would appreciate it.

Go Up